1package c
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// CSharp lexer.
9var CSharp = internal.Register(MustNewLexer(
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	Rules{
19		"root": {
20			{`^\s*\[.*?\]`, NameAttribute, nil},
21			{`[^\S\n]+`, Text, nil},
22			{`\\\n`, Text, nil},
23			{`//.*?\n`, CommentSingle, nil},
24			{`/[*].*?[*]/`, CommentMultiline, nil},
25			{`\n`, Text, nil},
26			{`[~!%^&*()+=|\[\]:;,.<>/?-]`, Punctuation, nil},
27			{`[{}]`, Punctuation, nil},
28			{`@"(""|[^"])*"`, LiteralString, nil},
29			{`\$@?"(""|[^"])*"`, LiteralString, nil},
30			{`"(\\\\|\\"|[^"\n])*["\n]`, LiteralString, nil},
31			{`'\\.'|'[^\\]'`, LiteralStringChar, nil},
32			{`[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
33			{`#[ \t]*(if|endif|else|elif|define|undef|line|error|warning|region|endregion|pragma)\b.*?\n`, CommentPreproc, nil},
34			{`\b(extern)(\s+)(alias)\b`, ByGroups(Keyword, Text, Keyword), nil},
35			{`(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|interface|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},
36			{`(global)(::)`, ByGroups(Keyword, Punctuation), nil},
37			{`(bool|byte|char|decimal|double|dynamic|float|int|long|object|sbyte|short|string|uint|ulong|ushort|var)\b\??`, KeywordType, nil},
38			{`(class|struct)(\s+)`, ByGroups(Keyword, Text), Push("class")},
39			{`(namespace|using)(\s+)`, ByGroups(Keyword, Text), Push("namespace")},
40			{`@?[_a-zA-Z]\w*`, Name, nil},
41		},
42		"class": {
43			{`@?[_a-zA-Z]\w*`, NameClass, Pop(1)},
44			Default(Pop(1)),
45		},
46		"namespace": {
47			{`(?=\()`, Text, Pop(1)},
48			{`(@?[_a-zA-Z]\w*|\.)+`, NameNamespace, Pop(1)},
49		},
50	},
51))
52