blob: 244e05359633143254d45c819b003e7226ecf8bc [file] [log] [blame]
Bram Moolenaar5baddf02006-03-12 21:53:56 +00001" Vim syntax file for the D programming language (version 0.149).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002"
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003" Language: D
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00004" Maintainer: Jason Mills<jmills@cs.mun.ca>
Bram Moolenaar5baddf02006-03-12 21:53:56 +00005" When emailing me, please put the word vim somewhere in the subject
6" to ensure the email does not get marked as spam.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007" Last Change: 2006 Apr 30
Bram Moolenaar5baddf02006-03-12 21:53:56 +00008" Version: 0.15
Bram Moolenaar071d4272004-06-13 20:20:40 +00009"
10" Options:
11" d_comment_strings - set to highlight strings and numbers in comments
12"
13" d_hl_operator_overload - set to highlight D's specially named functions
14" that when overloaded implement unary and binary operators (e.g. cmp).
15"
16" Todo:
Bram Moolenaar5baddf02006-03-12 21:53:56 +000017" - Must determine a better method of sync'ing than simply setting minlines
18" to a large number for /+ +/.
Bram Moolenaar071d4272004-06-13 20:20:40 +000019"
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"
27
28" Quit when a syntax file was already loaded
29if exists("b:current_syntax")
30 finish
31endif
32
33" Keyword definitions
34"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000035syn keyword dExternal import package module extern
Bram Moolenaara5792f52005-11-23 21:25:05 +000036syn keyword dConditional if else switch iftype
Bram Moolenaar21cf8232004-07-16 20:18:37 +000037syn keyword dBranch goto break continue
38syn keyword dRepeat while for do foreach
39syn keyword dBoolean true false
40syn keyword dConstant null
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000041syn keyword dConstant __FILE__ __LINE__ __DATE__ __TIME__ __TIMESTAMP__
Bram Moolenaar21cf8232004-07-16 20:18:37 +000042syn keyword dTypedef alias typedef
43syn keyword dStructure template interface class enum struct union
44syn keyword dOperator new delete typeof typeid cast align is
45syn keyword dOperator this super
Bram Moolenaar071d4272004-06-13 20:20:40 +000046if exists("d_hl_operator_overload")
Bram Moolenaara5792f52005-11-23 21:25:05 +000047 syn keyword dOpOverload opNeg opCom opPostInc opPostDec opCast opAdd opSub opSub_r
Bram Moolenaar21cf8232004-07-16 20:18:37 +000048 syn keyword dOpOverload opMul opDiv opDiv_r opMod opMod_r opAnd opOr opXor
49 syn keyword dOpOverload opShl opShl_r opShr opShr_r opUShr opUShr_r opCat
50 syn keyword dOpOverload opCat_r opEquals opEquals opCmp opCmp opCmp opCmp
51 syn keyword dOpOverload opAddAssign opSubAssign opMulAssign opDivAssign
52 syn keyword dOpOverload opModAssign opAndAssign opOrAssign opXorAssign
53 syn keyword dOpOverload opShlAssign opShrAssign opUShrAssign opCatAssign
Bram Moolenaar5baddf02006-03-12 21:53:56 +000054 syn keyword dOpOverload opIndex opIndexAssign opCall opSlice opSliceAssign opPos
55 syn keyword dOpOverload opAdd_r opMul_r opAnd_r opOr_r opXor_r
Bram Moolenaar071d4272004-06-13 20:20:40 +000056endif
Bram Moolenaar21cf8232004-07-16 20:18:37 +000057syn keyword dType ushort int uint long ulong float
58syn keyword dType void byte ubyte double bit char wchar ucent cent
59syn keyword dType short bool dchar
60syn keyword dType real ireal ifloat idouble creal cfloat cdouble
61syn keyword dDebug deprecated unittest
62syn keyword dExceptions throw try catch finally
63syn keyword dScopeDecl public protected private export
Bram Moolenaar5baddf02006-03-12 21:53:56 +000064syn keyword dStatement version debug return with invariant body scope
Bram Moolenaar21cf8232004-07-16 20:18:37 +000065syn keyword dStatement in out inout asm mixin
66syn keyword dStatement function delegate
67syn keyword dStorageClass auto static override final const abstract volatile
68syn keyword dStorageClass synchronized
69syn keyword dPragma pragma
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
71
72" Assert is a statement and a module name.
73syn match dAssert "^assert\>"
74syn match dAssert "[^.]\s*\<assert\>"ms=s+1
75
76" Marks contents of the asm statment body as special
77"
78" TODO
79"syn match dAsmStatement "\<asm\>"
80"syn region dAsmBody start="asm[\n]*\s*{"hs=e+1 end="}"he=e-1 contains=dAsmStatement
81"
82"hi def link dAsmBody dUnicode
83"hi def link dAsmStatement dStatement
84
85" Labels
86"
87" We contain dScopeDecl so public: private: etc. are not highlighted like labels
Bram Moolenaar21cf8232004-07-16 20:18:37 +000088syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl
89syn keyword dLabel case default
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
91" Comments
92"
Bram Moolenaar21cf8232004-07-16 20:18:37 +000093syn keyword dTodo contained TODO FIXME TEMP XXX
94syn match dCommentStar contained "^\s*\*[^/]"me=e-1
95syn match dCommentStar contained "^\s*\*$"
96syn match dCommentPlus contained "^\s*+[^/]"me=e-1
97syn match dCommentPlus contained "^\s*+$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000098if exists("d_comment_strings")
Bram Moolenaar21cf8232004-07-16 20:18:37 +000099 syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell
100 syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell
101 syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell
102 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
103 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
104 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105else
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000106 syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,@Spell
107 syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell
108 syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109endif
110
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000111hi link dLineCommentString dBlockCommentString
112hi link dBlockCommentString dString
113hi link dNestedCommentString dString
114hi link dCommentStar dBlockComment
115hi link dCommentPlus dNestedComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000117" /+ +/ style comments and strings that span multiple lines can cause
118" problems. To play it safe, set minlines to a large number.
119syn sync minlines=200
120" Use ccomment for /* */ style comments
121syn sync ccomment dBlockComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122
123" Characters
124"
125syn match dSpecialCharError contained "[^']"
126
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000127" Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
128" These are not contained because they are considered string litterals
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000129syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000130syn match dEscSequence "\\&[^;& \t]\+;"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000131syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError
132syn match dCharacter "'\\''" contains=dEscSequence
133syn match dCharacter "'[^\\]'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135" Unicode characters
136"
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000137syn match dUnicode "\\u\d\{4\}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000139
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140" String.
141"
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000142syn region dString start=+"+ end=+"[cwd]\=+ contains=dEscSequence,@Spell
143syn region dRawString start=+`+ skip=+\\`+ end=+`[cwd]\=+ contains=@Spell
144syn region dRawString start=+r"+ skip=+\\"+ end=+"[cwd]\=+ contains=@Spell
145syn region dHexString start=+x"+ skip=+\\"+ end=+"[cwd]\=+ contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
147" Numbers
148"
149syn case ignore
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000150
151syn match dDec display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
152
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153" Hex number
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000154syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000155
156syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>"
157" flag an octal number with wrong digits
158syn match dOctalError display "\<0[0-7_]*[89][0-9_]*"
159
160" binary numbers
161syn match dBinary display "\<0b[01_]\+\(u\=l\=\|l\=u\=\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
163"floating point without the dot
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000164syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165"floating point number, with dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000166syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167"floating point number, starting with a dot, optional exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000168syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169"floating point number, without dot, with exponent
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000170"syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>"
171syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172
173"floating point without the dot
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000174syn match dHexFloat display "\<0x[0-9a-f_]\+\(fi\=\|l\=i\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175"floating point number, with dot, optional exponent
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000176syn match dHexFloat display "\<0x[0-9a-f_]\+\.[0-9a-f_]*\(p[-+]\=[0-9_]\+\)\=[fl]\=i\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177"floating point number, without dot, with exponent
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000178syn match dHexFloat display "\<0x[0-9a-f_]\+p[-+]\=[0-9_]\+[fl]\=i\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180syn case match
181
182" Pragma (preprocessor) support
183" TODO: Highlight following Integer and optional Filespec.
184syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$"
185
186
187" The default highlighting.
188"
189hi def link dBinary Number
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000190hi def link dDec Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191hi def link dHex Number
192hi def link dOctal Number
193hi def link dFloat Float
194hi def link dHexFloat Float
195hi def link dDebug Debug
196hi def link dBranch Conditional
197hi def link dConditional Conditional
198hi def link dLabel Label
199hi def link dUserLabel Label
200hi def link dRepeat Repeat
201hi def link dExceptions Exception
202hi def link dAssert Statement
203hi def link dStatement Statement
204hi def link dScopeDecl dStorageClass
205hi def link dStorageClass StorageClass
206hi def link dBoolean Boolean
207hi def link dUnicode Special
208hi def link dRawString String
209hi def link dString String
210hi def link dHexString String
211hi def link dCharacter Character
212hi def link dEscSequence SpecialChar
213hi def link dSpecialCharError Error
214hi def link dOctalError Error
215hi def link dOperator Operator
216hi def link dOpOverload Operator
217hi def link dConstant Constant
218hi def link dTypedef Typedef
219hi def link dStructure Structure
220hi def link dTodo Todo
221hi def link dType Type
222hi def link dLineComment Comment
223hi def link dBlockComment Comment
224hi def link dNestedComment Comment
225hi def link dExternal Include
226hi def link dPragma PreProc
227
228let b:current_syntax = "d"
Bram Moolenaar5baddf02006-03-12 21:53:56 +0000229
Bram Moolenaara5792f52005-11-23 21:25:05 +0000230" vim: ts=8 noet