1 package j
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var JSON = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "JSON",
12 Aliases: []string{"json"},
13 Filenames: []string{"*.json"},
14 MimeTypes: []string{"application/json"},
15 NotMultiline: true,
16 DotAll: true,
17 },
18 jsonRules,
19 ))
20
21 func jsonRules() Rules {
22 return Rules{
23 "whitespace": {
24 {`\s+`, Text, nil},
25 },
26 "comment": {
27 {`//.*?\n`, CommentSingle, nil},
28 },
29 "simplevalue": {
30 {`(true|false|null)\b`, KeywordConstant, nil},
31 {`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
32 {`-?(0|[1-9]\d*)`, LiteralNumberInteger, nil},
33 {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
34 },
35 "objectattribute": {
36 Include("value"),
37 {`:`, Punctuation, nil},
38 {`,`, Punctuation, Pop(1)},
39 {`\}`, Punctuation, Pop(2)},
40 },
41 "objectvalue": {
42 Include("whitespace"),
43 Include("comment"),
44 {`"(\\\\|\\"|[^"])*"`, NameTag, Push("objectattribute")},
45 {`\}`, Punctuation, Pop(1)},
46 },
47 "arrayvalue": {
48 Include("whitespace"),
49 Include("value"),
50 Include("comment"),
51 {`,`, Punctuation, nil},
52 {`\]`, Punctuation, Pop(1)},
53 },
54 "value": {
55 Include("whitespace"),
56 Include("simplevalue"),
57 Include("comment"),
58 {`\{`, Punctuation, Push("objectvalue")},
59 {`\[`, Punctuation, Push("arrayvalue")},
60 },
61 "root": {
62 Include("value"),
63 },
64 }
65 }
66
View as plain text