1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
" Vim syntax file for the D programming language (version 1.076 and 2.069).
"
" Language: D
" Maintainer: Jesse Phillips <Jesse.K.Phillips+D@gmail.com>
" Last Change: 2016 Feb 2
" Version: 0.28
"
" Contributors:
" - Jason Mills: original Maintainer
" - Kirk McDonald
" - Tim Keating
" - Frank Benoit
" - Shougo Matsushita
" - Ellery Newcomer
" - Steven N. Oliver
" - Sohgo Takeuchi
" - Robert Clipsham
" - Petar Kirov
"
" Please submit bugs/comments/suggestions to the github repo:
" https://github.com/JesseKPhillips/d.vim
"
" Options:
" d_comment_strings - Set to highlight strings and numbers in comments.
"
" d_hl_operator_overload - Set to highlight D's specially named functions
" that when overloaded implement unary and binary operators (e.g. opCmp).
"
" d_hl_object_types - Set to highlight some common types from object.di.
" Quit when a syntax file was already loaded
if exists("b:current_syntax")
finish
endif
" Support cpoptions
let s:cpo_save = &cpo
set cpo&vim
" Set the current syntax to be known as d
let b:current_syntax = "d"
" Keyword definitions
"
syn keyword dExternal contained import module
syn keyword dAssert assert
syn keyword dConditional if else switch
syn keyword dBranch goto break continue
syn keyword dRepeat while for do foreach foreach_reverse
syn keyword dBoolean true false
syn keyword dConstant null
syn keyword dConstant __FILE__ __LINE__ __EOF__ __VERSION__
syn keyword dConstant __DATE__ __TIME__ __TIMESTAMP__ __VENDOR__
syn keyword dConstant __MODULE__ __FUNCTION__ __PRETTY_FUNCTION__
syn keyword dTypedef alias typedef
syn keyword dStructure template interface class struct union
syn keyword dEnum enum
syn keyword dOperator new delete typeof typeid cast align is
syn keyword dOperator this super
if exists("d_hl_operator_overload")
syn keyword dOpOverload opNeg opCom opPostInc opPostDec opCast opAdd
syn keyword dOpOverload opSub opSub_r opMul opDiv opDiv_r opMod
syn keyword dOpOverload opMod_r opAnd opOr opXor opShl opShl_r opShr
syn keyword dOpOverload opShr_r opUShr opUShr_r opCat
syn keyword dOpOverload opCat_r opEquals opCmp
syn keyword dOpOverload opAssign opAddAssign opSubAssign opMulAssign
syn keyword dOpOverload opDivAssign opModAssign opAndAssign
syn keyword dOpOverload opOrAssign opXorAssign opShlAssign
syn keyword dOpOverload opShrAssign opUShrAssign opCatAssign
syn keyword dOpOverload opIndex opIndexAssign opIndexOpAssign
syn keyword dOpOverload opCall opSlice opSliceAssign opSliceOpAssign
syn keyword dOpOverload opPos opAdd_r opMul_r opAnd_r opOr_r opXor_r
syn keyword dOpOverload opIn opIn_r opPow opDispatch opStar opDot
syn keyword dOpOverload opApply opApplyReverse opDollar
syn keyword dOpOverload opUnary opIndexUnary opSliceUnary
syn keyword dOpOverload opBinary opBinaryRight
endif
syn keyword dType byte ubyte short ushort int uint long ulong cent ucent
syn keyword dType void bool Object
syn keyword dType float double real
syn keyword dType ushort int uint long ulong float
syn keyword dType char wchar dchar string wstring dstring
syn keyword dType ireal ifloat idouble creal cfloat cdouble
syn keyword dType size_t ptrdiff_t sizediff_t equals_t hash_t
if exists("d_hl_object_types")
syn keyword dType Object Throwable AssociativeArray Error Exception
syn keyword dType Interface OffsetTypeInfo TypeInfo TypeInfo_Typedef
syn keyword dType TypeInfo_Enum TypeInfo_Pointer TypeInfo_Array
syn keyword dType TypeInfo_StaticArray TypeInfo_AssociativeArray
syn keyword dType TypeInfo_Function TypeInfo_Delegate TypeInfo_Class
syn keyword dType ClassInfo TypeInfo_Interface TypeInfo_Struct
syn keyword dType TypeInfo_Tuple TypeInfo_Const TypeInfo_Invariant
syn keyword dType TypeInfo_Shared TypeInfo_Inout MemberInfo
syn keyword dType MemberInfo_field MemberInfo_function ModuleInfo
endif
syn keyword dDebug deprecated unittest invariant
syn keyword dExceptions throw try catch finally
syn keyword dScopeDecl public protected private export package
syn keyword dStatement debug return with
syn keyword dStatement function delegate __ctfe mixin macro __simd
syn keyword dStatement in out body
syn keyword dStorageClass contained in out scope
syn keyword dStorageClass inout ref lazy pure nothrow
syn keyword dStorageClass auto static override final abstract volatile
syn keyword dStorageClass __gshared __vector
syn keyword dStorageClass synchronized shared immutable const lazy
syn keyword dIdentifier _arguments _argptr __vptr __monitor
syn keyword dIdentifier _ctor _dtor __argTypes __overloadset
syn keyword dScopeIdentifier contained exit success failure
syn keyword dTraitsIdentifier contained isAbstractClass isArithmetic
syn keyword dTraitsIdentifier contained isAssociativeArray isFinalClass
syn keyword dTraitsIdentifier contained isPOD isNested isFloating
syn keyword dTraitsIdentifier contained isIntegral isScalar isStaticArray
syn keyword dTraitsIdentifier contained isUnsigned isVirtualFunction
syn keyword dTraitsIdentifier contained isVirtualMethod isAbstractFunction
syn keyword dTraitsIdentifier contained isFinalFunction isStaticFunction
syn keyword dTraitsIdentifier contained isOverrideFunction isTemplate
syn keyword dTraitsIdentifier contained isRef isOut isLazy hasMember
syn keyword dTraitsIdentifier contained identifier getAliasThis
syn keyword dTraitsIdentifier contained getAttributes getFunctionAttributes getMember
syn keyword dTraitsIdentifier contained getOverloads getPointerBitmap getProtection
syn keyword dTraitsIdentifier contained getVirtualFunctions getVirtualIndex
syn keyword dTraitsIdentifier contained getVirtualMethods getUnitTests
syn keyword dTraitsIdentifier contained parent classInstanceSize allMembers
syn keyword dTraitsIdentifier contained derivedMembers isSame compiles
syn keyword dPragmaIdentifier contained inline lib mangle msg startaddress GNU_asm
syn keyword dExternIdentifier contained C C++ D Windows Pascal System Objective-C
syn keyword dAttribute contained safe trusted system
syn keyword dAttribute contained property disable nogc
syn keyword dVersionIdentifier contained DigitalMars GNU LDC SDC D_NET
syn keyword dVersionIdentifier contained X86 X86_64 ARM PPC PPC64 IA64 MIPS MIPS64 Alpha
syn keyword dVersionIdentifier contained SPARC SPARC64 S390 S390X HPPA HPPA64 SH SH64
syn keyword dVersionIdentifier contained linux Posix OSX FreeBSD Windows Win32 Win64
syn keyword dVersionIdentifier contained OpenBSD BSD Solaris AIX SkyOS SysV3 SysV4 Hurd
syn keyword dVersionIdentifier contained Cygwin MinGW
syn keyword dVersionIdentifier contained LittleEndian BigEndian
syn keyword dVersionIdentifier contained D_InlineAsm_X86 D_InlineAsm_X86_64
syn keyword dVersionIdentifier contained D_Version2 D_Coverage D_Ddoc D_LP64 D_PIC
syn keyword dVersionIdentifier contained unittest assert none all
syn cluster dComment contains=dNestedComment,dBlockComment,dLineComment
" Highlight the sharpbang
syn match dSharpBang "\%^#!.*" display
" Attributes/annotations
syn match dAnnotation "@[_$a-zA-Z][_$a-zA-Z0-9_]*\>" contains=dAttribute
" Version Identifiers
syn match dVersion "\<version\>"
syn match dVersion "\<version\s*([_a-zA-Z][_a-zA-Z0-9]*\>"he=s+7 contains=dVersionIdentifier
" Scope Identifiers
syn match dStatement "\<scope\>"
syn match dStatement "\<scope\s*([_a-zA-Z][_a-zA-Z0-9]*\>"he=s+5 contains=dScopeIdentifier
" Traits Statement
syn match dStatement "\<__traits\>"
syn match dStatement "\<__traits\s*([_a-zA-Z][_a-zA-Z0-9]*\>"he=s+8 contains=dTraitsIdentifier
" Pragma Statement
syn match dPragma "\<pragma\>"
syn match dPragma "\<pragma\s*([_a-zA-Z][_a-zA-Z0-9]*\>"he=s+6 contains=dPragmaIdentifier
" Necessary to highlight C++ in extern modifiers.
syn match dExternIdentifier "C\(++\)\?" contained
" Extern Identifiers
syn match dExternal "\<extern\>"
syn match dExtern "\<extern\s*([_a-zA-Z][_a-zA-Z0-9\+]*\>"he=s+6 contains=dExternIdentifier
" Make import a region to prevent highlighting keywords
syn region dImport start="\<import\_s" end=";" contains=dExternal,@dComment
" Make module a region to prevent highlighting keywords
syn region dImport start="\<module\_s" end=";" contains=dExternal,@dComment
" dTokens is used by the token string highlighting
syn cluster dTokens contains=dExternal,dConditional,dBranch,dRepeat,dBoolean
syn cluster dTokens add=dConstant,dTypedef,dStructure,dOperator,dOpOverload
syn cluster dTokens add=dType,dDebug,dExceptions,dScopeDecl,dStatement
syn cluster dTokens add=dStorageClass,dPragma,dAssert,dAnnotation,dEnum
syn cluster dTokens add=dParenString,dBrackString,dAngleString,dCurlyString
syn cluster dTokens add=dTokenString,dDelimString,dHereString
" Create a match for parameter lists to identify storage class
syn region paramlist start="(" end=")" contains=@dTokens
" Labels
"
" We contain dScopeDecl so public: private: etc. are not highlighted like labels
syn match dUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl,dEnum
syn keyword dLabel case default
syn cluster dTokens add=dUserLabel,dLabel
" Comments
"
syn match dCommentError display "\*/"
syn match dNestedCommentError display "+/"
syn keyword dTodo contained TODO FIXME TEMP REFACTOR REVIEW HACK BUG XXX
syn match dCommentStar contained "^\s*\*[^/]"me=e-1
syn match dCommentStar contained "^\s*\*$"
syn match dCommentPlus contained "^\s*+[^/]"me=e-1
syn match dCommentPlus contained "^\s*+$"
if exists("d_comment_strings")
syn region dBlockCommentString contained start=+"+ end=+"+ end=+\*/+me=s-1,he=s-1 contains=dCommentStar,dUnicode,dEscSequence,@Spell
syn region dNestedCommentString contained start=+"+ end=+"+ end="+"me=s-1,he=s-1 contains=dCommentPlus,dUnicode,dEscSequence,@Spell
syn region dLineCommentString contained start=+"+ end=+$\|"+ contains=dUnicode,dEscSequence,@Spell
endif
syn region dBlockComment start="/\*" end="\*/" contains=dBlockCommentString,dTodo,dCommentStartError,@Spell fold
syn region dNestedComment start="/+" end="+/" contains=dNestedComment,dNestedCommentString,dTodo,@Spell fold
syn match dLineComment "//.*" contains=dLineCommentString,dTodo,@Spell
hi link dLineCommentString dBlockCommentString
hi link dBlockCommentString dString
hi link dNestedCommentString dString
hi link dCommentStar dBlockComment
hi link dCommentPlus dNestedComment
syn cluster dTokens add=dBlockComment,dNestedComment,dLineComment
" /+ +/ style comments and strings that span multiple lines can cause
" problems. To play it safe, set minlines to a large number.
syn sync minlines=200
" Use ccomment for /* */ style comments
syn sync ccomment dBlockComment
" Characters
"
syn match dSpecialCharError contained "[^']"
" Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
" These are not contained because they are considered string literals.
syn match dEscSequence "\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
syn match dEscSequence "\\&[^;& \t]\+;"
syn match dCharacter "'[^']*'" contains=dEscSequence,dSpecialCharError
syn match dCharacter "'\\''" contains=dEscSequence
syn match dCharacter "'[^\\]'"
syn cluster dTokens add=dEscSequence,dCharacter
" Unicode characters
"
syn match dUnicode "\\u\d\{4\}"
" String.
"
syn match dFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
syn match dFormat display "%%" contained
syn region dString start=+"+ end=+"[cwd]\=+ skip=+\\\\\|\\"+ contains=dFormat,dEscSequence,@Spell
syn region dRawString start=+`+ end=+`[cwd]\=+ contains=@Spell
syn region dRawString start=+r"+ end=+"[cwd]\=+ contains=@Spell
syn region dHexString start=+x"+ end=+"[cwd]\=+ contains=@Spell
syn region dDelimString start=+q"\z(.\)+ end=+\z1"+ contains=@Spell
syn region dHereString start=+q"\z(\I\i*\)\n+ end=+^\z1"+ contains=@Spell
" Nesting delimited string contents
"
syn region dNestParenString start=+(+ end=+)+ contained transparent contains=dNestParenString,@Spell
syn region dNestBrackString start=+\[+ end=+\]+ contained transparent contains=dNestBrackString,@Spell
syn region dNestAngleString start=+<+ end=+>+ contained transparent contains=dNestAngleString,@Spell
syn region dNestCurlyString start=+{+ end=+}+ contained transparent contains=dNestCurlyString,@Spell
" Nesting delimited strings
"
syn region dParenString matchgroup=dParenString start=+q"(+ end=+)"+ contains=dNestParenString,@Spell
syn region dBrackString matchgroup=dBrackString start=+q"\[+ end=+\]"+ contains=dNestBrackString,@Spell
syn region dAngleString matchgroup=dAngleString start=+q"<+ end=+>"+ contains=dNestAngleString,@Spell
syn region dCurlyString matchgroup=dCurlyString start=+q"{+ end=+}"+ contains=dNestCurlyString,@Spell
hi link dParenString dNestString
hi link dBrackString dNestString
hi link dAngleString dNestString
hi link dCurlyString dNestString
syn cluster dTokens add=dString,dRawString,dHexString,dDelimString,dNestString
" Token strings
"
syn region dNestTokenString start=+{+ end=+}+ contained contains=dNestTokenString,@dTokens,dFormat
syn region dTokenString matchgroup=dTokenStringBrack transparent start=+q{+ end=+}+ contains=dNestTokenString,@dTokens,dFormat
syn cluster dTokens add=dTokenString
" Numbers
"
syn case ignore
syn match dDec display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
" Hex number
syn match dHex display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
syn match dOctal display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>"
" flag an octal number with wrong digits
syn match dOctalError display "\<0[0-7_]*[89][0-9_]*"
" binary numbers
syn match dBinary display "\<0b[01_]\+\(u\=l\=\|l\=u\=\)\>"
"floating point without the dot
syn match dFloat display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
"floating point number, with dot, optional exponent
syn match dFloat display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
"floating point number, starting with a dot, optional exponent
syn match dFloat display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
"floating point number, without dot, with exponent
"syn match dFloat display "\<\d\+e[-+]\=\d\+[fl]\=\>"
syn match dFloat display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
"floating point without the dot
syn match dHexFloat display "\<0x[0-9a-f_]\+\(fi\=\|l\=i\)\>"
"floating point number, with dot, optional exponent
syn match dHexFloat display "\<0x[0-9a-f_]\+\.[0-9a-f_]*\(p[-+]\=[0-9_]\+\)\=[fl]\=i\="
"floating point number, without dot, with exponent
syn match dHexFloat display "\<0x[0-9a-f_]\+p[-+]\=[0-9_]\+[fl]\=i\=\>"
syn cluster dTokens add=dDec,dHex,dOctal,dOctalError,dBinary,dFloat,dHexFloat
syn case match
" Pragma (preprocessor) support
" TODO: Highlight following Integer and optional Filespec.
syn region dPragma start="#\s*\(line\>\)" skip="\\$" end="$"
" Block
"
syn region dBlock start="{" end="}" transparent fold
" The default highlighting.
"
hi def link dBinary Number
hi def link dDec Number
hi def link dHex Number
hi def link dOctal Number
hi def link dFloat Float
hi def link dHexFloat Float
hi def link dDebug Debug
hi def link dBranch Conditional
hi def link dConditional Conditional
hi def link dLabel Label
hi def link dUserLabel Label
hi def link dRepeat Repeat
hi def link dExceptions Exception
hi def link dAssert Statement
hi def link dStatement Statement
hi def link dScopeDecl dStorageClass
hi def link dStorageClass StorageClass
hi def link dBoolean Boolean
hi def link dUnicode Special
hi def link dTokenStringBrack String
hi def link dHereString String
hi def link dNestString String
hi def link dDelimString String
hi def link dRawString String
hi def link dString String
hi def link dHexString String
hi def link dCharacter Character
hi def link dEscSequence SpecialChar
hi def link dFormat SpecialChar
hi def link dSpecialCharError Error
hi def link dOctalError Error
hi def link dOperator Operator
hi def link dOpOverload Identifier
hi def lin
|