1" Vim syntax file 2" Language: C# 3" Maintainer: Nick Jensen <[email protected]> 4" Former Maintainers: Anduin Withers <[email protected]> 5" Johannes Zellner <[email protected]> 6" Last Change: 2020-11-23 7" Filenames: *.cs 8" License: Vim (see :h license) 9" Repository: https://github.com/nickspoons/vim-cs 10" 11" REFERENCES: 12" [1] ECMA TC39: C# Language Specification (WD13Oct01.doc) 13 14if exists('b:current_syntax') 15 finish 16endif 17 18let s:save_cpo = &cpoptions 19set cpoptions&vim 20 21syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic 22syn keyword csStorage delegate enum interface namespace struct 23syn keyword csRepeat break continue do for foreach goto return while 24syn keyword csConditional else if switch 25syn keyword csLabel case default 26syn match csOperatorError display +::+ 27syn match csGlobal display +global::+ 28" user labels (see [1] 8.6 Statements) 29syn match csLabel display +^\s*\I\i*\s*:\%([^:]\)\@=+ 30syn keyword csModifier abstract const extern internal override private protected public readonly sealed static virtual volatile 31syn keyword csConstant false null true 32syn keyword csException try catch finally throw when 33syn keyword csLinq ascending by descending equals from group in into join let on orderby select where 34syn keyword csAsync async await 35 36syn keyword csUnspecifiedStatement as base checked event fixed in is lock nameof operator out params ref sizeof stackalloc this unchecked unsafe using 37syn keyword csUnsupportedStatement add remove value 38syn keyword csUnspecifiedKeyword explicit implicit 39 40" Contextual Keywords 41syn match csContextualStatement /\<yield[[:space:]\n]\+\%(return\|break\)/me=s+5 42syn match csContextualStatement /\<partial[[:space:]\n]\+\%(class\|struct\|interface\)/me=s+7 43syn match csContextualStatement /\<\%(get\|set\)\%(;\|[[:space:]\n]*{\)/me=s+3 44syn match csContextualStatement /\<\%(get\|set\)\s*=>/me=s+3 45syn match csContextualStatement /\<where\>[^:]\+:/me=s+5 46 47" Operators 48syn keyword csTypeOf typeof contained 49syn region csTypeOfStatement start="typeof(" end=")" contains=csType, csTypeOf 50 51" Punctuation 52syn match csBraces "[{}\[\]]" display 53syn match csParens "[()]" display 54syn match csOpSymbols "+\{1,2}" display 55syn match csOpSymbols "-\{1,2}" display 56syn match csOpSymbols "=\{1,2}" display 57syn match csOpSymbols ">\{1,2}" display 58syn match csOpSymbols "<\{1,2}" display 59syn match csOpSymbols "[!><+\-*/]=" display 60syn match csOpSymbols "[!*/^]" display 61syn match csOpSymbols "=>" display 62syn match csEndColon ";" display 63syn match csLogicSymbols "&&" display 64syn match csLogicSymbols "||" display 65syn match csLogicSymbols "?" display 66syn match csLogicSymbols ":" display 67 68" Generics 69syn region csGeneric matchgroup=csGenericBraces start="<" end=">" oneline contains=csType,csGeneric,csUserType,csUserIdentifier,csUserInterface,csUserMethod 70 71" Comments 72" 73" PROVIDES: @csCommentHook 74syn keyword csTodo contained TODO FIXME XXX NOTE HACK TBD 75syn region csComment start="/\*" end="\*/" contains=@csCommentHook,csTodo,@Spell 76syn match csComment "//.*$" contains=@csCommentHook,csTodo,@Spell 77 78" xml markup inside '///' comments 79syn cluster xmlRegionHook add=csXmlCommentLeader 80syn cluster xmlCdataHook add=csXmlCommentLeader 81syn cluster xmlStartTagHook add=csXmlCommentLeader 82syn keyword csXmlTag contained Libraries Packages Types Excluded ExcludedTypeName ExcludedLibraryName 83syn keyword csXmlTag contained ExcludedBucketName TypeExcluded Type TypeKind TypeSignature AssemblyInfo 84syn keyword csXmlTag contained AssemblyName AssemblyPublicKey AssemblyVersion AssemblyCulture Base 85syn keyword csXmlTag contained BaseTypeName Interfaces Interface InterfaceName Attributes Attribute 86syn keyword csXmlTag contained AttributeName Members Member MemberSignature MemberType MemberValue 87syn keyword csXmlTag contained ReturnValue ReturnType Parameters Parameter MemberOfPackage 88syn keyword csXmlTag contained ThreadingSafetyStatement Docs devdoc example overload remarks returns summary 89syn keyword csXmlTag contained threadsafe value internalonly nodoc exception param permission platnote 90syn keyword csXmlTag contained seealso b c i pre sub sup block code note paramref see subscript superscript 91syn keyword csXmlTag contained list listheader item term description altcompliant altmember 92 93syn cluster xmlTagHook add=csXmlTag 94 95syn match csXmlCommentLeader "///" contained 96syn match csXmlComment "///.*$" contains=csXmlCommentLeader,@csXml,@Spell keepend 97syn include @csXml syntax/xml.vim 98hi def link xmlRegion Comment 99 100" Since syntax/xml.vim contains `syn spell toplevel`, we need to set it back to `default` here. 101syn spell default 102 103" [1] 9.5 Pre-processing directives 104syn region csPreCondit start="^\s*#\s*\%(define\|undef\|if\|elif\|else\|endif\|line\|error\|warning\|pragma\)\>" skip="\\$" end="$" contains=csComment keepend 105syn region csRegion matchgroup=csPreCondit start="^\s*#\s*region.*$" end="^\s*#\s*endregion" transparent fold contains=TOP 106syn region csSummary start="^\s*/// <summary" end="^\%\(\s*///\)\@!" transparent fold keepend 107 108 109syn region csClassType start="@\@1<!\<class\>"hs=s+6 end="[:\n{]"me=e-1 contains=csClass 110" csUserType may be defined by user scripts/plugins - it should be contained in csNewType 111syn region csNewType start="@\@1<!\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,csUserType 112syn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 113syn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 114syn keyword csNew new contained 115syn keyword csClass class contained 116syn keyword csIsAs is as 117 118" Strings and constants 119syn match csSpecialError "\\." contained 120syn match csSpecialCharError "[^']" contained 121" [1] 9.4.4.4 Character literals 122syn match csSpecialChar +\\["\\'0abfnrtvx]+ contained display 123syn match csUnicodeNumber +\\x\x\{2,4}+ contained contains=csUnicodeSpecifier display 124syn match csUnicodeNumber +\\u\x\{4}+ contained contains=csUnicodeSpecifier display 125syn match csUnicodeNumber +\\U\x\{8}+ contained contains=csUnicodeSpecifier display 126syn match csUnicodeSpecifier +\\[uU]+ contained display 127 128syn region csString matchgroup=csQuote start=+"+ end=+"+ end=+$+ extend contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 129syn match csCharacter "'[^']*'" contains=csSpecialChar,csSpecialCharError,csUnicodeNumber display 130syn match csCharacter "'\\''" contains=csSpecialChar display 131syn match csCharacter "'[^\\]'" display 132syn match csNumber "\<0[0-7]*[lL]\=\>" display 133syn match csNumber "\<0[xX][[:xdigit:]_]\+[lL]\=\>" display 134syn match csNumber "\<0[bB][01_]\+[lL]\=\>" display 135syn match csNumber "\<[[:digit:]_]\+[lL]\=\>" display 136syn match csNumber "\<[[:digit:]_]\+\.[[:digit:]_]*\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\=" display 137syn match csNumber "\.[[:digit:]_]\+\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\=" display 138syn match csNumber "\<[[:digit:]_]\+[eE][-+]\=[[:digit:]_]\+[fFdDmM]\=\>" display 139syn match csNumber "\<[[:digit:]_]\+\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\>" display 140 141syn region csInterpolatedString matchgroup=csQuote start=+\$"+ end=+"+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 142 143syn region csInterpolation matchgroup=csInterpolationDelimiter start=+{+ end=+}+ keepend contained contains=@csAll,csBraced,csBracketed,csInterpolationAlign,csInterpolationFormat 144syn match csEscapedInterpolation "{{" transparent contains=NONE display 145syn match csEscapedInterpolation "}}" transparent contains=NONE display 146syn region csInterpolationAlign matchgroup=csInterpolationAlignDel start=+,+ end=+}+ end=+:+me=e-1 contained contains=csNumber,csConstant,csCharacter,csParens,csOpSymbols,csString,csBracketed display 147syn match csInterpolationFormat +:[^}]\+}+ contained contains=csInterpolationFormatDel display 148syn match csInterpolationAlignDel +,+ contained display 149syn match csInterpolationFormatDel +:+ contained display 150 151syn region csVerbatimString matchgroup=csQuote start=+@"+ end=+"+ skip=+""+ extend contains=csVerbatimQuote,@Spell 152syn match csVerbatimQuote +""+ contained 153syn match csQuoteError +@$"+he=s+2,me=s+2 154 155syn region csInterVerbString matchgroup=csQuote start=+\$@"+ end=+"+ skip=+""+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,csVerbatimQuote,@Spell 156 157syn region csBracketed matchgroup=csParens start=+(+ end=+)+ extend contained transparent contains=@csAll,csBraced,csBracketed 158syn region csBraced matchgroup=csParens start=+{+ end=+}+ extend contained transparent contains=@csAll,csBraced,csBracketed 159 160syn cluster csAll contains=csCharacter,csClassType,csComment,csContextualStatement,csEndColon,csIsType,csLabel,csLogicSymbols,csNewType,csConstant,csNumber,csOpSymbols,csOperatorError,csParens,csPreCondit,csRegion,csString,csSummary,csType,csUnicodeNumber,csUnicodeSpecifier,csInterpolatedString,csVerbatimString,csInterVerbString,csUserType,csUserIdentifier,csUserInterface,csUserMethod 161 162" The default highlighting. 163hi def link csType Type 164hi def link csClassType Type 165hi def link csIsType Type 166hi def link csStorage Structure 167hi def link csClass Structure 168hi def link csRepeat Repeat 169hi def link csConditional Conditional 170hi def link csLabel Label 171hi def link csModifier StorageClass 172hi def link csConstant Constant 173hi def link csException Exception 174hi def link csTypeOf Keyword 175hi def link csTypeOfStatement Typedef 176hi def link csUnspecifiedStatement Statement 177hi def link csUnsupportedStatement Statement 178hi def link csUnspecifiedKeyword Keyword 179hi def link csNew Statement 180hi def link csLinq Statement 181hi def link csIsAs Keyword 182hi def link csAsync Keyword 183hi def link csContextualStatement Statement 184hi def link csOperatorError Error 185 186hi def link csTodo Todo 187hi def link csComment Comment 188 189hi def link csOpSymbols Operator 190hi def link csLogicSymbols Operator 191 192hi def link csSpecialError Error 193hi def link csSpecialCharError Error 194hi def link csString String 195hi def link csQuote String 196hi def link csQuoteError Error 197hi def link csInterpolatedString String 198hi def link csVerbatimString String 199hi def link csInterVerbString String 200hi def link csVerbatimQuote SpecialChar 201hi def link csPreCondit PreCondit 202hi def link csCharacter Character 203hi def link csSpecialChar SpecialChar 204hi def link csNumber Number 205hi def link csUnicodeNumber SpecialChar 206hi def link csUnicodeSpecifier SpecialChar 207hi def link csInterpolationDelimiter Delimiter 208hi def link csInterpolationAlignDel csInterpolationDelimiter 209hi def link csInterpolationFormat csInterpolationDelimiter 210hi def link csInterpolationFormatDel csInterpolationDelimiter 211 212hi def link csGenericBraces csBraces 213 214" xml markup 215hi def link csXmlCommentLeader Comment 216hi def link csXmlComment Comment 217hi def link csXmlTag Statement 218 219let b:current_syntax = 'cs' 220 221let &cpoptions = s:save_cpo 222unlet s:save_cpo 223 224" vim: vts=16,28 225