From 8183159cf3def112f6d1fe94815fce70e1bffa12 Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Wed, 2 Aug 2023 22:05:44 -0400 Subject: examples : generate JSON according to schema (#1887) * examples : add JSON schema grammars * complete JSON grammar * ensure primitive types can be used as root of schema * support integer type and adjust usage text --- grammars/json.gbnf | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'grammars') diff --git a/grammars/json.gbnf b/grammars/json.gbnf index 40fa2b6..a9537cd 100644 --- a/grammars/json.gbnf +++ b/grammars/json.gbnf @@ -1,29 +1,25 @@ -# Grammar for subset of JSON - doesn't support full string or number syntax - -root ::= object -value ::= object | array | string | number | boolean | "null" +root ::= object +value ::= object | array | string | number | ("true" | "false" | "null") ws object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* - )? "}" + )? "}" ws array ::= "[" ws ( value ("," ws value)* - )? "]" + )? "]" ws -string ::= +string ::= "\"" ( [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes )* "\"" ws -# Only plain integers currently -number ::= "-"? [0-9]+ ws -boolean ::= ("true" | "false") ws +number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws # Optional space: by convention, applied in this grammar after literal chars when allowed ws ::= ([ \t\n] ws)? -- cgit v1.2.3