2018-03-19 17:08:44 +01:00
|
|
|
package j
|
2017-10-22 05:37:38 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
2018-03-19 17:08:44 +01:00
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
2017-10-22 05:37:38 +02:00
|
|
|
)
|
|
|
|
|
2019-02-18 19:29:11 +01:00
|
|
|
// JSON lexer.
|
2021-08-04 20:11:59 +02:00
|
|
|
var JSON = internal.Register(MustNewLazyLexer(
|
2017-10-22 05:37:38 +02:00
|
|
|
&Config{
|
|
|
|
Name: "JSON",
|
|
|
|
Aliases: []string{"json"},
|
|
|
|
Filenames: []string{"*.json"},
|
|
|
|
MimeTypes: []string{"application/json"},
|
|
|
|
NotMultiline: true,
|
|
|
|
DotAll: true,
|
|
|
|
},
|
2021-08-04 20:11:59 +02:00
|
|
|
jsonRules,
|
|
|
|
))
|
|
|
|
|
|
|
|
func jsonRules() Rules {
|
|
|
|
return Rules{
|
2017-10-22 05:37:38 +02:00
|
|
|
"whitespace": {
|
|
|
|
{`\s+`, Text, nil},
|
|
|
|
},
|
2022-01-28 18:23:06 +01:00
|
|
|
"comment": {
|
|
|
|
{`//.*?\n`, CommentSingle, nil},
|
|
|
|
},
|
2017-10-22 05:37:38 +02:00
|
|
|
"simplevalue": {
|
|
|
|
{`(true|false|null)\b`, KeywordConstant, nil},
|
|
|
|
{`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
|
|
|
|
{`-?(0|[1-9]\d*)`, LiteralNumberInteger, nil},
|
|
|
|
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
|
|
|
|
},
|
|
|
|
"objectattribute": {
|
|
|
|
Include("value"),
|
|
|
|
{`:`, Punctuation, nil},
|
|
|
|
{`,`, Punctuation, Pop(1)},
|
|
|
|
{`\}`, Punctuation, Pop(2)},
|
|
|
|
},
|
|
|
|
"objectvalue": {
|
|
|
|
Include("whitespace"),
|
2022-01-28 18:23:06 +01:00
|
|
|
Include("comment"),
|
2017-10-22 05:37:38 +02:00
|
|
|
{`"(\\\\|\\"|[^"])*"`, NameTag, Push("objectattribute")},
|
|
|
|
{`\}`, Punctuation, Pop(1)},
|
|
|
|
},
|
|
|
|
"arrayvalue": {
|
|
|
|
Include("whitespace"),
|
|
|
|
Include("value"),
|
2022-01-28 18:23:06 +01:00
|
|
|
Include("comment"),
|
2017-10-22 05:37:38 +02:00
|
|
|
{`,`, Punctuation, nil},
|
|
|
|
{`\]`, Punctuation, Pop(1)},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
Include("whitespace"),
|
|
|
|
Include("simplevalue"),
|
2022-01-28 18:23:06 +01:00
|
|
|
Include("comment"),
|
2017-10-22 05:37:38 +02:00
|
|
|
{`\{`, Punctuation, Push("objectvalue")},
|
|
|
|
{`\[`, Punctuation, Push("arrayvalue")},
|
|
|
|
},
|
|
|
|
"root": {
|
|
|
|
Include("value"),
|
|
|
|
},
|
2021-08-04 20:11:59 +02:00
|
|
|
}
|
|
|
|
}
|