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: 2019-08-01 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 21 22syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic 23syn keyword csStorage delegate enum interface namespace struct 24syn keyword csRepeat break continue do for foreach goto return while 25syn keyword csConditional else if switch 26syn keyword csLabel case default 27syn match csOperatorError display +::+ 28syn match csGlobal display +global::+ 29" user labels (see [1] 8.6 Statements) 30syn match csLabel display +^\s*\I\i*\s*:\([^:]\)\@=+ 31syn keyword csModifier abstract const extern internal override private protected public readonly sealed static virtual volatile 32syn keyword csConstant false null true 33syn keyword csException try catch finally throw when 34syn keyword csLinq ascending by descending equals from group in into join let on orderby select where 35syn keyword csAsync async await 36 37syn keyword csUnspecifiedStatement as base checked event fixed in is lock nameof operator out params ref sizeof stackalloc this unchecked unsafe using 38syn keyword csUnsupportedStatement add remove value 39syn keyword csUnspecifiedKeyword explicit implicit 40 41" Contextual Keywords 42syn match csContextualStatement /\<yield[[:space:]\n]\+\(return\|break\)/me=s+5 43syn match csContextualStatement /\<partial[[:space:]\n]\+\(class\|struct\|interface\)/me=s+7 44syn match csContextualStatement /\<\(get\|set\)\(;\|[[:space:]\n]*{\)/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 101" [1] 9.5 Pre-processing directives 102syn region csPreCondit start="^\s*#\s*\(define\|undef\|if\|elif\|else\|endif\|line\|error\|warning\)" skip="\\$" end="$" contains=csComment keepend 103syn region csRegion matchgroup=csPreCondit start="^\s*#\s*region.*$" end="^\s*#\s*endregion" transparent fold contains=TOP 104syn region csSummary start="^\s*/// <summary" end="^\%\(\s*///\)\@!" transparent fold keepend 105 106 107syn region csClassType start="@\@1<!\<class\>"hs=s+6 end="[:\n{]"me=e-1 contains=csClass 108" csUserType may be defined by user scripts/plugins - it should be contained in csNewType 109syn region csNewType start="@\@1<!\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,csUserType 110syn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 111syn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 112syn keyword csNew new contained 113syn keyword csClass class contained 114syn keyword csIsAs is as 115 116" Strings and constants 117syn match csSpecialError "\\." contained 118syn match csSpecialCharError "[^']" contained 119" [1] 9.4.4.4 Character literals 120syn match csSpecialChar +\\["\\'0abfnrtvx]+ contained display 121syn match csUnicodeNumber +\\u\x\{4}+ contained contains=csUnicodeSpecifier display 122syn match csUnicodeNumber +\\U\x\{8}+ contained contains=csUnicodeSpecifier display 123syn match csUnicodeSpecifier +\\[uU]+ contained display 124 125syn region csString matchgroup=csQuote start=+"+ end=+"+ end=+$+ extend contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 126syn match csCharacter "'[^']*'" contains=csSpecialChar,csSpecialCharError display 127syn match csCharacter "'\\''" contains=csSpecialChar display 128syn match csCharacter "'[^\\]'" display 129syn match csNumber "\<0[0-7]*[lL]\=\>" display 130syn match csNumber "\<0[xX]\x\+[lL]\=\>" display 131syn match csNumber "\<\d\+[lL]\=\>" display 132syn match csNumber "\<\d\+\.\d*\%\([eE][-+]\=\d\+\)\=[fFdD]\=" display 133syn match csNumber "\.\d\+\%\([eE][-+]\=\d\+\)\=[fFdD]\=" display 134syn match csNumber "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>" display 135syn match csNumber "\<\d\+\%\([eE][-+]\=\d\+\)\=[fFdD]\>" display 136 137syn region csInterpolatedString matchgroup=csQuote start=+\$"+ end=+"+ end=+$+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 138 139syn region csInterpolation matchgroup=csInterpolationDelimiter start=+{+ end=+}+ keepend contained contains=@csAll,csBracketed,csInterpolationAlign,csInterpolationFormat 140syn match csEscapedInterpolation "{{" transparent contains=NONE display 141syn match csEscapedInterpolation "}}" transparent contains=NONE display 142syn region csInterpolationAlign matchgroup=csInterpolationAlignDel start=+,+ end=+}+ end=+:+me=e-1 contained contains=csNumber,csConstant,csCharacter,csParens,csOpSymbols,csString,csBracketed display 143syn match csInterpolationFormat +:[^}]\+}+ contained contains=csInterpolationFormatDel display 144syn match csInterpolationAlignDel +,+ contained display 145syn match csInterpolationFormatDel +:+ contained display 146 147syn region csVerbatimString matchgroup=csQuote start=+@"+ end=+"+ skip=+""+ extend contains=csVerbatimQuote,@Spell 148syn match csVerbatimQuote +""+ contained 149syn match csQuoteError +@$"+he=s+2,me=s+2 150 151syn region csInterVerbString matchgroup=csQuote start=+\$@"+ end=+"+ skip=+""+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,csVerbatimQuote,@Spell 152 153syn region csBracketed matchgroup=csParens start=+(+ end=+)+ contained transparent contains=@csAll,csBracketed 154 155syn cluster csAll contains=csCharacter,csClassType,csComment,csContextualStatement,csEndColon,csInterpolatedString,csIsType,csLabel,csLogicSymbols,csNewType,csConstant,csNumber,csOpSymbols,csOperatorError,csParens,csPreCondit,csRegion,csString,csSummary,csType,csUnicodeNumber,csUnicodeSpecifier,csVerbatimString,csUserType,csUserIdentifier,csUserInterface,csUserMethod 156 157" The default highlighting. 158hi def link csType Type 159hi def link csClassType Type 160hi def link csIsType Type 161hi def link csStorage Structure 162hi def link csClass Structure 163hi def link csRepeat Repeat 164hi def link csConditional Conditional 165hi def link csLabel Label 166hi def link csModifier StorageClass 167hi def link csConstant Constant 168hi def link csException Exception 169hi def link csTypeOf Keyword 170hi def link csTypeOfStatement Typedef 171hi def link csUnspecifiedStatement Statement 172hi def link csUnsupportedStatement Statement 173hi def link csUnspecifiedKeyword Keyword 174hi def link csNew Statement 175hi def link csLinq Statement 176hi def link csIsAs Keyword 177hi def link csAsync Keyword 178hi def link csContextualStatement Statement 179hi def link csOperatorError Error 180 181hi def link csTodo Todo 182hi def link csComment Comment 183 184hi def link csOpSymbols Operator 185hi def link csLogicSymbols Operator 186 187hi def link csSpecialError Error 188hi def link csSpecialCharError Error 189hi def link csString String 190hi def link csQuote String 191hi def link csQuoteError Error 192hi def link csInterpolatedString String 193hi def link csVerbatimString String 194hi def link csInterVerbString String 195hi def link csVerbatimQuote SpecialChar 196hi def link csPreCondit PreCondit 197hi def link csCharacter Character 198hi def link csSpecialChar SpecialChar 199hi def link csNumber Number 200hi def link csUnicodeNumber SpecialChar 201hi def link csUnicodeSpecifier SpecialChar 202hi def link csInterpolationDelimiter Delimiter 203hi def link csInterpolationAlignDel csInterpolationDelimiter 204hi def link csInterpolationFormat csInterpolationDelimiter 205hi def link csInterpolationFormatDel csInterpolationDelimiter 206 207hi def link csGenericBraces csBraces 208 209" xml markup 210hi def link csXmlCommentLeader Comment 211hi def link csXmlComment Comment 212hi def link csXmlTag Statement 213 214let b:current_syntax = 'cs' 215 216let &cpoptions = s:save_cpo 217unlet s:save_cpo 218 219" vim: vts=16,28 220