1package c
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Ceylon lexer.
9var Ceylon = internal.Register(MustNewLazyLexer(
10	&Config{
11		Name:      "Ceylon",
12		Aliases:   []string{"ceylon"},
13		Filenames: []string{"*.ceylon"},
14		MimeTypes: []string{"text/x-ceylon"},
15		DotAll:    true,
16	},
17	ceylonRules,
18))
19
20func ceylonRules() Rules {
21	return Rules{
22		"root": {
23			{`^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)([a-zA-Z_]\w*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
24			{`[^\S\n]+`, Text, nil},
25			{`//.*?\n`, CommentSingle, nil},
26			{`/\*`, CommentMultiline, Push("comment")},
27			{`(shared|abstract|formal|default|actual|variable|deprecated|small|late|literal|doc|by|see|throws|optional|license|tagged|final|native|annotation|sealed)\b`, NameDecorator, nil},
28			{`(break|case|catch|continue|else|finally|for|in|if|return|switch|this|throw|try|while|is|exists|dynamic|nonempty|then|outer|assert|let)\b`, Keyword, nil},
29			{`(abstracts|extends|satisfies|super|given|of|out|assign)\b`, KeywordDeclaration, nil},
30			{`(function|value|void|new)\b`, KeywordType, nil},
31			{`(assembly|module|package)(\s+)`, ByGroups(KeywordNamespace, Text), nil},
32			{`(true|false|null)\b`, KeywordConstant, nil},
33			{`(class|interface|object|alias)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
34			{`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
35			{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
36			{`'\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'`, LiteralStringChar, nil},
37			{"\".*``.*``.*\"", LiteralStringInterpol, nil},
38			{`(\.)([a-z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
39			{`[a-zA-Z_]\w*:`, NameLabel, nil},
40			{`[a-zA-Z_]\w*`, Name, nil},
41			{`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
42			{`\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?`, LiteralNumberFloat, nil},
43			{`\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?`, LiteralNumberFloat, nil},
44			{`[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?`, LiteralNumberFloat, nil},
45			{`[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?`, LiteralNumberFloat, nil},
46			{`#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+`, LiteralNumberHex, nil},
47			{`#[0-9a-fA-F]+`, LiteralNumberHex, nil},
48			{`\$([01]{4})(_[01]{4})+`, LiteralNumberBin, nil},
49			{`\$[01]+`, LiteralNumberBin, nil},
50			{`\d{1,3}(_\d{3})+[kMGTP]?`, LiteralNumberInteger, nil},
51			{`[0-9]+[kMGTP]?`, LiteralNumberInteger, nil},
52			{`\n`, Text, nil},
53		},
54		"class": {
55			{`[A-Za-z_]\w*`, NameClass, Pop(1)},
56		},
57		"import": {
58			{`[a-z][\w.]*`, NameNamespace, Pop(1)},
59		},
60		"comment": {
61			{`[^*/]`, CommentMultiline, nil},
62			{`/\*`, CommentMultiline, Push()},
63			{`\*/`, CommentMultiline, Pop(1)},
64			{`[*/]`, CommentMultiline, nil},
65		},
66	}
67}
68