Advertisement
Guest User

Untitled

a guest
Dec 27th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.89 KB | None | 0 0
  1. " Vim syntax file for the D programming language (version 1.053 and 2.047).
  2. "
  3. " Language: D
  4. " Maintainer: Jason Mills<jasonmills@nf.sympatico.ca>
  5. " Contribute Author: Shougo Matsushita <Shougo.Matsu@gmail.com>
  6. " Last Change: 2010 Jul 31
  7. " Version: 0.18-r2
  8. "
  9. " Contributors:
  10. " - Kirk McDonald: version 0.17 updates, with minor modifications
  11. " (http://paste.dprogramming.com/dplmb7qx?view=hidelines)
  12. " - Jesse K. Phillips: patch for some keywords and attributes (annotations), with modifications
  13. " - Tim Keating: patch to fix a bug in highlighting the `\` literal
  14. " - Frank Benoit: Fixed a bug that caused some identifiers and numbers to highlight as octal number errors.
  15. "
  16. "
  17. " Please email me with bugs, comments, and suggestions.
  18. "
  19. " Options:
  20. " d_comment_strings - Set to highlight strings and numbers in comments.
  21. "
  22. " d_hl_operator_overload - Set to highlight D's specially named functions
  23. " that when overloaded implement unary and binary operators (e.g. opCmp).
  24. "
  25. " Todo:
  26. " - Determine a better method of sync'ing than simply setting minlines
  27. " to a large number.
  28. "
  29. " - Several keywords (e.g., in, out, inout) are both storage class and
  30. " statements, depending on their context. Perhaps use pattern matching to
  31. " figure out which and highlight appropriately. For now I have made such
  32. " keywords storage classes so their highlighting is consistent with other
  33. " keywords that are commonly used with them, but are true storage classes,
  34. " such as lazy. Similarly, I made some statement keywords (e.g. body) storage
  35. " classes.
  36. "
  37. " - Mark contents of the asm statement body as special
  38. "
  39. " - Maybe highlight the 'exit', 'failure', and 'success' parts of the
  40. " scope() statement.
  41. "
  42. " - Highlighting DDoc comments.
  43. "
  44. "-----------------------------------------------------------------------------
  45. " ChangeLog: "{{{
  46. " 0.18-r1:
  47. " - Merged Ver.0.18.
  48. " 0.18-r2:
  49. " - Supported D Ver.2.047.
  50. " }}}
  51. "=============================================================================
  52.  
  53. " Quit when a syntax file was already loaded
  54. if exists("b:current_syntax")
  55. finish
  56. endif
  57.  
  58. " Keyword definitions
  59. "
  60. syn keyword dExternal import package module extern
  61. syn keyword dConditional if else switch
  62. syn keyword dBranch goto break continue
  63. syn keyword dRepeat while for do foreach foreach_reverse
  64. syn keyword dBoolean true false
  65. syn keyword dConstant null
  66. syn keyword dConstant __FILE__ __LINE__ __EOF__ __VERSION__
  67. syn keyword dConstant __DATE__ __TIME__ __TIMESTAMP__ __VENDOR__
  68. syn keyword dTypedef alias typedef
  69. syn keyword dStructure template interface class struct union
  70. syn keyword dEnum enum
  71. syn keyword dOperator new delete typeof typeid cast align is
  72. syn keyword dOperator this super
  73. if exists("d_hl_operator_overload")
  74. syn keyword dOpOverload opNeg opCom opPostInc opPostDec opCast opAdd opSub opSub_r
  75. syn keyword dOpOverload opMul opDiv opDiv_r opMod opMod_r opAnd opOr opXor
  76. syn keyword dOpOverload opShl opShl_r opShr opShr_r opUShr opUShr_r opCat
  77. syn keyword dOpOverload opCat_r opEquals opEquals opCmp
  78. syn keyword dOpOverload opAssign opAddAssign opSubAssign opMulAssign opDivAssign
  79. syn keyword dOpOverload opModAssign opAndAssign opOrAssign opXorAssign
  80. syn keyword dOpOverload opShlAssign opShrAssign opUShrAssign opCatAssign
  81. syn keyword dOpOverload opIndex opIndexAssign opIndexOpAssign opCall opSlice opSliceAssign opSliceOpAssign opPos
  82. syn keyword dOpOverload opAdd_r opMul_r opAnd_r opOr_r opXor_r opIn opIn_r
  83. syn keyword dOpOverload opPow opDispatch opStar opDot opApply opApplyReverse
  84. syn keyword dOpOverload opUnary opIndexUnary opSliceUnary
  85. syn keyword dOpOverload opBinary opBinaryRight
  86. endif
  87. syn keyword dType ushort int uint long ulong float
  88. syn keyword dType void byte ubyte double bit char wchar ucent cent
  89. syn keyword dType short bool dchar string wstring dstring
  90. syn keyword dType real ireal ifloat idouble creal cfloat cdouble
  91. syn keyword dDebug deprecated unittest
  92. syn keyword dExceptions throw try catch finally
  93. syn keyword dScopeDecl public protected private export
  94. syn keyword dStatement version debug return with
  95. syn keyword dStatement function delegate __traits asm mixin macro
  96. syn keyword dStorageClass in out inout ref lazy scope body
  97. syn keyword dStorageClass pure nothrow
  98. syn keyword dStorageClass auto static override final abstract volatile __gshared __thread
  99. syn keyword dStorageClass synchronized immutable shared const invariant lazy
  100. syn keyword dStorageClass @disable @property
  101. syn keyword dPragma pragma
  102. syn keyword dIdentifier _arguments _argptr __vptr __monitor _ctor _dtor
  103. syn keyword dVersionIdentifier DigitalMars X86 X86_64 Windows Win32 Win64 linux Posix LittleEndian BigEndian
  104. syn keyword dVersionIdentifier D_Coverage D_Ddoc D_InlineAsm_X86 D_InlineAsm_X86_64 D_LP64 D_PIC unittest D_Version2
  105. syn keyword dVersionIdentifier none all
  106.  
  107. " Attributes/annotations
  108. syn match dAnnotation "@[_$a-zA-Z][_$a-zA-Z0-9_]*\>"
  109.  
  110. " Highlight the 'exit', 'failure', and 'success' parts of the
  111. " scope() statement.
  112. syn match dStatement "scope\s*(\s*\(exit\|failure\|success\)\s*)"
  113. syn match dStorageClass "scope\s\+[^(]"he=e-1
  114.  
  115. " Assert is a statement and a module name.
  116. syn match dAssert "^assert\>"
  117. syn match dAssert "[^.]\s*\<assert\>"ms=s+1
  118.  
  119. " dTokens is used by the token string highlighting
  120. syn cluster dTokens contains=dExternal,dConditional,dBranch,dRepeat,dBoolean
  121. syn cluster dTokens add=dConstant,dTypedef,dStructure,dOperator,dOpOverload
  122. syn cluster dTokens add=dType,dDebug,dExceptions,dScopeDecl,dStatement
  123. syn cluster dTokens add=dStorageClass,dPragma,dAssert,dAnnotation
  124.  
  125. " Marks contents of the asm statment body as special
  126. "
  127. syn match dAsmStatement "\<asm\>"
  128. syn region dAsmBody start="asm[\n]*\s*{"hs=e+1 end="}"he=e-1 contains=dAsmStatement
  129.  
  130. hi def link dAsmBody dUnicode
  131. hi def link dAsmStatement dStatement
  132.  
  133. " Labels
  134. "
  135. " We contain dScopeDecl so public: private: etc. are not highlighted like labels
  136. syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl,dEnum
  137. syn keyword dLabel case default
  138.  
  139. " Comments
  140. "
  141. syn keyword dTodo contained TODO FIXME TEMP REFACTOR REVIEW HACK BUG XXX
  142. syn match dCommentStar contained "^\s*\*[^/]"me=e-1
  143. syn match dCommentStar contained "^\s*\*$"
  144. syn match dCommentPlus contained "^\s*+[^/]"me=e-1
  145. syn match dCommentPlus contained "^\s*+$"
  146. if exists("d_comment_strings")
  147. syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell
  148. syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell
  149. syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell
  150. syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
  151. syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
  152. syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
  153. else
  154. syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
  155. syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
  156. syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
  157. endif
  158.  
  159. hi link dLineCommentString dBlockCommentString
  160. hi link dBlockCommentString dString
  161. hi link dNestedCommentString dString
  162. hi link dCommentStar dBlockComment
  163. hi link dCommentPlus dNestedComment
  164.  
  165. syn cluster dTokens add=dBlockComment,dNestedComment,dLineComment
  166.  
  167. " /+ +/ style comments and strings that span multiple lines can cause
  168. " problems. To play it safe, set minlines to a large number.
  169. syn sync minlines=200
  170. " Use ccomment for /* */ style comments
  171. syn sync ccomment dBlockComment
  172.  
  173. " Characters
  174. "
  175. syn match dSpecialCharError contained "[^']"
  176.  
  177. " Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
  178. " These are not contained because they are considered string literals.
  179. syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
  180. syn match dEscSequence "\\&[^;& \t]\+;"
  181. syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError
  182. syn match dCharacter "'\\''" contains=dEscSequence
  183. syn match dCharacter "'[^\\]'"
  184.  
  185. " Unicode characters
  186. "
  187. syn match dUnicode "\\u\d\{4\}"
  188.  
  189.  
  190. " String.
  191. "
  192. syn region dString start=+"+ end=+"[cwd]\=+ skip=+\\\\\|\\"+ contains=dEscSequence,@Spell
  193. syn region dRawString start=+`+ end=+`[cwd]\=+ contains=@Spell
  194. syn region dRawString start=+r"+ end=+"[cwd]\=+ contains=@Spell
  195. syn region dHexString start=+x"+ end=+"[cwd]\=+ contains=@Spell
  196. syn region dDelimString start=+q"\z(.\)+ end=+\z1"+ contains=@Spell
  197. syn region dHereString start=+q"\z(\I\i*\)\n+ end=+\n\z1"+ contains=@Spell
  198.  
  199. " Nesting delimited string contents
  200. "
  201. syn region dNestParenString start=+(+ end=+)+ contained transparent contains=dNestParenString,@Spell
  202. syn region dNestBrackString start=+\[+ end=+\]+ contained transparent contains=dNestBrackString,@Spell
  203. syn region dNestAngleString start=+<+ end=+>+ contained transparent contains=dNestAngleString,@Spell
  204. syn region dNestCurlyString start=+{+ end=+}+ contained transparent contains=dNestCurlyString,@Spell
  205.  
  206. " Nesting delimited strings
  207. "
  208. syn region dParenString matchgroup=dParenString start=+q"(+ end=+)"+ contains=dNestParenString,@Spell
  209. syn region dBrackString matchgroup=dBrackString start=+q"\[+ end=+\]"+ contains=dNestBrackString,@Spell
  210. syn region dAngleString matchgroup=dAngleString start=+q"<+ end=+>"+ contains=dNestAngleString,@Spell
  211. syn region dCurlyString matchgroup=dCurlyString start=+q"{+ end=+}"+ contains=dNestCurlyString,@Spell
  212.  
  213. hi link dParenString dNestString
  214. hi link dBrackString dNestString
  215. hi link dAngleString dNestString
  216. hi link dCurlyString dNestString
  217.  
  218. syn cluster dTokens add=dString,dRawString,dHexString,dDelimString,dNestString
  219.  
  220. " Token strings
  221. "
  222. syn region dNestTokenString start=+{+ end=+}+ contained contains=dNestTokenString,@dTokens
  223. syn region dTokenString matchgroup=dTokenStringBrack transparent start=+q{+ end=+}+ contains=dNestTokenString,@dTokens
  224.  
  225. syn cluster dTokens add=dTokenString
  226.  
  227. " Numbers
  228. "
  229. syn case ignore
  230.  
  231. syn match dDec display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
  232.  
  233. " Hex number
  234. syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
  235.  
  236. syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>"
  237. " flag an octal number with wrong digits
  238. syn match dOctalError display "\<0[0-7_]*[89][0-9_]*"
  239.  
  240. " binary numbers
  241. syn match dBinary display "\<0b[01_]\+\(u\=l\=\|l\=u\=\)\>"
  242.  
  243. "floating point without the dot
  244. syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
  245. "floating point number, with dot, optional exponent
  246. syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
  247. "floating point number, starting with a dot, optional exponent
  248. syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
  249. "floating point number, without dot, with exponent
  250. "syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>"
  251. syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
  252.  
  253. "floating point without the dot
  254. syn match dHexFloat display "\<0x[0-9a-f_]\+\(fi\=\|l\=i\)\>"
  255. "floating point number, with dot, optional exponent
  256. syn match dHexFloat display "\<0x[0-9a-f_]\+\.[0-9a-f_]*\(p[-+]\=[0-9_]\+\)\=[fl]\=i\="
  257. "floating point number, without dot, with exponent
  258. syn match dHexFloat display "\<0x[0-9a-f_]\+p[-+]\=[0-9_]\+[fl]\=i\=\>"
  259.  
  260. syn cluster dTokens add=dDec,dHex,dOctal,dOctalError,dBinary,dFloat,dHexFloat
  261.  
  262. syn case match
  263.  
  264. " Pragma (preprocessor) support
  265. " TODO: Highlight following Integer and optional Filespec.
  266. syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$"
  267.  
  268.  
  269. " The default highlighting.
  270. "
  271. hi def link dBinary Number
  272. hi def link dDec Number
  273. hi def link dHex Number
  274. hi def link dOctal Number
  275. hi def link dFloat Float
  276. hi def link dHexFloat Float
  277. hi def link dDebug Debug
  278. hi def link dBranch Conditional
  279. hi def link dConditional Conditional
  280. hi def link dLabel Label
  281. hi def link dUserLabel Label
  282. hi def link dRepeat Repeat
  283. hi def link dExceptions Exception
  284. hi def link dAssert Statement
  285. hi def link dStatement Statement
  286. hi def link dScopeDecl dStorageClass
  287. hi def link dStorageClass StorageClass
  288. hi def link dBoolean Boolean
  289. hi def link dUnicode Special
  290. hi def link dTokenStringBrack String
  291. hi def link dHereString String
  292. hi def link dNestString String
  293. hi def link dDelimString String
  294. hi def link dRawString String
  295. hi def link dString String
  296. hi def link dHexString String
  297. hi def link dCharacter Character
  298. hi def link dEscSequence SpecialChar
  299. hi def link dSpecialCharError Error
  300. hi def link dOctalError Error
  301. hi def link dOperator Operator
  302. hi def link dOpOverload Identifier
  303. hi def link dConstant Constant
  304. hi def link dTypedef Typedef
  305. hi def link dEnum Structure
  306. hi def link dStructure Structure
  307. hi def link dTodo Todo
  308. hi def link dType Type
  309. hi def link dLineComment Comment
  310. hi def link dBlockComment Comment
  311. hi def link dNestedComment Comment
  312. hi def link dExternal Include
  313. hi def link dPragma PreProc
  314. hi def link dIdentifier Identifier
  315. hi def link dAnnotation PreProc
  316. hi def link dVersionIdentifier Identifier
  317.  
  318. let b:current_syntax = "d"
  319.  
  320. " vim: ts=8 noet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement