1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-18 07:47:09 +01:00
vim/runtime/syntax/cs.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

332 lines
14 KiB
VimL
Raw Permalink Normal View History

2004-06-13 20:20:40 +00:00
" Vim syntax file
2018-07-21 05:56:22 +02:00
" Language: C#
" Maintainer: Nick Jensen <nickspoon@gmail.com>
" Former Maintainers: Anduin Withers <awithers@anduin.com>
" Johannes Zellner <johannes@zellner.org>
2022-12-06 18:20:10 +00:00
" Last Change: 2022-11-16
2018-07-21 05:56:22 +02:00
" Filenames: *.cs
" License: Vim (see :h license)
" Repository: https://github.com/nickspoons/vim-cs
2004-06-13 20:20:40 +00:00
"
2022-06-09 20:45:54 +01:00
" References:
" - ECMA-334 5th Edition: C# Language Specification
" https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
" - C# Language Design: Draft 6th Edition and later proposals
" https://github.com/dotnet/csharplang
2004-06-13 20:20:40 +00:00
2018-12-09 20:43:55 +01:00
if exists('b:current_syntax')
finish
2004-06-13 20:20:40 +00:00
endif
2018-12-09 20:43:55 +01:00
let s:save_cpo = &cpoptions
set cpoptions&vim
2004-06-13 20:20:40 +00:00
2018-07-21 05:56:22 +02:00
syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic
2022-06-09 20:45:54 +01:00
syn keyword csType nint nuint " contextual
syn keyword csStorage enum interface namespace struct
2022-12-06 18:20:10 +00:00
syn match csStorage "\<record\ze\_s\+@\=\h\w*\_s*[<(:{;]"
syn match csStorage "\%(\<\%(partial\|new\|public\|protected\|internal\|private\|abstract\|sealed\|static\|unsafe\|readonly\)\)\@9<=\_s\+record\>"
syn match csStorage "\<record\ze\_s\+\%(class\|struct\)"
2022-06-09 20:45:54 +01:00
syn match csStorage "\<delegate\>"
2018-07-21 05:56:22 +02:00
syn keyword csRepeat break continue do for foreach goto return while
syn keyword csConditional else if switch
syn keyword csLabel case default
2022-06-09 20:45:54 +01:00
syn match csNamespaceAlias "@\=\h\w*\ze\_s*::" display
syn match csGlobalNamespaceAlias "global\ze\_s*::" display
syn cluster csNamespaceAlias contains=csGlobalNamespaceAlias,csNamespaceAlias,csNamespaceAliasQualifier
" user labels
2020-11-29 14:36:24 +01:00
syn match csLabel display +^\s*\I\i*\s*:\%([^:]\)\@=+
2022-06-09 20:45:54 +01:00
" Function pointers
syn match csType "\<delegate\s*\*" contains=csOpSymbols nextgroup=csManagedModifier skipwhite skipempty
syn keyword csManagedModifier managed unmanaged contained
" Modifiers
syn match csUsingModifier "\<global\ze\_s\+using\>"
syn keyword csAccessModifier internal private protected public
2022-12-06 18:20:10 +00:00
syn keyword csModifier operator nextgroup=csCheckedModifier skipwhite skipempty
syn keyword csCheckedModifier checked contained
2022-06-09 20:45:54 +01:00
" TODO: in new out
syn keyword csModifier abstract const event override readonly sealed static virtual volatile
syn match csModifier "\<\%(extern\|fixed\|unsafe\)\>"
syn match csModifier "\<partial\ze\_s\+\%(class\|struct\|interface\|record\|void\)\>"
2018-07-21 05:56:22 +02:00
syn keyword csException try catch finally throw when
2022-06-09 20:45:54 +01:00
syn keyword csLinq ascending by descending equals from group in into join let on orderby select
syn match csLinq "\<where\>"
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
" Type parameter constraint clause
syn match csStorage "\<where\>\ze\_s\+@\=\h\w*\_s*:"
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
" Async
syn keyword csAsyncModifier async
syn keyword csAsyncOperator await
syn match csStorage "\<extern\ze\s\+alias\>"
syn match csStorage "\%(\<extern\s\+\)\@16<=alias\>"
syn match csStatement "\<\%(checked\|unchecked\|unsafe\)\ze\_s*{"
syn match csStatement "\<fixed\ze\_s*("
syn keyword csStatement lock
syn match csStatement "\<yield\ze\_s\+\%(return\|break\)\>"
syn match csAccessor "\<\%(get\|set\|init\|add\|remove\)\ze\_s*\%([;{]\|=>\)"
syn keyword csAccess base
syn match csAccess "\<this\>"
" Extension method parameter modifier
syn match csModifier "\<this\ze\_s\+@\=\h"
2022-12-06 18:20:10 +00:00
syn keyword csUnspecifiedStatement as in is nameof out params ref sizeof stackalloc using
2022-06-09 20:45:54 +01:00
syn keyword csUnsupportedStatement value
syn keyword csUnspecifiedKeyword explicit implicit
2018-07-21 05:56:22 +02:00
2018-12-09 20:43:55 +01:00
" Operators
2022-06-09 20:45:54 +01:00
syn keyword csTypeOf typeof nextgroup=csTypeOfOperand,csTypeOfError skipwhite skipempty
syn region csTypeOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
syn match csTypeOfError "[^([:space:]]" contained
syn match csKeywordOperator "\<\%(checked\|unchecked\)\ze\_s*("
2018-12-09 20:43:55 +01:00
2018-07-21 05:56:22 +02:00
" Punctuation
2022-06-09 20:45:54 +01:00
syn match csBraces "[{}[\]]" display
2018-07-21 05:56:22 +02:00
syn match csParens "[()]" display
2019-08-08 22:15:18 +02:00
syn match csOpSymbols "+\{1,2}" display
syn match csOpSymbols "-\{1,2}" display
syn match csOpSymbols "=\{1,2}" display
syn match csOpSymbols ">\{1,2}" display
syn match csOpSymbols "<\{1,2}" display
2018-07-21 05:56:22 +02:00
syn match csOpSymbols "[!><+\-*/]=" display
syn match csOpSymbols "[!*/^]" display
syn match csOpSymbols "=>" display
syn match csEndColon ";" display
syn match csLogicSymbols "&&" display
syn match csLogicSymbols "||" display
syn match csLogicSymbols "?" display
syn match csLogicSymbols ":" display
2022-06-09 20:45:54 +01:00
syn match csNamespaceAliasQualifier "::" display
2004-06-13 20:20:40 +00:00
2019-08-08 22:15:18 +02:00
" Generics
2022-06-09 20:45:54 +01:00
syn region csGeneric matchgroup=csGenericBraces start="<" end=">" oneline contains=csType,csGeneric,@csNamespaceAlias,csUserType,csUserIdentifier,csUserInterface,csUserMethod
2019-08-08 22:15:18 +02:00
2004-06-13 20:20:40 +00:00
" Comments
"
" PROVIDES: @csCommentHook
2018-07-21 05:56:22 +02:00
syn keyword csTodo contained TODO FIXME XXX NOTE HACK TBD
2022-06-09 20:45:54 +01:00
syn region csBlockComment start="/\*" end="\*/" contains=@csCommentHook,csTodo,@Spell
syn match csLineComment "//.*$" contains=@csCommentHook,csTodo,@Spell
syn cluster csComment contains=csLineComment,csBlockComment
syn region csSummary start="^\s*/// <summary" end="^\%\(\s*///\)\@!" transparent fold keepend
" xml markup inside '///' and /**...*/ comments
syn cluster xmlRegionHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
syn cluster xmlCdataHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
syn cluster xmlStartTagHook add=csXmlLineCommentLeader,csXmlBlockCommentMiddle
syn cluster xmlTagHook add=csXmlTag
syn cluster xmlAttribHook add=csXmlAttrib
" https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
syn keyword csXmlTag contained summary remarks
syn keyword csXmlTag contained returns param paramref exception value
syn keyword csXmlTag contained para list c code example
syn keyword csXmlTag contained inheritdoc include
syn keyword csXmlTag contained see seealso
syn keyword csXmlTag contained typeparam typeparamref
syn keyword csXmlTag contained b i u br a
syn keyword csXmlAttrib contained cref href
syn match csXmlLineCommentLeader "///" contained
syn match csXmlLineComment "///.*$" contains=csXmlLineCommentLeader,@csXml,@Spell keepend
syn match csXmlBlockCommentMiddle "^\s*\zs\*" contained
syn region csXmlBlockComment start="/\*\*" end="\*/" contains=@csXml,@Spell,csXmlBlockCommentMiddle keepend
2018-07-21 05:56:22 +02:00
syn include @csXml syntax/xml.vim
hi def link xmlRegion Comment
2004-06-13 20:20:40 +00:00
2020-02-04 22:53:05 +01:00
" Since syntax/xml.vim contains `syn spell toplevel`, we need to set it back to `default` here.
syn spell default
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
" Pre-processing directives
syn region csPreProcDeclaration start="^\s*\zs#\s*\%(define\|undef\)\>" end="$" contains=csLineComment keepend
syn region csPreProcConditional start="^\s*\zs#\s*\%(if\|elif\)\>" end="$" contains=csLineComment keepend
syn region csPreProcConditional start="^\s*\zs#\s*\%(else\|endif\)\>" end="$" contains=csLineComment keepend
syn region csPreProcLine start="^\s*\zs#\s*line\>" end="$" contains=csLineComment keepend
syn region csPreProcDiagnostic start="^\s*\zs#\s*\%(error\|warning\)\>" end="$"
syn region csPreProcConditionalSection matchgroup=csPreProcRegion start="^\s*#\s*region\>.*" end="^\s*#\s*endregion\>.*" transparent fold contains=TOP
syn region csPreProcPragma start="^\s*\zs#\s*pragma\>" end="$" contains=csLineComment keepend
syn region csPreProcNullable start="^\s*\zs#\s*nullable\>" end="$" contains=csLineComment keepend
if expand('%:e') == 'csx' || getline('1') =~ '^#!.*\<dotnet-script\>'
syn region csPreProcInclude start="^\s*\zs#\s*\%(load\|r\)\>" end="$" contains=csLineComment keepend
syn match csShebang "\%^#!.*" display
endif
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
syn cluster csPreProcessor contains=csPreProc.*
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
syn region csClassType start="\<class\>"hs=s+6 end=">" end="[:{]"me=e-1 contains=csClass
2019-08-08 22:15:18 +02:00
" csUserType may be defined by user scripts/plugins - it should be contained in csNewType
2022-06-09 20:45:54 +01:00
syn region csNewType start="\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,@csNamespaceAlias,csUserType
2018-07-21 05:56:22 +02:00
syn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
syn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
syn keyword csNew new contained
syn keyword csClass class contained
syn keyword csIsAs is as
2004-06-13 20:20:40 +00:00
2022-06-09 20:45:54 +01:00
syn keyword csBoolean false true
syn keyword csNull null
2004-06-13 20:20:40 +00:00
" Strings and constants
2018-07-21 05:56:22 +02:00
syn match csSpecialError "\\." contained
syn match csSpecialCharError "[^']" contained
2022-06-09 20:45:54 +01:00
" Character literals
syn match csSpecialChar +\\["\\'0abfnrtv]+ contained display
syn match csUnicodeNumber +\\x\x\{1,4}+ contained contains=csUnicodeSpecifier display
2018-07-21 05:56:22 +02:00
syn match csUnicodeNumber +\\u\x\{4}+ contained contains=csUnicodeSpecifier display
2022-06-09 20:45:54 +01:00
syn match csUnicodeNumber +\\U00\x\{6}+ contained contains=csUnicodeSpecifier display
syn match csUnicodeSpecifier +\\[uUx]+ contained display
2018-07-21 05:56:22 +02:00
2022-12-06 18:20:10 +00:00
syn region csString matchgroup=csQuote start=+"+ end=+"\%(u8\)\=+ end=+$+ extend contains=csSpecialChar,csSpecialError,csUnicodeNumber,@Spell
2020-11-29 14:36:24 +01:00
syn match csCharacter "'[^']*'" contains=csSpecialChar,csSpecialCharError,csUnicodeNumber display
2018-07-21 05:56:22 +02:00
syn match csCharacter "'\\''" contains=csSpecialChar display
syn match csCharacter "'[^\\]'" display
2022-06-09 20:45:54 +01:00
" Numbers
syn case ignore
syn match csInteger "\<0b[01_]*[01]\%([lu]\|lu\|ul\)\=\>" display
syn match csInteger "\<\d\+\%(_\+\d\+\)*\%([lu]\|lu\|ul\)\=\>" display
syn match csInteger "\<0x[[:xdigit:]_]*\x\%([lu]\|lu\|ul\)\=\>" display
syn match csReal "\<\d\+\%(_\+\d\+\)*\.\d\+\%(_\+\d\+\)*\%\(e[-+]\=\d\+\%(_\+\d\+\)*\)\=[fdm]\=" display
syn match csReal "\.\d\+\%(_\+\d\+\)*\%(e[-+]\=\d\+\%(_\+\d\+\)*\)\=[fdm]\=\>" display
syn match csReal "\<\d\+\%(_\+\d\+\)*e[-+]\=\d\+\%(_\+\d\+\)*[fdm]\=\>" display
syn match csReal "\<\d\+\%(_\+\d\+\)*[fdm]\>" display
syn case match
syn cluster csNumber contains=csInteger,csReal
2018-07-21 05:56:22 +02:00
2022-12-06 18:20:10 +00:00
syn region csInterpolatedString matchgroup=csQuote start=+\$"+ end=+"\%(u8\)\=+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,@Spell
2018-07-21 05:56:22 +02:00
2020-11-29 14:36:24 +01:00
syn region csInterpolation matchgroup=csInterpolationDelimiter start=+{+ end=+}+ keepend contained contains=@csAll,csBraced,csBracketed,csInterpolationAlign,csInterpolationFormat
2018-07-21 05:56:22 +02:00
syn match csEscapedInterpolation "{{" transparent contains=NONE display
syn match csEscapedInterpolation "}}" transparent contains=NONE display
2022-06-09 20:45:54 +01:00
syn region csInterpolationAlign matchgroup=csInterpolationAlignDel start=+,+ end=+}+ end=+:+me=e-1 contained contains=@csNumber,csBoolean,csConstant,csCharacter,csParens,csOpSymbols,csString,csBracketed display
2018-07-21 05:56:22 +02:00
syn match csInterpolationFormat +:[^}]\+}+ contained contains=csInterpolationFormatDel display
syn match csInterpolationAlignDel +,+ contained display
syn match csInterpolationFormatDel +:+ contained display
2022-12-06 18:20:10 +00:00
syn region csVerbatimString matchgroup=csQuote start=+@"+ end=+"\%(u8\)\=+ skip=+""+ extend contains=csVerbatimQuote,@Spell
2018-07-21 05:56:22 +02:00
syn match csVerbatimQuote +""+ contained
2022-12-06 18:20:10 +00:00
syn region csInterVerbString matchgroup=csQuote start=+$@"+ start=+@$"+ end=+"\%(u8\)\=+ skip=+""+ extend contains=csInterpolation,csEscapedInterpolation,csSpecialChar,csSpecialError,csUnicodeNumber,csVerbatimQuote,@Spell
2022-06-09 20:45:54 +01:00
syn cluster csString contains=csString,csInterpolatedString,csVerbatimString,csInterVerbString
syn cluster csLiteral contains=csBoolean,@csNumber,csCharacter,@csString,csNull
2018-07-21 05:56:22 +02:00
2020-11-29 14:36:24 +01:00
syn region csBracketed matchgroup=csParens start=+(+ end=+)+ extend contained transparent contains=@csAll,csBraced,csBracketed
syn region csBraced matchgroup=csParens start=+{+ end=+}+ extend contained transparent contains=@csAll,csBraced,csBracketed
2018-07-21 05:56:22 +02:00
2022-06-09 20:45:54 +01:00
syn cluster csAll contains=@csLiteral,csClassType,@csComment,csEndColon,csIsType,csLabel,csLogicSymbols,csNewType,csOpSymbols,csParens,@csPreProcessor,csSummary,@csNamespaceAlias,csType,csUnicodeNumber,csUserType,csUserIdentifier,csUserInterface,csUserMethod
" Keyword identifiers
syn match csIdentifier "@\h\w*"
2004-06-13 20:20:40 +00:00
" The default highlighting.
2022-06-09 20:45:54 +01:00
hi def link csUnspecifiedStatement Statement
hi def link csUnsupportedStatement Statement
hi def link csUnspecifiedKeyword Keyword
hi def link csGlobalNamespaceAlias Include
2018-07-21 05:56:22 +02:00
hi def link csType Type
hi def link csClassType Type
hi def link csIsType Type
2022-06-09 20:45:54 +01:00
2018-12-09 20:43:55 +01:00
hi def link csStorage Structure
hi def link csClass Structure
2022-06-09 20:45:54 +01:00
hi def link csNew Statement
hi def link csIsAs Keyword
hi def link csAccessor Keyword
hi def link csAccess Keyword
hi def link csLinq Statement
hi def link csStatement Statement
2018-07-21 05:56:22 +02:00
hi def link csRepeat Repeat
hi def link csConditional Conditional
hi def link csLabel Label
hi def link csException Exception
2022-06-09 20:45:54 +01:00
hi def link csModifier StorageClass
hi def link csAccessModifier csModifier
hi def link csAsyncModifier csModifier
2022-12-06 18:20:10 +00:00
hi def link csCheckedModifier csModifier
2022-06-09 20:45:54 +01:00
hi def link csManagedModifier csModifier
hi def link csUsingModifier csModifier
2018-07-21 05:56:22 +02:00
hi def link csTodo Todo
hi def link csComment Comment
2022-06-09 20:45:54 +01:00
hi def link csLineComment csComment
hi def link csBlockComment csComment
hi def link csKeywordOperator Keyword
hi def link csAsyncOperator csKeywordOperator
hi def link csTypeOf csKeywordOperator
hi def link csTypeOfOperand Typedef
hi def link csTypeOfError Error
2018-07-21 05:56:22 +02:00
hi def link csOpSymbols Operator
2018-12-09 20:43:55 +01:00
hi def link csLogicSymbols Operator
2018-07-21 05:56:22 +02:00
hi def link csSpecialError Error
hi def link csSpecialCharError Error
hi def link csString String
hi def link csQuote String
hi def link csInterpolatedString String
hi def link csVerbatimString String
hi def link csInterVerbString String
hi def link csVerbatimQuote SpecialChar
2022-06-09 20:45:54 +01:00
hi def link csPreProc PreProc
hi def link csPreProcDeclaration Define
hi def link csPreProcConditional PreCondit
hi def link csPreProcLine csPreProc
hi def link csPreProcDiagnostic csPreProc
hi def link csPreProcRegion csPreProc
hi def link csPreProcPragma csPreProc
hi def link csPreProcNullable csPreProc
hi def link csPreProcInclude csPreProc
hi def link csShebang csPreProc
hi def link csConstant Constant
hi def link csNull Constant
hi def link csBoolean Boolean
2018-07-21 05:56:22 +02:00
hi def link csCharacter Character
hi def link csSpecialChar SpecialChar
2022-06-09 20:45:54 +01:00
hi def link csInteger Number
hi def link csReal Float
2018-07-21 05:56:22 +02:00
hi def link csUnicodeNumber SpecialChar
hi def link csUnicodeSpecifier SpecialChar
hi def link csInterpolationDelimiter Delimiter
hi def link csInterpolationAlignDel csInterpolationDelimiter
hi def link csInterpolationFormat csInterpolationDelimiter
hi def link csInterpolationFormatDel csInterpolationDelimiter
2004-06-13 20:20:40 +00:00
2019-08-08 22:15:18 +02:00
hi def link csGenericBraces csBraces
2004-06-13 20:20:40 +00:00
" xml markup
2022-06-09 20:45:54 +01:00
hi def link csXmlLineCommentLeader Comment
hi def link csXmlLineComment Comment
hi def link csXmlBlockComment Comment
hi def link csXmlBlockCommentMiddle csXmlBlockComment
2018-07-21 05:56:22 +02:00
hi def link csXmlTag Statement
2022-06-09 20:45:54 +01:00
hi def link csXmlAttrib Statement
2004-06-13 20:20:40 +00:00
2018-12-09 20:43:55 +01:00
let b:current_syntax = 'cs'
2004-06-13 20:20:40 +00:00
2018-12-09 20:43:55 +01:00
let &cpoptions = s:save_cpo
unlet s:save_cpo
2004-06-13 20:20:40 +00:00
2018-07-21 05:56:22 +02:00
" vim: vts=16,28