# From http://www.json.org/

grammar JSON;

rule object { \{ <members>?  \} }
rule array  { \[ \] | \[ <elements> \] }
rule string { "<char>*" }

rule  members { <string> \: <thing> [, <string> \: <thing> ]* }

rule  elements { <thing> [, <thing> ]* }

# XXX This should be called 'value', but...
# RT#40069: [PGE] "value" can't be used as a rule name.

token thing {
  | <object>
  | <array>
  | <string>
  | <number>
  | true
  | false
  | null
  | <?PGE::Util::die 'not a valid JSON value'>
}

# XXX need to add "except control char" to the final charclass here.
token char {
  | \\<["\\/bfnrt]>
  | \\u<xdigit>**{4}
  | <-[\\"]>
}

token number {
 <?ws>
 -?
 [ <[1..9]> <[0..9]>+ | <[0..9]> ]
 [ \. <[0..9]>+ ]?
 [ <[Ee]> <[+\-]>? <[0..9]>+ ]?
 <?ws>
}
