diff --git a/json.parser b/json.parser index 09c6214..10f0dde 100644 --- a/json.parser +++ b/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; diff --git a/parse_test.go b/parse_test.go index 2554da6..af5ee88 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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", + }, + }}, + ) +} diff --git a/syntax.go b/syntax.go index c5b1183..3333d03 100644 --- a/syntax.go +++ b/syntax.go @@ -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 {