1package j
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Java lexer.
9var Java = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Java",
12 Aliases: []string{"java"},
13 Filenames: []string{"*.java"},
14 MimeTypes: []string{"text/x-java"},
15 DotAll: true,
16 },
17 Rules{
18 "root": {
19 {`[^\S\n]+`, Text, nil},
20 {`//.*?\n`, CommentSingle, nil},
21 {`/\*.*?\*/`, CommentMultiline, nil},
22 {`(assert|break|case|catch|continue|default|do|else|finally|for|if|goto|instanceof|new|return|switch|this|throw|try|while)\b`, Keyword, nil},
23 {`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
24 {`@[^\W\d][\w.]*`, NameDecorator, nil},
25 {`(abstract|const|enum|extends|final|implements|native|private|protected|public|static|strictfp|super|synchronized|throws|transient|volatile)\b`, KeywordDeclaration, nil},
26 {`(boolean|byte|char|double|float|int|long|short|void)\b`, KeywordType, nil},
27 {`(package)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
28 {`(true|false|null)\b`, KeywordConstant, nil},
29 {`(class|interface)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
30 {`(import(?:\s+static)?)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
31 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
32 {`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
33 {`(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil},
34 {`^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil},
35 {`([^\W\d]|\$)[\w$]*`, Name, nil},
36 {`([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)[pP][+\-]?[0-9][0-9_]*[fFdD]?`, LiteralNumberFloat, nil},
37 {`0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?`, LiteralNumberHex, nil},
38 {`0[bB][01][01_]*[lL]?`, LiteralNumberBin, nil},
39 {`0[0-7_]+[lL]?`, LiteralNumberOct, nil},
40 {`0|[1-9][0-9_]*[lL]?`, LiteralNumberInteger, nil},
41 {`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
42 {`\n`, Text, nil},
43 },
44 "class": {
45 {`([^\W\d]|\$)[\w$]*`, NameClass, Pop(1)},
46 },
47 "import": {
48 {`[\w.]+\*?`, NameNamespace, Pop(1)},
49 },
50 },
51))