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