blob: 2ab9b25c5eabddecd4145c6325d74e871a5029ad [file] [log] [blame]
Bram Moolenaara5792f52005-11-23 21:25:05 +00001" Vim syntax file for the D programming language (version 0.137).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002"
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003" Language: D
4" Maintainer: Jason Mills<jmills@cs.mun.ca>
Bram Moolenaara5792f52005-11-23 21:25:05 +00005" Last Change: 2005 Oct 29
6" Version: 0.14
7"
8" Please email me with bugs, comments, and suggestion. Put vim in the subject
9" to ensure the email will not be marked has spam.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010"
11" Options:
12" d_comment_strings - set to highlight strings and numbers in comments
13"
14" d_hl_operator_overload - set to highlight D's specially named functions
15" that when overloaded implement unary and binary operators (e.g. cmp).
16"
17" Todo:
18" - Allow user to set sync minlines
19"
20" - Several keywords (namely, in and out) are both storage class and
21" statements, depending on their context. Must use some matching to figure
22" out which and highlight appropriately. For now I have made such keywords
23" statements.
24"
25" - Mark contents of the asm statement body as special
26"
Bram Moolenaara5792f52005-11-23 21:25:05 +000027" - Highlight the string prefix r and and postfixes c,w,d
28"
Bram Moolenaar071d4272004-06-13 20:20:40 +000029
30" Quit when a syntax file was already loaded
31if exists("b:current_syntax")
32 finish
33endif
34
35" Keyword definitions
36"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000037syn keyword dExternal import package module extern
Bram Moolenaara5792f52005-11-23 21:25:05 +000038syn keyword dConditional if else switch iftype
Bram Moolenaar21cf8232004-07-16 20:18:37 +000039syn keyword dBranch goto break continue
40syn keyword dRepeat while for do foreach
41syn keyword dBoolean true false
42syn keyword dConstant null
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000043syn keyword dConstant __FILE__ __LINE__ __DATE__ __TIME__ __TIMESTAMP__
Bram Moolenaar21cf8232004-07-16 20:18:37 +000044syn keyword dTypedef alias typedef
45syn keyword dStructure template interface class enum struct union
46syn keyword dOperator new delete typeof typeid cast align is
47syn keyword dOperator this super
Bram Moolenaar071d4272004-06-13 20:20:40 +000048if exists("d_hl_operator_overload")
Bram Moolenaara5792f52005-11-23 21:25:05 +000049 syn keyword dOpOverload opNeg opCom opPostInc opPostDec opCast opAdd opSub opSub_r
Bram Moolenaar21cf8232004-07-16 20:18:37 +000050 syn keyword dOpOverload opMul opDiv opDiv_r opMod opMod_r opAnd opOr opXor
51 syn keyword dOpOverload opShl opShl_r opShr opShr_r opUShr opUShr_r opCat
52 syn keyword dOpOverload opCat_r opEquals opEquals opCmp opCmp opCmp opCmp
53 syn keyword dOpOverload opAddAssign opSubAssign opMulAssign opDivAssign
54 syn keyword dOpOverload opModAssign opAndAssign opOrAssign opXorAssign
55 syn keyword dOpOverload opShlAssign opShrAssign opUShrAssign opCatAssign
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000056 syn keyword dOpOverload opIndex opIndexAssign opCall opSlice opPos
Bram Moolenaara5792f52005-11-23 21:25:05 +000057 syn keyword dOpOverload opAdd_r opMul_r opAnd_r opOr_r opXor_r
Bram Moolenaar071d4272004-06-13 20:20:40 +000058endif
Bram Moolenaar21cf8232004-07-16 20:18:37 +000059syn keyword dType ushort int uint long ulong float
60syn keyword dType void byte ubyte double bit char wchar ucent cent
61syn keyword dType short bool dchar
62syn keyword dType real ireal ifloat idouble creal cfloat cdouble
63syn keyword dDebug deprecated unittest
64syn keyword dExceptions throw try catch finally
65syn keyword dScopeDecl public protected private export
66syn keyword dStatement version debug return with invariant body
67syn keyword dStatement in out inout asm mixin
68syn keyword dStatement function delegate
69syn keyword dStorageClass auto static override final const abstract volatile
70syn keyword dStorageClass synchronized
71syn keyword dPragma pragma
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
73
74" Assert is a statement and a module name.
75syn match dAssert "^assert\>"
76syn match dAssert "[^.]\s*\<assert\>"ms=s+1
77
78" Marks contents of the asm statment body as special
79"
80" TODO
81"syn match dAsmStatement "\<asm\>"
82"syn region dAsmBody start="asm[\n]*\s*{"hs=e+1 end="}"he=e-1 contains=dAsmStatement
83"
84"hi def link dAsmBody dUnicode
85"hi def link dAsmStatement dStatement
86
87" Labels
88"
89" We contain dScopeDecl so public: private: etc. are not highlighted like labels
Bram Moolenaar21cf8232004-07-16 20:18:37 +000090syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl
91syn keyword dLabel case default
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93" Comments
94"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000095syn keyword dTodo contained TODO FIXME TEMP XXX
96syn match dCommentStar contained "^\s*\*[^/]"me=e-1
97syn match dCommentStar contained "^\s*\*$"
98syn match dCommentPlus contained "^\s*+[^/]"me=e-1
99syn match dCommentPlus contained "^\s*+$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100if exists("d_comment_strings")
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000101 syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell
102 syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell
103 syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell
104 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
105 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
106 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107else
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000108 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
109 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
110 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111endif
112
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000113hi link dLineCommentString dBlockCommentString
114hi link dBlockCommentString dString
115hi link dNestedCommentString dString
116hi link dCommentStar dBlockComment
117hi link dCommentPlus dNestedComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119syn sync minlines=25
120
121" Characters
122"
123syn match dSpecialCharError contained "[^']"
124
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000125" Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
126" These are not contained because they are considered string litterals
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000127syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000128syn match dEscSequence "\\&[^;& \t]\+;"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000129syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError
130syn match dCharacter "'\\''" contains=dEscSequence
131syn match dCharacter "'[^\\]'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132
133" Unicode characters
134"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000135syn match dUnicode "\\u\d\{4\}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000137
138
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139" String.
140"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000141syn region dString start=+"+ end=+"+ contains=dEscSequence,@Spell
142syn region dRawString start=+`+ skip=+\\`+ end=+`+ contains=@Spell
Bram Moolenaara5792f52005-11-23 21:25:05 +0000143"syn region dRawString start=+r"+ skip=+\\"+ end=+"+ contains=@Spell
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000144syn region dHexString start=+x"+ skip=+\\"+ end=+"+
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145
146" Numbers
147"
148syn case ignore
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000149syn match dInt display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150" Hex number
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000151syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
152syn match dHex display "\<\x[0-9a-f_]*h\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153" Flag the first zero of an octal number as something special
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000154syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>" contains=cOctalZero
155syn match dOctalZero display contained "\<0"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156
157"floating point without the dot
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000158syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159"floating point number, with dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000160syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161"floating point number, starting with a dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000162syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163"floating point number, without dot, with exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000164"syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>"
165syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166
167"floating point without the dot
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000168syn match dHexFloat display "\<0x\x\+\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169"floating point number, with dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000170syn match dHexFloat display "\<0x\x\+\.\x*\(p[-+]\=\x\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171"floating point number, without dot, with exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000172syn match dHexFloat display "\<0x\x\+p[-+]\=\x\+[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173
174" binary numbers
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000175syn match dBinary display "\<0b[01_]\+\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176" flag an octal number with wrong digits
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000177syn match dOctalError display "0\o*[89]\d*"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178syn case match
179
180" Pragma (preprocessor) support
181" TODO: Highlight following Integer and optional Filespec.
182syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$"
183
184
185" The default highlighting.
186"
187hi def link dBinary Number
188hi def link dInt Number
189hi def link dHex Number
190hi def link dOctal Number
191hi def link dFloat Float
192hi def link dHexFloat Float
193hi def link dDebug Debug
194hi def link dBranch Conditional
195hi def link dConditional Conditional
196hi def link dLabel Label
197hi def link dUserLabel Label
198hi def link dRepeat Repeat
199hi def link dExceptions Exception
200hi def link dAssert Statement
201hi def link dStatement Statement
202hi def link dScopeDecl dStorageClass
203hi def link dStorageClass StorageClass
204hi def link dBoolean Boolean
205hi def link dUnicode Special
206hi def link dRawString String
207hi def link dString String
208hi def link dHexString String
209hi def link dCharacter Character
210hi def link dEscSequence SpecialChar
211hi def link dSpecialCharError Error
212hi def link dOctalError Error
213hi def link dOperator Operator
214hi def link dOpOverload Operator
215hi def link dConstant Constant
216hi def link dTypedef Typedef
217hi def link dStructure Structure
218hi def link dTodo Todo
219hi def link dType Type
220hi def link dLineComment Comment
221hi def link dBlockComment Comment
222hi def link dNestedComment Comment
223hi def link dExternal Include
224hi def link dPragma PreProc
225
226let b:current_syntax = "d"
227
Bram Moolenaara5792f52005-11-23 21:25:05 +0000228" vim: ts=8 noet