json.ebnf 1.48 KB
Newer Older
eckhart's avatar
eckhart committed
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# json-grammar  see: https://json.org/

#######################################################################
#
#  EBNF-Directives
#
#######################################################################

@ whitespace  = vertical        # implicit whitespace, includes any number of line feeds
@ literalws   = right           # literals have implicit whitespace on the right hand side
@ comment     = /\/\/.*/        # comments range from a '#'-character to the end of the line
@ ignorecase  = False           # literals and regular expressions are case-sensitive


#######################################################################
#
#:  JSON elements
#
#######################################################################

json       = ~ element EOF
element    = value
value      = object | array | string | number | "true" | "false" | "null"
object     = "{" [member { "," member }] "}"
member     = string ":" element
array      = "[" [value { "," value }] "]"
string     = `"` CHARACTERS `"` ~
number     = INT FRAC EXP ~

#######################################################################
#
#:  JSON primitives
#
#######################################################################

CHARACTERS = { /[^"\\]+/ | ESCAPE }
ESCAPE     = /\\[\/bnrt\\]/ | /\\u/ HEX HEX HEX HEX
HEX        = /[0-9a-fA-F]/

INT        = [`-`] /[0-9]/ | /[1-9][0-9]+/
FRAC       = [ `.` /[0-9]+/ ]
EXP        = [ (`E`|`e`) [`+`|`-`] /[0-9]+/ ]

EOF      =  !/./        # no more characters ahead, end of file reached