automatic whitespace for json

This commit is contained in:
Arpad Ryszka 2017-10-28 23:18:53 +02:00
parent 5fd3d6b7ba
commit 6f5f4bf270
3 changed files with 27 additions and 12 deletions

View File

@ -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;

View File

@ -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",
},
}},
)
}

View File

@ -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 {