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