1 // pest. Elegant, efficient grammars
2 // Copyright (C) 2016 DragoČ™ Tiselice
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #![recursion_limit = "80"]
25 json
= { value ~ eoi }
27 object
= { ["{"] ~ pair ~ ([","] ~ pair)* ~ ["}
"] | ["{"] ~ ["}
"] }
28 pair = { string ~ [":"] ~ value }
30 array = { ["["] ~ value ~ ([","] ~ value)* ~ ["]"] | ["["] ~ ["]"] }
32 value = { string | number | object | array | ["true"] | ["false"] | ["null"] }
34 string = @{ ["\""] ~ (escape | !(["\""] | ["\\"]) ~ any)* ~ ["\""] }
35 escape = { ["\\"] ~ (["\""] | ["\\"] | ["/"] | ["b"] | ["f"] | ["n"] | ["r"] | ["t"] | unicode) }
36 unicode = { ["u"] ~ hex ~ hex ~ hex ~ hex }
37 hex = { ['0'..'9'] | ['a'..'f'] | ['A'..'F'] }
39 number = @{ ["-"]? ~ int ~ (["."] ~ ['0'..'9']+ ~ exp? | exp)? }
40 int = { ["0"] | ['1'..'9'] ~ ['0'..'9']* }
41 exp = { (["E"] | ["e"]) ~ (["+"] | ["-"])? ~ int }
43 whitespace = _{ [" "] | ["\t"] | ["\r"] | ["\n"] }
48 fn data(b: &mut Bencher) {
49 let mut file = File::open("benches
/data
.json
").unwrap();
50 let mut data = String::new();
52 file.read_to_string(&mut data).unwrap();
54 let mut parser = Rdp::new(StringInput::new(&data));