1071d4279SBram Moolenaar" Vim syntax file 2071d4279SBram Moolenaar" Language: C# 385eee130SBram Moolenaar" Maintainer: Nick Jensen <[email protected]> 4a9604e61SBram Moolenaar" Former Maintainers: Anduin Withers <[email protected]> 5a9604e61SBram Moolenaar" Johannes Zellner <[email protected]> 6*23515b4eSBram Moolenaar" Last Change: 2020-11-23 7071d4279SBram Moolenaar" Filenames: *.cs 885eee130SBram Moolenaar" License: Vim (see :h license) 985eee130SBram Moolenaar" Repository: https://github.com/nickspoons/vim-cs 10071d4279SBram Moolenaar" 11071d4279SBram Moolenaar" REFERENCES: 12071d4279SBram Moolenaar" [1] ECMA TC39: C# Language Specification (WD13Oct01.doc) 13071d4279SBram Moolenaar 14d47d5223SBram Moolenaarif exists('b:current_syntax') 15071d4279SBram Moolenaar finish 16071d4279SBram Moolenaarendif 17071d4279SBram Moolenaar 18d47d5223SBram Moolenaarlet s:save_cpo = &cpoptions 19d47d5223SBram Moolenaarset cpoptions&vim 20071d4279SBram Moolenaar 2185eee130SBram Moolenaarsyn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic 2285eee130SBram Moolenaarsyn keyword csStorage delegate enum interface namespace struct 23071d4279SBram Moolenaarsyn keyword csRepeat break continue do for foreach goto return while 24071d4279SBram Moolenaarsyn keyword csConditional else if switch 25071d4279SBram Moolenaarsyn keyword csLabel case default 26071d4279SBram Moolenaarsyn match csOperatorError display +::+ 27a9604e61SBram Moolenaarsyn match csGlobal display +global::+ 28071d4279SBram Moolenaar" user labels (see [1] 8.6 Statements) 29*23515b4eSBram Moolenaarsyn match csLabel display +^\s*\I\i*\s*:\%([^:]\)\@=+ 30071d4279SBram Moolenaarsyn keyword csModifier abstract const extern internal override private protected public readonly sealed static virtual volatile 31071d4279SBram Moolenaarsyn keyword csConstant false null true 3285eee130SBram Moolenaarsyn keyword csException try catch finally throw when 3385eee130SBram Moolenaarsyn keyword csLinq ascending by descending equals from group in into join let on orderby select where 3485eee130SBram Moolenaarsyn keyword csAsync async await 35071d4279SBram Moolenaar 36d47d5223SBram Moolenaarsyn keyword csUnspecifiedStatement as base checked event fixed in is lock nameof operator out params ref sizeof stackalloc this unchecked unsafe using 379c102387SBram Moolenaarsyn keyword csUnsupportedStatement add remove value 38071d4279SBram Moolenaarsyn keyword csUnspecifiedKeyword explicit implicit 39071d4279SBram Moolenaar 409c102387SBram Moolenaar" Contextual Keywords 41*23515b4eSBram Moolenaarsyn match csContextualStatement /\<yield[[:space:]\n]\+\%(return\|break\)/me=s+5 42*23515b4eSBram Moolenaarsyn match csContextualStatement /\<partial[[:space:]\n]\+\%(class\|struct\|interface\)/me=s+7 43*23515b4eSBram Moolenaarsyn match csContextualStatement /\<\%(get\|set\)\%(;\|[[:space:]\n]*{\)/me=s+3 44*23515b4eSBram Moolenaarsyn match csContextualStatement /\<\%(get\|set\)\s*=>/me=s+3 459c102387SBram Moolenaarsyn match csContextualStatement /\<where\>[^:]\+:/me=s+5 46071d4279SBram Moolenaar 47d47d5223SBram Moolenaar" Operators 48d47d5223SBram Moolenaarsyn keyword csTypeOf typeof contained 49d47d5223SBram Moolenaarsyn region csTypeOfStatement start="typeof(" end=")" contains=csType, csTypeOf 50d47d5223SBram Moolenaar 51a9604e61SBram Moolenaar" Punctuation 52a9604e61SBram Moolenaarsyn match csBraces "[{}\[\]]" display 53a9604e61SBram Moolenaarsyn match csParens "[()]" display 54088e8e34SBram Moolenaarsyn match csOpSymbols "+\{1,2}" display 55088e8e34SBram Moolenaarsyn match csOpSymbols "-\{1,2}" display 56088e8e34SBram Moolenaarsyn match csOpSymbols "=\{1,2}" display 57088e8e34SBram Moolenaarsyn match csOpSymbols ">\{1,2}" display 58088e8e34SBram Moolenaarsyn match csOpSymbols "<\{1,2}" display 59a9604e61SBram Moolenaarsyn match csOpSymbols "[!><+\-*/]=" display 60a9604e61SBram Moolenaarsyn match csOpSymbols "[!*/^]" display 61a9604e61SBram Moolenaarsyn match csOpSymbols "=>" display 62a9604e61SBram Moolenaarsyn match csEndColon ";" display 63a9604e61SBram Moolenaarsyn match csLogicSymbols "&&" display 64a9604e61SBram Moolenaarsyn match csLogicSymbols "||" display 65a9604e61SBram Moolenaarsyn match csLogicSymbols "?" display 66a9604e61SBram Moolenaarsyn match csLogicSymbols ":" display 67a9604e61SBram Moolenaar 68088e8e34SBram Moolenaar" Generics 69088e8e34SBram Moolenaarsyn region csGeneric matchgroup=csGenericBraces start="<" end=">" oneline contains=csType,csGeneric,csUserType,csUserIdentifier,csUserInterface,csUserMethod 70088e8e34SBram Moolenaar 71071d4279SBram Moolenaar" Comments 72071d4279SBram Moolenaar" 73071d4279SBram Moolenaar" PROVIDES: @csCommentHook 74a9604e61SBram Moolenaarsyn keyword csTodo contained TODO FIXME XXX NOTE HACK TBD 75551dbcc9SBram Moolenaarsyn region csComment start="/\*" end="\*/" contains=@csCommentHook,csTodo,@Spell 76551dbcc9SBram Moolenaarsyn match csComment "//.*$" contains=@csCommentHook,csTodo,@Spell 77071d4279SBram Moolenaar 78071d4279SBram Moolenaar" xml markup inside '///' comments 79071d4279SBram Moolenaarsyn cluster xmlRegionHook add=csXmlCommentLeader 80071d4279SBram Moolenaarsyn cluster xmlCdataHook add=csXmlCommentLeader 81071d4279SBram Moolenaarsyn cluster xmlStartTagHook add=csXmlCommentLeader 82071d4279SBram Moolenaarsyn keyword csXmlTag contained Libraries Packages Types Excluded ExcludedTypeName ExcludedLibraryName 83071d4279SBram Moolenaarsyn keyword csXmlTag contained ExcludedBucketName TypeExcluded Type TypeKind TypeSignature AssemblyInfo 84071d4279SBram Moolenaarsyn keyword csXmlTag contained AssemblyName AssemblyPublicKey AssemblyVersion AssemblyCulture Base 85071d4279SBram Moolenaarsyn keyword csXmlTag contained BaseTypeName Interfaces Interface InterfaceName Attributes Attribute 86071d4279SBram Moolenaarsyn keyword csXmlTag contained AttributeName Members Member MemberSignature MemberType MemberValue 87071d4279SBram Moolenaarsyn keyword csXmlTag contained ReturnValue ReturnType Parameters Parameter MemberOfPackage 88071d4279SBram Moolenaarsyn keyword csXmlTag contained ThreadingSafetyStatement Docs devdoc example overload remarks returns summary 89071d4279SBram Moolenaarsyn keyword csXmlTag contained threadsafe value internalonly nodoc exception param permission platnote 90071d4279SBram Moolenaarsyn keyword csXmlTag contained seealso b c i pre sub sup block code note paramref see subscript superscript 91071d4279SBram Moolenaarsyn keyword csXmlTag contained list listheader item term description altcompliant altmember 92071d4279SBram Moolenaar 93071d4279SBram Moolenaarsyn cluster xmlTagHook add=csXmlTag 94071d4279SBram Moolenaar 95088e8e34SBram Moolenaarsyn match csXmlCommentLeader "///" contained 96088e8e34SBram Moolenaarsyn match csXmlComment "///.*$" contains=csXmlCommentLeader,@csXml,@Spell keepend 97a9604e61SBram Moolenaarsyn include @csXml syntax/xml.vim 98071d4279SBram Moolenaarhi def link xmlRegion Comment 99071d4279SBram Moolenaar 100560979edSBram Moolenaar" Since syntax/xml.vim contains `syn spell toplevel`, we need to set it back to `default` here. 101560979edSBram Moolenaarsyn spell default 102071d4279SBram Moolenaar 103071d4279SBram Moolenaar" [1] 9.5 Pre-processing directives 104*23515b4eSBram Moolenaarsyn region csPreCondit start="^\s*#\s*\%(define\|undef\|if\|elif\|else\|endif\|line\|error\|warning\|pragma\)\>" skip="\\$" end="$" contains=csComment keepend 105a9604e61SBram Moolenaarsyn region csRegion matchgroup=csPreCondit start="^\s*#\s*region.*$" end="^\s*#\s*endregion" transparent fold contains=TOP 106a9604e61SBram Moolenaarsyn region csSummary start="^\s*/// <summary" end="^\%\(\s*///\)\@!" transparent fold keepend 107071d4279SBram Moolenaar 108071d4279SBram Moolenaar 109a9604e61SBram Moolenaarsyn region csClassType start="@\@1<!\<class\>"hs=s+6 end="[:\n{]"me=e-1 contains=csClass 110088e8e34SBram Moolenaar" csUserType may be defined by user scripts/plugins - it should be contained in csNewType 111088e8e34SBram Moolenaarsyn region csNewType start="@\@1<!\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,csUserType 112a9604e61SBram Moolenaarsyn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 113a9604e61SBram Moolenaarsyn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs 11485eee130SBram Moolenaarsyn keyword csNew new contained 11585eee130SBram Moolenaarsyn keyword csClass class contained 11685eee130SBram Moolenaarsyn keyword csIsAs is as 117071d4279SBram Moolenaar 118071d4279SBram Moolenaar" Strings and constants 119a9604e61SBram Moolenaarsyn match csSpecialError "\\." contained 120a9604e61SBram Moolenaarsyn match csSpecialCharError "[^']" contained 121071d4279SBram Moolenaar" [1] 9.4.4.4 Character literals 122a9604e61SBram Moolenaarsyn match csSpecialChar +\\["\\'0abfnrtvx]+ contained display 123*23515b4eSBram Moolenaarsyn match csUnicodeNumber +\\x\x\{2,4}+ contained contains=csUnicodeSpecifier display 124a9604e61SBram Moolenaarsyn match csUnicodeNumber +\\u\x\{4}+ contained contains=csUnicodeSpecifier display 125a9604e61SBram Moolenaarsyn match csUnicodeNumber +\\U\x\{8}+ contained contains=csUnicodeSpecifier display 126a9604e61SBram Moolenaarsyn match csUnicodeSpecifier +\\[uU]+ contained display 127a9604e61SBram Moolenaar 128a9604e61SBram Moolenaarsyn region csString matchgroup=csQuote start=+"+ end=+"+ end=+$+ extend contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 129*23515b4eSBram Moolenaarsyn match csCharacter "'[^']*'" contains=csSpecialChar,csSpecialCharError,csUnicodeNumber display 130a9604e61SBram Moolenaarsyn match csCharacter "'\\''" contains=csSpecialChar display 131a9604e61SBram Moolenaarsyn match csCharacter "'[^\\]'" display 132a9604e61SBram Moolenaarsyn match csNumber "\<0[0-7]*[lL]\=\>" display 133*23515b4eSBram Moolenaarsyn match csNumber "\<0[xX][[:xdigit:]_]\+[lL]\=\>" display 134*23515b4eSBram Moolenaarsyn match csNumber "\<0[bB][01_]\+[lL]\=\>" display 135*23515b4eSBram Moolenaarsyn match csNumber "\<[[:digit:]_]\+[lL]\=\>" display 136*23515b4eSBram Moolenaarsyn match csNumber "\<[[:digit:]_]\+\.[[:digit:]_]*\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\=" display 137*23515b4eSBram Moolenaarsyn match csNumber "\.[[:digit:]_]\+\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\=" display 138*23515b4eSBram Moolenaarsyn match csNumber "\<[[:digit:]_]\+[eE][-+]\=[[:digit:]_]\+[fFdDmM]\=\>" display 139*23515b4eSBram Moolenaarsyn match csNumber "\<[[:digit:]_]\+\%\([eE][-+]\=[[:digit:]_]\+\)\=[fFdDmM]\>" display 140a9604e61SBram Moolenaar 141*23515b4eSBram Moolenaarsyn region csInterpolatedString matchgroup=csQuote start=+\$"+ end=+"+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,@Spell 142a9604e61SBram Moolenaar 143*23515b4eSBram Moolenaarsyn region csInterpolation matchgroup=csInterpolationDelimiter start=+{+ end=+}+ keepend contained contains=@csAll,csBraced,csBracketed,csInterpolationAlign,csInterpolationFormat 144a9604e61SBram Moolenaarsyn match csEscapedInterpolation "{{" transparent contains=NONE display 145a9604e61SBram Moolenaarsyn match csEscapedInterpolation "}}" transparent contains=NONE display 146a9604e61SBram Moolenaarsyn region csInterpolationAlign matchgroup=csInterpolationAlignDel start=+,+ end=+}+ end=+:+me=e-1 contained contains=csNumber,csConstant,csCharacter,csParens,csOpSymbols,csString,csBracketed display 147a9604e61SBram Moolenaarsyn match csInterpolationFormat +:[^}]\+}+ contained contains=csInterpolationFormatDel display 148a9604e61SBram Moolenaarsyn match csInterpolationAlignDel +,+ contained display 149a9604e61SBram Moolenaarsyn match csInterpolationFormatDel +:+ contained display 150a9604e61SBram Moolenaar 151a9604e61SBram Moolenaarsyn region csVerbatimString matchgroup=csQuote start=+@"+ end=+"+ skip=+""+ extend contains=csVerbatimQuote,@Spell 152a9604e61SBram Moolenaarsyn match csVerbatimQuote +""+ contained 153a9604e61SBram Moolenaarsyn match csQuoteError +@$"+he=s+2,me=s+2 154a9604e61SBram Moolenaar 155a9604e61SBram Moolenaarsyn region csInterVerbString matchgroup=csQuote start=+\$@"+ end=+"+ skip=+""+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,csVerbatimQuote,@Spell 156a9604e61SBram Moolenaar 157*23515b4eSBram Moolenaarsyn region csBracketed matchgroup=csParens start=+(+ end=+)+ extend contained transparent contains=@csAll,csBraced,csBracketed 158*23515b4eSBram Moolenaarsyn region csBraced matchgroup=csParens start=+{+ end=+}+ extend contained transparent contains=@csAll,csBraced,csBracketed 159a9604e61SBram Moolenaar 160*23515b4eSBram Moolenaarsyn 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 161071d4279SBram Moolenaar 162071d4279SBram Moolenaar" The default highlighting. 163071d4279SBram Moolenaarhi def link csType Type 16485eee130SBram Moolenaarhi def link csClassType Type 16585eee130SBram Moolenaarhi def link csIsType Type 166d47d5223SBram Moolenaarhi def link csStorage Structure 167d47d5223SBram Moolenaarhi def link csClass Structure 168071d4279SBram Moolenaarhi def link csRepeat Repeat 169071d4279SBram Moolenaarhi def link csConditional Conditional 170071d4279SBram Moolenaarhi def link csLabel Label 171071d4279SBram Moolenaarhi def link csModifier StorageClass 172071d4279SBram Moolenaarhi def link csConstant Constant 173071d4279SBram Moolenaarhi def link csException Exception 174088e8e34SBram Moolenaarhi def link csTypeOf Keyword 175d47d5223SBram Moolenaarhi def link csTypeOfStatement Typedef 176071d4279SBram Moolenaarhi def link csUnspecifiedStatement Statement 177071d4279SBram Moolenaarhi def link csUnsupportedStatement Statement 178071d4279SBram Moolenaarhi def link csUnspecifiedKeyword Keyword 17985eee130SBram Moolenaarhi def link csNew Statement 18085eee130SBram Moolenaarhi def link csLinq Statement 18185eee130SBram Moolenaarhi def link csIsAs Keyword 18285eee130SBram Moolenaarhi def link csAsync Keyword 1839c102387SBram Moolenaarhi def link csContextualStatement Statement 184071d4279SBram Moolenaarhi def link csOperatorError Error 185071d4279SBram Moolenaar 186071d4279SBram Moolenaarhi def link csTodo Todo 187071d4279SBram Moolenaarhi def link csComment Comment 188071d4279SBram Moolenaar 189a9604e61SBram Moolenaarhi def link csOpSymbols Operator 190d47d5223SBram Moolenaarhi def link csLogicSymbols Operator 191a9604e61SBram Moolenaar 192071d4279SBram Moolenaarhi def link csSpecialError Error 193071d4279SBram Moolenaarhi def link csSpecialCharError Error 194071d4279SBram Moolenaarhi def link csString String 195a9604e61SBram Moolenaarhi def link csQuote String 196a9604e61SBram Moolenaarhi def link csQuoteError Error 197a9604e61SBram Moolenaarhi def link csInterpolatedString String 198071d4279SBram Moolenaarhi def link csVerbatimString String 199a9604e61SBram Moolenaarhi def link csInterVerbString String 200a9604e61SBram Moolenaarhi def link csVerbatimQuote SpecialChar 201071d4279SBram Moolenaarhi def link csPreCondit PreCondit 202071d4279SBram Moolenaarhi def link csCharacter Character 203071d4279SBram Moolenaarhi def link csSpecialChar SpecialChar 204071d4279SBram Moolenaarhi def link csNumber Number 205071d4279SBram Moolenaarhi def link csUnicodeNumber SpecialChar 206071d4279SBram Moolenaarhi def link csUnicodeSpecifier SpecialChar 207a9604e61SBram Moolenaarhi def link csInterpolationDelimiter Delimiter 208a9604e61SBram Moolenaarhi def link csInterpolationAlignDel csInterpolationDelimiter 209a9604e61SBram Moolenaarhi def link csInterpolationFormat csInterpolationDelimiter 210a9604e61SBram Moolenaarhi def link csInterpolationFormatDel csInterpolationDelimiter 211071d4279SBram Moolenaar 212088e8e34SBram Moolenaarhi def link csGenericBraces csBraces 213088e8e34SBram Moolenaar 214071d4279SBram Moolenaar" xml markup 215071d4279SBram Moolenaarhi def link csXmlCommentLeader Comment 216071d4279SBram Moolenaarhi def link csXmlComment Comment 217071d4279SBram Moolenaarhi def link csXmlTag Statement 218071d4279SBram Moolenaar 219d47d5223SBram Moolenaarlet b:current_syntax = 'cs' 220071d4279SBram Moolenaar 221d47d5223SBram Moolenaarlet &cpoptions = s:save_cpo 222d47d5223SBram Moolenaarunlet s:save_cpo 223071d4279SBram Moolenaar 224a9604e61SBram Moolenaar" vim: vts=16,28 225