automatic whitespace for json
This commit is contained in:
parent
5fd3d6b7ba
commit
6f5f4bf270
16
json.parser
16
json.parser
@ -1,12 +1,12 @@
|
|||||||
// JSON (http://www.json.org)
|
// JSON (http://www.json.org)
|
||||||
ws:alias = [ \b\f\n\r\t];
|
whitespace:ws = [ \b\f\n\r\t];
|
||||||
true = "true";
|
true = "true";
|
||||||
false = "false";
|
false = "false";
|
||||||
null = "null";
|
null = "null";
|
||||||
string = "\"" ([^\\"\b\f\n\r\t] | "\\" (["\\/bfnrt] | "u" [0-9a-f]{4}))* "\"";
|
string:nows = "\"" ([^\\"\b\f\n\r\t] | "\\" (["\\/bfnrt] | "u" [0-9a-f]{4}))* "\"";
|
||||||
number = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
number:nows = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
||||||
entry = string ws* ":" ws* value;
|
entry = string ":" expression;
|
||||||
object = "{" ws* (entry ws* ("," ws* entry)*)? ws* "}";
|
object = "{" (entry ("," entry)*)? "}";
|
||||||
array = "[" ws* (value ws* ("," ws* value)*)? ws* "]";
|
array = "[" (expression ("," expression)*)? "]";
|
||||||
value:alias = true | false | null | string | number | object | array;
|
expression:alias = true | false | null | string | number | object | array;
|
||||||
json:root = ws* value ws*;
|
json:root = expression;
|
||||||
|
@ -629,3 +629,18 @@ func TestEmpty(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCharAsRoot(t *testing.T) {
|
||||||
|
runTests(
|
||||||
|
t,
|
||||||
|
`A = "a"`,
|
||||||
|
[]testItem{{
|
||||||
|
title: "char as root",
|
||||||
|
text: "a",
|
||||||
|
ignorePosition: true,
|
||||||
|
node: &Node{
|
||||||
|
Name: "A",
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (s *Syntax) CharSequence(name string, ct CommitType, chars []rune) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.Sequence(name, ct, namesToSequenceItems(refs)...)
|
return s.Sequence(name, ct|NoWhitespace, namesToSequenceItems(refs)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Syntax) Sequence(name string, ct CommitType, items ...SequenceItem) error {
|
func (s *Syntax) Sequence(name string, ct CommitType, items ...SequenceItem) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user