7
|
1 " Vim syntax file
|
14372
|
2 " Language: C#
|
|
3 " Maintainer: Nick Jensen <nickspoon@gmail.com>
|
|
4 " Former Maintainers: Anduin Withers <awithers@anduin.com>
|
|
5 " Johannes Zellner <johannes@zellner.org>
|
31383
|
6 " Last Change: 2022-11-16
|
14372
|
7 " Filenames: *.cs
|
|
8 " License: Vim (see :h license)
|
|
9 " Repository: https://github.com/nickspoons/vim-cs
|
7
|
10 "
|
29104
|
11 " References:
|
|
12 " - ECMA-334 5th Edition: C# Language Specification
|
|
13 " https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
|
|
14 " - C# Language Design: Draft 6th Edition and later proposals
|
|
15 " https://github.com/dotnet/csharplang
|
7
|
16
|
15131
|
17 if exists('b:current_syntax')
|
|
18 finish
|
7
|
19 endif
|
|
20
|
15131
|
21 let s:save_cpo = &cpoptions
|
|
22 set cpoptions&vim
|
7
|
23
|
14372
|
24 syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic
|
29104
|
25 syn keyword csType nint nuint " contextual
|
|
26
|
|
27 syn keyword csStorage enum interface namespace struct
|
31383
|
28 syn match csStorage "\<record\ze\_s\+@\=\h\w*\_s*[<(:{;]"
|
|
29 syn match csStorage "\%(\<\%(partial\|new\|public\|protected\|internal\|private\|abstract\|sealed\|static\|unsafe\|readonly\)\)\@9<=\_s\+record\>"
|
|
30 syn match csStorage "\<record\ze\_s\+\%(class\|struct\)"
|
29104
|
31 syn match csStorage "\<delegate\>"
|
14372
|
32 syn keyword csRepeat break continue do for foreach goto return while
|
|
33 syn keyword csConditional else if switch
|
|
34 syn keyword csLabel case default
|
29104
|
35
|
|
36 syn match csNamespaceAlias "@\=\h\w*\ze\_s*::" display
|
|
37 syn match csGlobalNamespaceAlias "global\ze\_s*::" display
|
|
38 syn cluster csNamespaceAlias contains=csGlobalNamespaceAlias,csNamespaceAlias,csNamespaceAliasQualifier
|
|
39
|
|
40 " user labels
|
23047
|
41 syn match csLabel display +^\s*\I\i*\s*:\%([^:]\)\@=+
|
29104
|
42
|
|
43 " Function pointers
|
|
44 syn match csType "\<delegate\s*\*" contains=csOpSymbols nextgroup=csManagedModifier skipwhite skipempty
|
|
45 syn keyword csManagedModifier managed unmanaged contained
|
|
46
|
|
47 " Modifiers
|
|
48 syn match csUsingModifier "\<global\ze\_s\+using\>"
|
|
49 syn keyword csAccessModifier internal private protected public
|
31383
|
50 syn keyword csModifier operator nextgroup=csCheckedModifier skipwhite skipempty
|
|
51 syn keyword csCheckedModifier checked contained
|
|
52
|
29104
|
53 " TODO: in new out
|
|
54 syn keyword csModifier abstract const event override readonly sealed static virtual volatile
|
|
55 syn match csModifier "\<\%(extern\|fixed\|unsafe\)\>"
|
|
56 syn match csModifier "\<partial\ze\_s\+\%(class\|struct\|interface\|record\|void\)\>"
|
|
57
|
14372
|
58 syn keyword csException try catch finally throw when
|
29104
|
59 syn keyword csLinq ascending by descending equals from group in into join let on orderby select
|
|
60 syn match csLinq "\<where\>"
|
|
61
|
|
62 " Type parameter constraint clause
|
|
63 syn match csStorage "\<where\>\ze\_s\+@\=\h\w*\_s*:"
|
|
64
|
|
65 " Async
|
|
66 syn keyword csAsyncModifier async
|
|
67 syn keyword csAsyncOperator await
|
|
68
|
|
69 syn match csStorage "\<extern\ze\s\+alias\>"
|
|
70 syn match csStorage "\%(\<extern\s\+\)\@16<=alias\>"
|
7
|
71
|
29104
|
72 syn match csStatement "\<\%(checked\|unchecked\|unsafe\)\ze\_s*{"
|
|
73 syn match csStatement "\<fixed\ze\_s*("
|
|
74 syn keyword csStatement lock
|
|
75 syn match csStatement "\<yield\ze\_s\+\%(return\|break\)\>"
|
|
76
|
|
77 syn match csAccessor "\<\%(get\|set\|init\|add\|remove\)\ze\_s*\%([;{]\|=>\)"
|
|
78
|
|
79 syn keyword csAccess base
|
|
80 syn match csAccess "\<this\>"
|
|
81
|
|
82 " Extension method parameter modifier
|
|
83 syn match csModifier "\<this\ze\_s\+@\=\h"
|
|
84
|
31383
|
85 syn keyword csUnspecifiedStatement as in is nameof out params ref sizeof stackalloc using
|
29104
|
86 syn keyword csUnsupportedStatement value
|
14372
|
87 syn keyword csUnspecifiedKeyword explicit implicit
|
7
|
88
|
15131
|
89 " Operators
|
29104
|
90 syn keyword csTypeOf typeof nextgroup=csTypeOfOperand,csTypeOfError skipwhite skipempty
|
|
91 syn region csTypeOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
|
|
92 syn match csTypeOfError "[^([:space:]]" contained
|
|
93 syn match csKeywordOperator "\<\%(checked\|unchecked\)\ze\_s*("
|
15131
|
94
|
14372
|
95 " Punctuation
|
29104
|
96 syn match csBraces "[{}[\]]" display
|
14372
|
97 syn match csParens "[()]" display
|
17667
|
98 syn match csOpSymbols "+\{1,2}" display
|
|
99 syn match csOpSymbols "-\{1,2}" display
|
|
100 syn match csOpSymbols "=\{1,2}" display
|
|
101 syn match csOpSymbols ">\{1,2}" display
|
|
102 syn match csOpSymbols "<\{1,2}" display
|
14372
|
103 syn match csOpSymbols "[!><+\-*/]=" display
|
|
104 syn match csOpSymbols "[!*/^]" display
|
|
105 syn match csOpSymbols "=>" display
|
|
106 syn match csEndColon ";" display
|
|
107 syn match csLogicSymbols "&&" display
|
|
108 syn match csLogicSymbols "||" display
|
|
109 syn match csLogicSymbols "?" display
|
|
110 syn match csLogicSymbols ":" display
|
29104
|
111 syn match csNamespaceAliasQualifier "::" display
|
7
|
112
|
17667
|
113 " Generics
|
29104
|
114 syn region csGeneric matchgroup=csGenericBraces start="<" end=">" oneline contains=csType,csGeneric,@csNamespaceAlias,csUserType,csUserIdentifier,csUserInterface,csUserMethod
|
17667
|
115
|
7
|
116 " Comments
|
|
117 "
|
|
118 " PROVIDES: @csCommentHook
|
14372
|
119 syn keyword csTodo contained TODO FIXME XXX NOTE HACK TBD
|
29104
|
120 syn region csBlockComment start="/\*" end="\*/" contains=@csCommentHook,csTodo,@Spell
|
|
121 syn match csLineComment "//.*$" contains=@csCommentHook,csTodo,@Spell
|
|
122 syn cluster csComment contains=csLineComment,csBlockComment
|
|
123
|
|
124 syn region csSummary start="^\s*/// <summary" end="^\%\(\s*///\)\@!" transparent fold keepend
|
|
125
|
|
126 " xml markup inside '///' and /**...*/ comments
|
|
127 syn cluster xmlRegionHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
|
|
128 syn cluster xmlCdataHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
|
|
129 syn cluster xmlStartTagHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
|
|
130 syn cluster xmlTagHook add=csXmlTag
|
|
131 syn cluster xmlAttribHook add=csXmlAttrib
|
7
|
132
|
29104
|
133 " https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
|
|
134 syn keyword csXmlTag contained summary remarks
|
|
135 syn keyword csXmlTag contained returns param paramref exception value
|
|
136 syn keyword csXmlTag contained para list c code example
|
|
137 syn keyword csXmlTag contained inheritdoc include
|
|
138 syn keyword csXmlTag contained see seealso
|
|
139 syn keyword csXmlTag contained typeparam typeparamref
|
|
140 syn keyword csXmlTag contained b i u br a
|
|
141 syn keyword csXmlAttrib contained cref href
|
7
|
142
|
29104
|
143 syn match csXmlLineCommentLeader "///" contained
|
|
144 syn match csXmlLineComment "///.*$" contains=csXmlLineCommentLeader,@csXml,@Spell keepend
|
|
145 syn match csXmlBlockCommentMiddle "^\s*\zs\*" contained
|
|
146 syn region csXmlBlockComment start="/\*\*" end="\*/" contains=@csXml,@Spell,csXmlBlockCommentMiddle keepend
|
14372
|
147 syn include @csXml syntax/xml.vim
|
|
148 hi def link xmlRegion Comment
|
7
|
149
|
19303
|
150 " Since syntax/xml.vim contains `syn spell toplevel`, we need to set it back to `default` here.
|
|
151 syn spell default
|
7
|
152
|
29104
|
153 " Pre-processing directives
|
|
154 syn region csPreProcDeclaration start="^\s*\zs#\s*\%(define\|undef\)\>" end="$" contains=csLineComment keepend
|
|
155 syn region csPreProcConditional start="^\s*\zs#\s*\%(if\|elif\)\>" end="$" contains=csLineComment keepend
|
|
156 syn region csPreProcConditional start="^\s*\zs#\s*\%(else\|endif\)\>" end="$" contains=csLineComment keepend
|
|
157 syn region csPreProcLine start="^\s*\zs#\s*line\>" end="$" contains=csLineComment keepend
|
|
158 syn region csPreProcDiagnostic start="^\s*\zs#\s*\%(error\|warning\)\>" end="$"
|
|
159 syn region csPreProcConditionalSection matchgroup=csPreProcRegion start="^\s*#\s*region\>.*" end="^\s*#\s*endregion\>.*" transparent fold contains=TOP
|
|
160 syn region csPreProcPragma start="^\s*\zs#\s*pragma\>" end="$" contains=csLineComment keepend
|
|
161 syn region csPreProcNullable start="^\s*\zs#\s*nullable\>" end="$" contains=csLineComment keepend
|
7
|
162
|
29104
|
163 if expand('%:e') == 'csx' || getline('1') =~ '^#!.*\<dotnet-script\>'
|
|
164 syn region csPreProcInclude start="^\s*\zs#\s*\%(load\|r\)\>" end="$" contains=csLineComment keepend
|
|
165 syn match csShebang "\%^#!.*" display
|
|
166 endif
|
7
|
167
|
29104
|
168 syn cluster csPreProcessor contains=csPreProc.*
|
|
169
|
|
170 syn region csClassType start="\<class\>"hs=s+6 end=">" end="[:{]"me=e-1 contains=csClass
|
17667
|
171 " csUserType may be defined by user scripts/plugins - it should be contained in csNewType
|
29104
|
172 syn region csNewType start="\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,@csNamespaceAlias,csUserType
|
14372
|
173 syn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
|
|
174 syn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
|
|
175 syn keyword csNew new contained
|
|
176 syn keyword csClass class contained
|
|
177 syn keyword csIsAs is as
|
7
|
178
|
29104
|
179 syn keyword csBoolean false true
|
|
180 syn keyword csNull null
|
|
181
|
7
|
182 " Strings and constants
|
14372
|
183 syn match csSpecialError "\\." contained
|
|
184 syn match csSpecialCharError "[^']" contained
|
29104
|
185 " Character literals
|
|
186 syn match csSpecialChar +\\["\\'0abfnrtv]+ contained display
|
|
187 syn match csUnicodeNumber +\\x\x\{1,4}+ contained contains=csUnicodeSpecifier display
|
14372
|
188 syn match csUnicodeNumber +\\u\x\{4}+ contained contains=csUnicodeSpecifier display
|
29104
|
189 syn match csUnicodeNumber +\\U00\x\{6}+ contained contains=csUnicodeSpecifier display
|
|
190 syn match csUnicodeSpecifier +\\[uUx]+ contained display
|
14372
|
191
|
31383
|
192 syn region csString matchgroup=csQuote start=+"+ end=+"\%(u8\)\=+ end=+$+ extend contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell
|
23047
|
193 syn match csCharacter "'[^']*'" contains=csSpecialChar,csSpecialCharError,csUnicodeNumber display
|
14372
|
194 syn match csCharacter "'\\''" contains=csSpecialChar display
|
|
195 syn match csCharacter "'[^\\]'" display
|
29104
|
196
|
|
197 " Numbers
|
|
198 syn case ignore
|
|
199 syn match csInteger "\<0b[01_]*[01]\%([lu]\|lu\|ul\)\=\>" display
|
|
200 syn match csInteger "\<\d\+\%(_\+\d\+\)*\%([lu]\|lu\|ul\)\=\>" display
|
|
201 syn match csInteger "\<0x[[:xdigit:]_]*\x\%([lu]\|lu\|ul\)\=\>" display
|
|
202 syn match csReal "\<\d\+\%(_\+\d\+\)*\.\d\+\%(_\+\d\+\)*\%\(e[-+]\=\d\+\%(_\+\d\+\)*\)\=[fdm]\=" display
|
|
203 syn match csReal "\.\d\+\%(_\+\d\+\)*\%(e[-+]\=\d\+\%(_\+\d\+\)*\)\=[fdm]\=\>" display
|
|
204 syn match csReal "\<\d\+\%(_\+\d\+\)*e[-+]\=\d\+\%(_\+\d\+\)*[fdm]\=\>" display
|
|
205 syn match csReal "\<\d\+\%(_\+\d\+\)*[fdm]\>" display
|
|
206 syn case match
|
|
207 syn cluster csNumber contains=csInteger,csReal
|
14372
|
208
|
31383
|
209 syn region csInterpolatedString matchgroup=csQuote start=+\$"+ end=+"\%(u8\)\=+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,@Spell
|
14372
|
210
|
23047
|
211 syn region csInterpolation matchgroup=csInterpolationDelimiter start=+{+ end=+}+ keepend contained contains=@csAll,csBraced,csBracketed,csInterpolationAlign,csInterpolationFormat
|
14372
|
212 syn match csEscapedInterpolation "{{" transparent contains=NONE display
|
|
213 syn match csEscapedInterpolation "}}" transparent contains=NONE display
|
29104
|
214 syn region csInterpolationAlign matchgroup=csInterpolationAlignDel start=+,+ end=+}+ end=+:+me=e-1 contained contains=@csNumber,csBoolean,csConstant,csCharacter,csParens,csOpSymbols,csString,csBracketed display
|
14372
|
215 syn match csInterpolationFormat +:[^}]\+}+ contained contains=csInterpolationFormatDel display
|
|
216 syn match csInterpolationAlignDel +,+ contained display
|
|
217 syn match csInterpolationFormatDel +:+ contained display
|
|
218
|
31383
|
219 syn region csVerbatimString matchgroup=csQuote start=+@"+ end=+"\%(u8\)\=+ skip=+""+ extend contains=csVerbatimQuote,@Spell
|
14372
|
220 syn match csVerbatimQuote +""+ contained
|
29104
|
221
|
31383
|
222 syn region csInterVerbString matchgroup=csQuote start=+$@"+ start=+@$"+ end=+"\%(u8\)\=+ skip=+""+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,csVerbatimQuote,@Spell
|
14372
|
223
|
29104
|
224 syn cluster csString contains=csString,csInterpolatedString,csVerbatimString,csInterVerbString
|
|
225
|
|
226 syn cluster csLiteral contains=csBoolean,@csNumber,csCharacter,@csString,csNull
|
14372
|
227
|
23047
|
228 syn region csBracketed matchgroup=csParens start=+(+ end=+)+ extend contained transparent contains=@csAll,csBraced,csBracketed
|
|
229 syn region csBraced matchgroup=csParens start=+{+ end=+}+ extend contained transparent contains=@csAll,csBraced,csBracketed
|
14372
|
230
|
29104
|
231 syn cluster csAll contains=@csLiteral,csClassType,@csComment,csEndColon,csIsType,csLabel,csLogicSymbols,csNewType,csOpSymbols,csParens,@csPreProcessor,csSummary,@csNamespaceAlias,csType,csUnicodeNumber,csUserType,csUserIdentifier,csUserInterface,csUserMethod
|
|
232
|
|
233 " Keyword identifiers
|
|
234 syn match csIdentifier "@\h\w*"
|
7
|
235
|
|
236 " The default highlighting.
|
29104
|
237 hi def link csUnspecifiedStatement Statement
|
|
238 hi def link csUnsupportedStatement Statement
|
|
239 hi def link csUnspecifiedKeyword Keyword
|
|
240
|
|
241 hi def link csGlobalNamespaceAlias Include
|
|
242
|
14372
|
243 hi def link csType Type
|
|
244 hi def link csClassType Type
|
|
245 hi def link csIsType Type
|
29104
|
246
|
15131
|
247 hi def link csStorage Structure
|
|
248 hi def link csClass Structure
|
29104
|
249 hi def link csNew Statement
|
|
250 hi def link csIsAs Keyword
|
|
251 hi def link csAccessor Keyword
|
|
252 hi def link csAccess Keyword
|
|
253
|
|
254 hi def link csLinq Statement
|
|
255
|
|
256 hi def link csStatement Statement
|
14372
|
257 hi def link csRepeat Repeat
|
|
258 hi def link csConditional Conditional
|
|
259 hi def link csLabel Label
|
29104
|
260 hi def link csException Exception
|
|
261
|
14372
|
262 hi def link csModifier StorageClass
|
29104
|
263 hi def link csAccessModifier csModifier
|
|
264 hi def link csAsyncModifier csModifier
|
31383
|
265 hi def link csCheckedModifier csModifier
|
29104
|
266 hi def link csManagedModifier csModifier
|
|
267 hi def link csUsingModifier csModifier
|
14372
|
268
|
|
269 hi def link csTodo Todo
|
|
270 hi def link csComment Comment
|
29104
|
271 hi def link csLineComment csComment
|
|
272 hi def link csBlockComment csComment
|
7
|
273
|
29104
|
274 hi def link csKeywordOperator Keyword
|
|
275 hi def link csAsyncOperator csKeywordOperator
|
|
276 hi def link csTypeOf csKeywordOperator
|
|
277 hi def link csTypeOfOperand Typedef
|
|
278 hi def link csTypeOfError Error
|
14372
|
279 hi def link csOpSymbols Operator
|
15131
|
280 hi def link csLogicSymbols Operator
|
7
|
281
|
14372
|
282 hi def link csSpecialError Error
|
|
283 hi def link csSpecialCharError Error
|
|
284 hi def link csString String
|
|
285 hi def link csQuote String
|
|
286 hi def link csInterpolatedString String
|
|
287 hi def link csVerbatimString String
|
|
288 hi def link csInterVerbString String
|
|
289 hi def link csVerbatimQuote SpecialChar
|
29104
|
290
|
|
291 hi def link csPreProc PreProc
|
|
292 hi def link csPreProcDeclaration Define
|
|
293 hi def link csPreProcConditional PreCondit
|
|
294 hi def link csPreProcLine csPreProc
|
|
295 hi def link csPreProcDiagnostic csPreProc
|
|
296 hi def link csPreProcRegion csPreProc
|
|
297 hi def link csPreProcPragma csPreProc
|
|
298 hi def link csPreProcNullable csPreProc
|
|
299 hi def link csPreProcInclude csPreProc
|
|
300 hi def link csShebang csPreProc
|
|
301
|
|
302 hi def link csConstant Constant
|
|
303 hi def link csNull Constant
|
|
304 hi def link csBoolean Boolean
|
14372
|
305 hi def link csCharacter Character
|
|
306 hi def link csSpecialChar SpecialChar
|
29104
|
307 hi def link csInteger Number
|
|
308 hi def link csReal Float
|
14372
|
309 hi def link csUnicodeNumber SpecialChar
|
|
310 hi def link csUnicodeSpecifier SpecialChar
|
|
311 hi def link csInterpolationDelimiter Delimiter
|
|
312 hi def link csInterpolationAlignDel csInterpolationDelimiter
|
|
313 hi def link csInterpolationFormat csInterpolationDelimiter
|
|
314 hi def link csInterpolationFormatDel csInterpolationDelimiter
|
7
|
315
|
17667
|
316 hi def link csGenericBraces csBraces
|
|
317
|
7
|
318 " xml markup
|
29104
|
319 hi def link csXmlLineCommentLeader Comment
|
|
320 hi def link csXmlLineComment Comment
|
|
321 hi def link csXmlBlockComment Comment
|
|
322 hi def link csXmlBlockCommentMiddle csXmlBlockComment
|
14372
|
323 hi def link csXmlTag Statement
|
29104
|
324 hi def link csXmlAttrib Statement
|
7
|
325
|
15131
|
326 let b:current_syntax = 'cs'
|
7
|
327
|
15131
|
328 let &cpoptions = s:save_cpo
|
|
329 unlet s:save_cpo
|
7
|
330
|
14372
|
331 " vim: vts=16,28
|