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

grammar JSON;

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

rule  members { <string> ':' <value> [',' <string> ':' <value> ]* }

rule  elements { <value> [',' <value> ]* }

token value {
  | <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>
}
