aboutsummaryrefslogtreecommitdiff
path: root/grammars/json.gbnf
blob: 40fa2b63732554acc2c37d79f54091edfa7df2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Grammar for subset of JSON - doesn't support full string or number syntax

root  ::= object
value ::= object | array | string | number | boolean | "null"

object ::=
  "{" ws (
            string ":" ws value
    ("," ws string ":" ws value)*
  )? "}"

array  ::=
  "[" ws (
            value
    ("," ws value)*
  )? "]"

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

# Optional space: by convention, applied in this grammar after literal chars when allowed
ws ::= ([ \t\n] ws)?