1 package a
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var ANTLR = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "ANTLR",
12 Aliases: []string{"antlr"},
13 Filenames: []string{},
14 MimeTypes: []string{},
15 },
16 antlrRules,
17 ))
18
19 func antlrRules() Rules {
20 return Rules{
21 "whitespace": {
22 {`\s+`, TextWhitespace, nil},
23 },
24 "comments": {
25 {`//.*$`, Comment, nil},
26 {`/\*(.|\n)*?\*/`, Comment, nil},
27 },
28 "root": {
29 Include("whitespace"),
30 Include("comments"),
31 {`(lexer|parser|tree)?(\s*)(grammar\b)(\s*)([A-Za-z]\w*)(;)`, ByGroups(Keyword, TextWhitespace, Keyword, TextWhitespace, NameClass, Punctuation), nil},
32 {`options\b`, Keyword, Push("options")},
33 {`tokens\b`, Keyword, Push("tokens")},
34 {`(scope)(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(Keyword, TextWhitespace, NameVariable, TextWhitespace, Punctuation), Push("action")},
35 {`(catch|finally)\b`, Keyword, Push("exception")},
36 {`(@[A-Za-z]\w*)(\s*)(::)?(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, NameLabel, TextWhitespace, Punctuation), Push("action")},
37 {`((?:protected|private|public|fragment)\b)?(\s*)([A-Za-z]\w*)(!)?`, ByGroups(Keyword, TextWhitespace, NameLabel, Punctuation), Push("rule-alts", "rule-prelims")},
38 },
39 "exception": {
40 {`\n`, TextWhitespace, Pop(1)},
41 {`\s`, TextWhitespace, nil},
42 Include("comments"),
43 {`\[`, Punctuation, Push("nested-arg-action")},
44 {`\{`, Punctuation, Push("action")},
45 },
46 "rule-prelims": {
47 Include("whitespace"),
48 Include("comments"),
49 {`returns\b`, Keyword, nil},
50 {`\[`, Punctuation, Push("nested-arg-action")},
51 {`\{`, Punctuation, Push("action")},
52 {`(throws)(\s+)([A-Za-z]\w*)`, ByGroups(Keyword, TextWhitespace, NameLabel), nil},
53 {`(,)(\s*)([A-Za-z]\w*)`, ByGroups(Punctuation, TextWhitespace, NameLabel), nil},
54 {`options\b`, Keyword, Push("options")},
55 {`(scope)(\s+)(\{)`, ByGroups(Keyword, TextWhitespace, Punctuation), Push("action")},
56 {`(scope)(\s+)([A-Za-z]\w*)(\s*)(;)`, ByGroups(Keyword, TextWhitespace, NameLabel, TextWhitespace, Punctuation), nil},
57 {`(@[A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation), Push("action")},
58 {`:`, Punctuation, Pop(1)},
59 },
60 "rule-alts": {
61 Include("whitespace"),
62 Include("comments"),
63 {`options\b`, Keyword, Push("options")},
64 {`:`, Punctuation, nil},
65 {`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
66 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
67 {`<<([^>]|>[^>])>>`, LiteralString, nil},
68 {`\$?[A-Z_]\w*`, NameConstant, nil},
69 {`\$?[a-z_]\w*`, NameVariable, nil},
70 {`(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)`, Operator, nil},
71 {`,`, Punctuation, nil},
72 {`\[`, Punctuation, Push("nested-arg-action")},
73 {`\{`, Punctuation, Push("action")},
74 {`;`, Punctuation, Pop(1)},
75 },
76 "tokens": {
77 Include("whitespace"),
78 Include("comments"),
79 {`\{`, Punctuation, nil},
80 {`([A-Z]\w*)(\s*)(=)?(\s*)(\'(?:\\\\|\\\'|[^\']*)\')?(\s*)(;)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, LiteralString, TextWhitespace, Punctuation), nil},
81 {`\}`, Punctuation, Pop(1)},
82 },
83 "options": {
84 Include("whitespace"),
85 Include("comments"),
86 {`\{`, Punctuation, nil},
87 {`([A-Za-z]\w*)(\s*)(=)(\s*)([A-Za-z]\w*|\'(?:\\\\|\\\'|[^\']*)\'|[0-9]+|\*)(\s*)(;)`, ByGroups(NameVariable, TextWhitespace, Punctuation, TextWhitespace, Text, TextWhitespace, Punctuation), nil},
88 {`\}`, Punctuation, Pop(1)},
89 },
90 "action": {
91 {`([^${}\'"/\\]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|\\(?!%)|/)+`, Other, nil},
92 {`(\\)(%)`, ByGroups(Punctuation, Other), nil},
93 {`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil},
94 {`\{`, Punctuation, Push()},
95 {`\}`, Punctuation, Pop(1)},
96 },
97 "nested-arg-action": {
98 {`([^$\[\]\'"/]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|/)+`, Other, nil},
99 {`\[`, Punctuation, Push()},
100 {`\]`, Punctuation, Pop(1)},
101 {`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil},
102 {`(\\\\|\\\]|\\\[|[^\[\]])+`, Other, nil},
103 },
104 }
105 }
106
View as plain text