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:
parent
02951cec42
commit
f7c1454f13
@ -23,6 +23,9 @@ func jsonRules() Rules {
|
|||||||
"whitespace": {
|
"whitespace": {
|
||||||
{`\s+`, Text, nil},
|
{`\s+`, Text, nil},
|
||||||
},
|
},
|
||||||
|
"comment": {
|
||||||
|
{`//.*?\n`, CommentSingle, nil},
|
||||||
|
},
|
||||||
"simplevalue": {
|
"simplevalue": {
|
||||||
{`(true|false|null)\b`, KeywordConstant, nil},
|
{`(true|false|null)\b`, KeywordConstant, nil},
|
||||||
{`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
|
{`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
|
||||||
@ -37,18 +40,21 @@ func jsonRules() Rules {
|
|||||||
},
|
},
|
||||||
"objectvalue": {
|
"objectvalue": {
|
||||||
Include("whitespace"),
|
Include("whitespace"),
|
||||||
|
Include("comment"),
|
||||||
{`"(\\\\|\\"|[^"])*"`, NameTag, Push("objectattribute")},
|
{`"(\\\\|\\"|[^"])*"`, NameTag, Push("objectattribute")},
|
||||||
{`\}`, Punctuation, Pop(1)},
|
{`\}`, Punctuation, Pop(1)},
|
||||||
},
|
},
|
||||||
"arrayvalue": {
|
"arrayvalue": {
|
||||||
Include("whitespace"),
|
Include("whitespace"),
|
||||||
Include("value"),
|
Include("value"),
|
||||||
|
Include("comment"),
|
||||||
{`,`, Punctuation, nil},
|
{`,`, Punctuation, nil},
|
||||||
{`\]`, Punctuation, Pop(1)},
|
{`\]`, Punctuation, Pop(1)},
|
||||||
},
|
},
|
||||||
"value": {
|
"value": {
|
||||||
Include("whitespace"),
|
Include("whitespace"),
|
||||||
Include("simplevalue"),
|
Include("simplevalue"),
|
||||||
|
Include("comment"),
|
||||||
{`\{`, Punctuation, Push("objectvalue")},
|
{`\{`, Punctuation, Push("objectvalue")},
|
||||||
{`\[`, Punctuation, Push("arrayvalue")},
|
{`\[`, Punctuation, Push("arrayvalue")},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user