-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.peg
More file actions
38 lines (27 loc) · 731 Bytes
/
json.peg
File metadata and controls
38 lines (27 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# JSON Grammar for PEG Parser
# Based on standard JSON specification
package json
import "os"
type Json Peg {
// JSON parser type
}
# Entry point
Value <- String / Number / Object / Array / "true" / "false" / "null"
# String with escape sequences
#String <- '"' (![\\"] . / Escape)* '"'
String <- '"' (![\\"] .)* '"'
# Escape sequences
#Escape <- "\\" (
# "\"" / "\\" / "/" /
# "b" / "f" / "n" / "r" / "t" /
# "u" Hex Hex Hex Hex
#)
# Hexadecimal digit
Hex <- [0-9a-fA-F]
# Number (integer or decimal)
Number <- '-'? Integer ('.' [0-9]+)? ([eE] [-+]? [0-9]+)?
Integer <- '0' / [1-9] [0-9]*
# Object
Object <- '{' (String ':' Value (',' String ':' Value)*)? '}'
# Array
Array <- '[' (Value (',' Value)*)? ']'