xref: /vim-8.2.3635/runtime/syntax/d.vim (revision f4cd3e80)
1" Vim syntax file for the D programming language (version 0.137).
2"
3" Language:	D
4" Maintainer:	Jason Mills<[email protected]>
5" 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.
10"
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"
27"   - Highlight the string prefix r and and postfixes c,w,d
28"
29
30" Quit when a syntax file was already loaded
31if exists("b:current_syntax")
32  finish
33endif
34
35" Keyword definitions
36"
37syn keyword dExternal		import package module extern
38syn keyword dConditional	if else switch iftype
39syn keyword dBranch		goto break continue
40syn keyword dRepeat		while for do foreach
41syn keyword dBoolean		true false
42syn keyword dConstant		null
43syn keyword dConstant		__FILE__ __LINE__ __DATE__ __TIME__ __TIMESTAMP__
44syn 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
48if exists("d_hl_operator_overload")
49  syn keyword dOpOverload	opNeg opCom opPostInc opPostDec opCast opAdd opSub opSub_r
50  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
56  syn keyword dOpOverload	opIndex opIndexAssign opCall opSlice opPos
57  syn keyword dOpOverload	opAdd_r opMul_r opAnd_r opOr_r opXor_r
58endif
59syn 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
72
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
90syn match dUserLabel	"^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=dLabel,dScopeDecl
91syn keyword dLabel	case default
92
93" Comments
94"
95syn 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*+$"
100if exists("d_comment_strings")
101  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
107else
108  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
111endif
112
113hi link dLineCommentString	dBlockCommentString
114hi link dBlockCommentString	dString
115hi link dNestedCommentString	dString
116hi link dCommentStar		dBlockComment
117hi link dCommentPlus		dNestedComment
118
119syn sync minlines=25
120
121" Characters
122"
123syn match dSpecialCharError contained "[^']"
124
125" Escape sequences (oct,specal char,hex,wchar, character entities \&xxx;)
126" These are not contained because they are considered string litterals
127syn match dEscSequence	"\\\(\o\{1,3}\|[\"\\'\\?ntbrfva]\|u\x\{4}\|U\x\{8}\|x\x\x\)"
128syn match dEscSequence "\\&[^;& \t]\+;"
129syn match dCharacter	"'[^']*'" contains=dEscSequence,dSpecialCharError
130syn match dCharacter	"'\\''" contains=dEscSequence
131syn match dCharacter	"'[^\\]'"
132
133" Unicode characters
134"
135syn match dUnicode "\\u\d\{4\}"
136
137
138
139" String.
140"
141syn region dString	start=+"+ end=+"+ contains=dEscSequence,@Spell
142syn region dRawString	start=+`+ skip=+\\`+ end=+`+ contains=@Spell
143"syn region dRawString	start=+r"+ skip=+\\"+ end=+"+ contains=@Spell
144syn region dHexString	start=+x"+ skip=+\\"+ end=+"+
145
146" Numbers
147"
148syn case ignore
149syn match dInt		display "\<\d[0-9_]*\(u\=l\=\|l\=u\=\)\>"
150" Hex number
151syn match dHex		display "\<0x[0-9a-f_]\+\(u\=l\=\|l\=u\=\)\>"
152syn match dHex		display "\<\x[0-9a-f_]*h\(u\=l\=\|l\=u\=\)\>"
153" Flag the first zero of an octal number as something special
154syn match dOctal	display "\<0[0-7_]\+\(u\=l\=\|l\=u\=\)\>" contains=cOctalZero
155syn match dOctalZero	display contained "\<0"
156
157"floating point without the dot
158syn match dFloat	display "\<\d[0-9_]*\(fi\=\|l\=i\)\>"
159"floating point number, with dot, optional exponent
160syn match dFloat	display "\<\d[0-9_]*\.[0-9_]*\(e[-+]\=[0-9_]\+\)\=[fl]\=i\="
161"floating point number, starting with a dot, optional exponent
162syn match dFloat	display "\(\.[0-9_]\+\)\(e[-+]\=[0-9_]\+\)\=[fl]\=i\=\>"
163"floating point number, without dot, with exponent
164"syn match dFloat	display "\<\d\+e[-+]\=\d\+[fl]\=\>"
165syn match dFloat	display "\<\d[0-9_]*e[-+]\=[0-9_]\+[fl]\=\>"
166
167"floating point without the dot
168syn match dHexFloat	display "\<0x\x\+\(fi\=\|l\=i\)\>"
169"floating point number, with dot, optional exponent
170syn match dHexFloat	display "\<0x\x\+\.\x*\(p[-+]\=\x\+\)\=[fl]\=i\="
171"floating point number, without dot, with exponent
172syn match dHexFloat	display "\<0x\x\+p[-+]\=\x\+[fl]\=\>"
173
174" binary numbers
175syn match dBinary	display "\<0b[01_]\+\>"
176" flag an octal number with wrong digits
177syn match dOctalError	display "0\o*[89]\d*"
178syn 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
228" vim: ts=8 noet
229