blob: 1b4995ed53b34e4ba9949ad70140fc03ef31b2d2 [file] [log] [blame]
Bram Moolenaarcd71fa32005-03-11 22:46:48 +00001" Vim syntax file for the D programming language (version 0.116).
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 Moolenaarcd71fa32005-03-11 22:46:48 +00005" Last Change: 2005 Mar 09
6" Version: 0.12
Bram Moolenaar071d4272004-06-13 20:20:40 +00007"
8" Options:
9" d_comment_strings - set to highlight strings and numbers in comments
10"
11" d_hl_operator_overload - set to highlight D's specially named functions
12" that when overloaded implement unary and binary operators (e.g. cmp).
13"
14" Todo:
15" - Allow user to set sync minlines
16"
17" - Several keywords (namely, in and out) are both storage class and
18" statements, depending on their context. Must use some matching to figure
19" out which and highlight appropriately. For now I have made such keywords
20" statements.
21"
22" - Mark contents of the asm statement body as special
23"
24
25" Quit when a syntax file was already loaded
26if exists("b:current_syntax")
27 finish
28endif
29
30" Keyword definitions
31"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000032syn keyword dExternal import package module extern
33syn keyword dConditional if else switch
34syn keyword dBranch goto break continue
35syn keyword dRepeat while for do foreach
36syn keyword dBoolean true false
37syn keyword dConstant null
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000038syn keyword dConstant __FILE__ __LINE__ __DATE__ __TIME__ __TIMESTAMP__
Bram Moolenaar21cf8232004-07-16 20:18:37 +000039syn keyword dTypedef alias typedef
40syn keyword dStructure template interface class enum struct union
41syn keyword dOperator new delete typeof typeid cast align is
42syn keyword dOperator this super
Bram Moolenaar071d4272004-06-13 20:20:40 +000043if exists("d_hl_operator_overload")
Bram Moolenaar21cf8232004-07-16 20:18:37 +000044 syn keyword dOpOverload opNeg opCom opPostInc opPostDec opAdd opSub opSub_r
45 syn keyword dOpOverload opMul opDiv opDiv_r opMod opMod_r opAnd opOr opXor
46 syn keyword dOpOverload opShl opShl_r opShr opShr_r opUShr opUShr_r opCat
47 syn keyword dOpOverload opCat_r opEquals opEquals opCmp opCmp opCmp opCmp
48 syn keyword dOpOverload opAddAssign opSubAssign opMulAssign opDivAssign
49 syn keyword dOpOverload opModAssign opAndAssign opOrAssign opXorAssign
50 syn keyword dOpOverload opShlAssign opShrAssign opUShrAssign opCatAssign
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000051 syn keyword dOpOverload opIndex opIndexAssign opCall opSlice opPos
Bram Moolenaar21cf8232004-07-16 20:18:37 +000052 syn keyword dOpOverload opAdd_r opMul_r opAnd_r opOr_r opXor_r
Bram Moolenaar071d4272004-06-13 20:20:40 +000053endif
Bram Moolenaar21cf8232004-07-16 20:18:37 +000054syn keyword dType ushort int uint long ulong float
55syn keyword dType void byte ubyte double bit char wchar ucent cent
56syn keyword dType short bool dchar
57syn keyword dType real ireal ifloat idouble creal cfloat cdouble
58syn keyword dDebug deprecated unittest
59syn keyword dExceptions throw try catch finally
60syn keyword dScopeDecl public protected private export
61syn keyword dStatement version debug return with invariant body
62syn keyword dStatement in out inout asm mixin
63syn keyword dStatement function delegate
64syn keyword dStorageClass auto static override final const abstract volatile
65syn keyword dStorageClass synchronized
66syn keyword dPragma pragma
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
68
69" Assert is a statement and a module name.
70syn match dAssert "^assert\>"
71syn match dAssert "[^.]\s*\<assert\>"ms=s+1
72
73" Marks contents of the asm statment body as special
74"
75" TODO
76"syn match dAsmStatement "\<asm\>"
77"syn region dAsmBody start="asm[\n]*\s*{"hs=e+1 end="}"he=e-1 contains=dAsmStatement
78"
79"hi def link dAsmBody dUnicode
80"hi def link dAsmStatement dStatement
81
82" Labels
83"
84" We contain dScopeDecl so public: private: etc. are not highlighted like labels
Bram Moolenaar21cf8232004-07-16 20:18:37 +000085syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl
86syn keyword dLabel case default
Bram Moolenaar071d4272004-06-13 20:20:40 +000087
88" Comments
89"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000090syn keyword dTodo contained TODO FIXME TEMP XXX
91syn match dCommentStar contained "^\s*\*[^/]"me=e-1
92syn match dCommentStar contained "^\s*\*$"
93syn match dCommentPlus contained "^\s*+[^/]"me=e-1
94syn match dCommentPlus contained "^\s*+$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000095if exists("d_comment_strings")
Bram Moolenaar21cf8232004-07-16 20:18:37 +000096 syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell
97 syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell
98 syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell
99 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
100 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
101 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102else
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000103 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
104 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
105 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106endif
107
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000108hi link dLineCommentString dBlockCommentString
109hi link dBlockCommentString dString
110hi link dNestedCommentString dString
111hi link dCommentStar dBlockComment
112hi link dCommentPlus dNestedComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114syn sync minlines=25
115
116" Characters
117"
118syn match dSpecialCharError contained "[^']"
119
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000120" Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
121" These are not contained because they are considered string litterals
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000122syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000123syn match dEscSequence "\\&[^;& \t]\+;"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000124syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError
125syn match dCharacter "'\\''" contains=dEscSequence
126syn match dCharacter "'[^\\]'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
128" Unicode characters
129"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000130syn match dUnicode "\\u\d\{4\}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000132
133
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134" String.
135"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000136syn region dString start=+"+ end=+"+ contains=dEscSequence,@Spell
137syn region dRawString start=+`+ skip=+\\`+ end=+`+ contains=@Spell
138syn region dRawString start=+r"+ skip=+\\"+ end=+"+ contains=@Spell
139syn region dHexString start=+x"+ skip=+\\"+ end=+"+
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140
141" Numbers
142"
143syn case ignore
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000144syn match dInt display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145" Hex number
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000146syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
147syn match dHex display "\<\x[0-9a-f_]*h\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148" Flag the first zero of an octal number as something special
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000149syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>" contains=cOctalZero
150syn match dOctalZero display contained "\<0"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151
152"floating point without the dot
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000153syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154"floating point number, with dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000155syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156"floating point number, starting with a dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000157syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158"floating point number, without dot, with exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000159"syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>"
160syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161
162"floating point without the dot
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000163syn match dHexFloat display "\<0x\x\+\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164"floating point number, with dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000165syn match dHexFloat display "\<0x\x\+\.\x*\(p[-+]\=\x\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166"floating point number, without dot, with exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000167syn match dHexFloat display "\<0x\x\+p[-+]\=\x\+[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168
169" binary numbers
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000170syn match dBinary display "\<0b[01_]\+\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171" flag an octal number with wrong digits
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000172syn match dOctalError display "0\o*[89]\d*"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173syn case match
174
175" Pragma (preprocessor) support
176" TODO: Highlight following Integer and optional Filespec.
177syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$"
178
179
180" The default highlighting.
181"
182hi def link dBinary Number
183hi def link dInt Number
184hi def link dHex Number
185hi def link dOctal Number
186hi def link dFloat Float
187hi def link dHexFloat Float
188hi def link dDebug Debug
189hi def link dBranch Conditional
190hi def link dConditional Conditional
191hi def link dLabel Label
192hi def link dUserLabel Label
193hi def link dRepeat Repeat
194hi def link dExceptions Exception
195hi def link dAssert Statement
196hi def link dStatement Statement
197hi def link dScopeDecl dStorageClass
198hi def link dStorageClass StorageClass
199hi def link dBoolean Boolean
200hi def link dUnicode Special
201hi def link dRawString String
202hi def link dString String
203hi def link dHexString String
204hi def link dCharacter Character
205hi def link dEscSequence SpecialChar
206hi def link dSpecialCharError Error
207hi def link dOctalError Error
208hi def link dOperator Operator
209hi def link dOpOverload Operator
210hi def link dConstant Constant
211hi def link dTypedef Typedef
212hi def link dStructure Structure
213hi def link dTodo Todo
214hi def link dType Type
215hi def link dLineComment Comment
216hi def link dBlockComment Comment
217hi def link dNestedComment Comment
218hi def link dExternal Include
219hi def link dPragma PreProc
220
221let b:current_syntax = "d"
222
223" vim: ts=8