diff options
author | Evan Jones <evan.q.jones@gmail.com> | 2023-08-02 22:05:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-02 22:05:44 -0400 |
commit | 8183159cf3def112f6d1fe94815fce70e1bffa12 (patch) | |
tree | 2a8438749b3b664b199778356dc6c2508d582a44 /grammars | |
parent | 468ea24fb4633a0d681f7ac84089566c1c6190cb (diff) |
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
Diffstat (limited to 'grammars')
-rw-r--r-- | grammars/json.gbnf | 16 |
1 files changed, 6 insertions, 10 deletions
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)? |