// pest. The Elegant Parser // Copyright (c) 2018 DragoČ™ Tiselice // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! A parser for JSON file. //! //! And this is a example for JSON parser. json = { SOI ~ value ~ EOI } /// Matches object, e.g.: `{ "foo": "bar" }` /// Foobar object = { "{" ~ pair ~ ("," ~ pair)* ~ "}" | "{" ~ "}" } pair = { #key = string ~ ":" ~ #val = value } array = { "[" ~ value ~ ("," ~ value)* ~ "]" | "[" ~ "]" } // ////////////////////// // /// Matches value, e.g.: `"foo"`, `42`, `true`, `null`, `[]`, `{}`. // ////////////////////// value = { string | number | object | array | bool | null } string = @{ "\"" ~ inner ~ "\"" } inner = @{ (!("\"" | "\\") ~ ANY)* ~ (escape ~ inner)? } escape = @{ "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t" | unicode) } unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} } number = @{ "-"? ~ int ~ ("." ~ ASCII_DIGIT+ ~ exp? | exp)? } int = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } exp = @{ ("E" | "e") ~ ("+" | "-")? ~ ASCII_DIGIT+ } bool = { "true" | "false" } null = { "null" } WHITESPACE = @{ " " | "\t" | "\r" | "\n" }