1package g
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Groovy lexer.
9var Groovy = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Groovy",
12 Aliases: []string{"groovy"},
13 Filenames: []string{"*.groovy", "*.gradle"},
14 MimeTypes: []string{"text/x-groovy"},
15 DotAll: true,
16 },
17 Rules{
18 "root": {
19 {`#!(.*?)$`, CommentPreproc, Push("base")},
20 Default(Push("base")),
21 },
22 "base": {
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, nil},
27 {`@[a-zA-Z_][\w.]*`, NameDecorator, nil},
28 {`(as|assert|break|case|catch|continue|default|do|else|finally|for|if|in|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b`, Keyword, nil},
29 {`(abstract|const|enum|extends|final|implements|native|private|protected|public|static|strictfp|super|synchronized|throws|transient|volatile)\b`, KeywordDeclaration, nil},
30 {`(def|boolean|byte|char|double|float|int|long|short|void)\b`, KeywordType, nil},
31 {`(package)(\s+)`, ByGroups(KeywordNamespace, Text), nil},
32 {`(true|false|null)\b`, KeywordConstant, nil},
33 {`(class|interface)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
34 {`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
35 {`""".*?"""`, LiteralStringDouble, nil},
36 {`'''.*?'''`, LiteralStringSingle, nil},
37 {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
38 {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
39 {`\$/((?!/\$).)*/\$`, LiteralString, nil},
40 {`/(\\\\|\\"|[^/])*/`, LiteralString, nil},
41 {`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
42 {`(\.)([a-zA-Z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
43 {`[a-zA-Z_]\w*:`, NameLabel, nil},
44 {`[a-zA-Z_$]\w*`, Name, nil},
45 {`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
46 {`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
47 {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
48 {`[0-9]+L?`, LiteralNumberInteger, nil},
49 {`\n`, Text, nil},
50 },
51 "class": {
52 {`[a-zA-Z_]\w*`, NameClass, Pop(1)},
53 },
54 "import": {
55 {`[\w.]+\*?`, NameNamespace, Pop(1)},
56 },
57 },
58))