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