automatic whitespace for json
This commit is contained in:
parent
5fd3d6b7ba
commit
6f5f4bf270
22
json.parser
22
json.parser
@ -1,12 +1,12 @@
|
||||
// JSON (http://www.json.org)
|
||||
ws:alias = [ \b\f\n\r\t];
|
||||
true = "true";
|
||||
false = "false";
|
||||
null = "null";
|
||||
string = "\"" ([^\\"\b\f\n\r\t] | "\\" (["\\/bfnrt] | "u" [0-9a-f]{4}))* "\"";
|
||||
number = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
||||
entry = string ws* ":" ws* value;
|
||||
object = "{" ws* (entry ws* ("," ws* entry)*)? ws* "}";
|
||||
array = "[" ws* (value ws* ("," ws* value)*)? ws* "]";
|
||||
value:alias = true | false | null | string | number | object | array;
|
||||
json:root = ws* value ws*;
|
||||
whitespace:ws = [ \b\f\n\r\t];
|
||||
true = "true";
|
||||
false = "false";
|
||||
null = "null";
|
||||
string:nows = "\"" ([^\\"\b\f\n\r\t] | "\\" (["\\/bfnrt] | "u" [0-9a-f]{4}))* "\"";
|
||||
number:nows = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
||||
entry = string ":" expression;
|
||||
object = "{" (entry ("," entry)*)? "}";
|
||||
array = "[" (expression ("," expression)*)? "]";
|
||||
expression:alias = true | false | null | string | number | object | array;
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user