...

Source file src/github.com/alecthomas/chroma/lexers/c/csharp.go

Documentation: github.com/alecthomas/chroma/lexers/c

     1  package c
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // CSharp lexer.
     9  var CSharp = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "C#",
    12  		Aliases:   []string{"csharp", "c#"},
    13  		Filenames: []string{"*.cs"},
    14  		MimeTypes: []string{"text/x-csharp"},
    15  		DotAll:    true,
    16  		EnsureNL:  true,
    17  	},
    18  	cSharpRules,
    19  ))
    20  
    21  func cSharpRules() Rules {
    22  	return Rules{
    23  		"root": {
    24  			{`^\s*\[.*?\]`, NameAttribute, nil},
    25  			{`[^\S\n]+`, Text, nil},
    26  			{`\\\n`, Text, nil},
    27  			{`///[^\n\r]+`, CommentSpecial, nil},
    28  			{`//[^\n\r]+`, CommentSingle, nil},
    29  			{`/[*].*?[*]/`, CommentMultiline, nil},
    30  			{`\n`, Text, nil},
    31  			{`[~!%^&*()+=|\[\]:;,.<>/?-]`, Punctuation, nil},
    32  			{`[{}]`, Punctuation, nil},
    33  			{`@"(""|[^"])*"`, LiteralString, nil},
    34  			{`\$@?"(""|[^"])*"`, LiteralString, nil},
    35  			{`"(\\\\|\\"|[^"\n])*["\n]`, LiteralString, nil},
    36  			{`'\\.'|'[^\\]'`, LiteralStringChar, nil},
    37  			{`0[xX][0-9a-fA-F]+[Ll]?|[0-9_](\.[0-9]*)?([eE][+-]?[0-9]+)?[flFLdD]?`, LiteralNumber, nil},
    38  			{`#[ \t]*(if|endif|else|elif|define|undef|line|error|warning|region|endregion|pragma|nullable)\b[^\n\r]+`, CommentPreproc, nil},
    39  			{`\b(extern)(\s+)(alias)\b`, ByGroups(Keyword, Text, Keyword), nil},
    40  			{`(abstract|as|async|await|base|break|by|case|catch|checked|const|continue|default|delegate|do|else|enum|event|explicit|extern|false|finally|fixed|for|foreach|goto|if|implicit|in|init|internal|is|let|lock|new|null|on|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|static|switch|this|throw|true|try|typeof|unchecked|unsafe|virtual|void|while|get|set|new|partial|yield|add|remove|value|alias|ascending|descending|from|group|into|orderby|select|thenby|where|join|equals)\b`, Keyword, nil},
    41  			{`(global)(::)`, ByGroups(Keyword, Punctuation), nil},
    42  			{`(bool|byte|char|decimal|double|dynamic|float|int|long|object|sbyte|short|string|uint|ulong|ushort|var)\b\??`, KeywordType, nil},
    43  			{`(class|struct|record|interface)(\s+)`, ByGroups(Keyword, Text), Push("class")},
    44  			{`(namespace|using)(\s+)`, ByGroups(Keyword, Text), Push("namespace")},
    45  			{`@?[_a-zA-Z]\w*`, Name, nil},
    46  		},
    47  		"class": {
    48  			{`@?[_a-zA-Z]\w*`, NameClass, Pop(1)},
    49  			Default(Pop(1)),
    50  		},
    51  		"namespace": {
    52  			{`(?=\()`, Text, Pop(1)},
    53  			{`(@?[_a-zA-Z]\w*|\.)+`, NameNamespace, Pop(1)},
    54  		},
    55  	}
    56  }
    57  

View as plain text