//! JSON Parser item = _{ SOI ~ line* ~ EOI } line = _{ object | array | other } other = ${ !(pair) ~ ANY } WHITESPACE = { " " | "\t" | NEWLINE } // Comment COMMENT = { line_comment | block_comment } line_comment = @{ "//" ~ (!(NEWLINE) ~ ANY)* } block_comment = @{ "/*" ~ (!("*/") ~ ANY)* ~ "*/" } /// Value value = _{ string | number | object | array | bool | null } string = @{ inner_string } inner_string = @{ "\"" ~ inner ~ "\"" } /// Number number = @{ "-"? ~ int ~ ("." ~ ASCII_DIGIT+ ~ exp? | exp)? } int = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } exp = @{ ("E" | "e") ~ ("+" | "-")? ~ ASCII_DIGIT+ } bool = @{ "true" | "false" } null = @{ "null" } /// Object object = { open_object ~ pair ~ (comma ~ pair?)* ~ close_object | open_object ~ close_object } open_object = @{ "{" } close_object = @{ "}" } /// Array array = { open_array ~ value ~ (comma ~ value?)* ~ close_array | open_array ~ close_array } open_array = @{ "[" } close_array = @{ "]" } /// Pair pair = { key ~ value } key = { inner_string ~ colon } colon = @{ ":" } /// Misc comma = @{ "," } inner = @{ (!("\"" | "\\") ~ ANY)* ~ (escape ~ inner)? } escape = @{ "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t" | unicode) } unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} }