1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

Support comments in JSON

JSON spec doesn't allow comments, but many implementation support them anyway. Having comments is very convenient, for example, when showing code in blog posts and articles.
This commit is contained in:
Andy Yankovsky 2021-08-01 18:21:54 +02:00 committed by Alec Thomas
parent 02951cec42
commit f7c1454f13

View File

@ -23,6 +23,9 @@ func jsonRules() Rules {
"whitespace": {
{`\s+`, Text, nil},
},
"comment": {
{`//.*?\n`, CommentSingle, nil},
},
"simplevalue": {
{`(true|false|null)\b`, KeywordConstant, nil},
{`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
@ -37,18 +40,21 @@ func jsonRules() Rules {
},
"objectvalue": {
Include("whitespace"),
Include("comment"),
{`"(\\\\|\\"|[^"])*"`, NameTag, Push("objectattribute")},
{`\}`, Punctuation, Pop(1)},
},
"arrayvalue": {
Include("whitespace"),
Include("value"),
Include("comment"),
{`,`, Punctuation, nil},
{`\]`, Punctuation, Pop(1)},
},
"value": {
Include("whitespace"),
Include("simplevalue"),
Include("comment"),
{`\{`, Punctuation, Push("objectvalue")},
{`\[`, Punctuation, Push("arrayvalue")},
},