# example.??? -rw-r--r-- 1.5 KiB View raw
                                                                                
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# - Easily read and edited by humans
# - Unambiguous and strongly typed
# - Syntax is a superset of JSON, but structure is identical to JSON
#
# Differences from JSON:
#
# - Commas optional if whitespace would disambiguate members
# - But trailing commas at the end of arrays and objects is fine
# - Quotes not required around object keys
# - Top-level element, if an object, may start listing members directly without
#   adding { and }
# - Two multiline string literals, one which joins all of the lines with " "
#   and another which preserves newlines
# - Hex, binary, and octal integer literals

scalars: {
	foo: 1234
	bar: 1.234
	baz: 1.2e34
	bad: true
	fab: false
	cab: null
	bin: 0b11001100
	oct: 0o644
	hex: 0xDEADBEEF
}

strings: {
	example: "hello world"
	with_escapes: "hello\nworld"
	joined: <
		this string is several lines
		long and each line is joined
		with a space to produce a
		one-line string. Whitespace
		before and after each line is
		stripped.
	>
	literal: `
		this string is several lines
		long and the newlines are
		preserved. Whitespace before
		and after each line is stripped.
	`
}

lists: {
	multiline: [
		"hello"
		"world"
	]
	spaces: ["hello" -10 null false "spaces" "separate" "members"]
	json: ["hello", "world"]
	matrix: [
		-1   0   0
		 0  -1   0
		 0   0  -1
	]
}

dicts: {
	json_style: {
		"hello": "world",
		"foo": "bar",
		#           ^ Trailing comma is permitted here
	}
	json_oneline: { "hello": "world", "foo": "bar" }
	lite: {
		hello: "world"
		foo: "bar"
	}
	lite_oneline: { hello: "world" foo: "bar" }
}
# example.grammar -rw-r--r-- 1.6 KiB View raw
                                                                                
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
json
    element
    members

value
    object
    array
    string
    number
    "true"
    "false"
    "null"

object
    '{' optwscomment '}'
    '{' members '}'
    '{' members ',' '}'

members
    member
    member ',' members
    member newline members

member
    optwscomment string optwscomment ':' element
    characters ':' element

array
    '[' optwscomment ']'
    '[' elements ']'
    '[' elements ',' ']'

elements
    element
    element ',' elements
    element wscomment elements

element
    optwscomment value optwscomment

string
    '"' characters '"'
    '<' characters '>'
    '`' characters '`'

characters
    ""
    character characters

character
    '0020' . '10ffff' - '"' - '\'
    '\' escape

escape
    '"'
    '\'
    '/'
    'b'
    'f'
    'n'
    'r'
    't'
    'u' hex hex hex hex

hex
    digit
    'A' . 'F'
    'a' . 'f'

number
    integer fraction exponent

integer
    digit
    onenine digits
    '-' digit
    '-' onenine digits
    '0' 'x' hexes
    '0' 'b' bins
    '0' 'o' octs

digits
    digit
    digit digits

digit
    '0'
    onenine

onenine
    octs
    '8'
    '9'

bins
    '0'
    '1'
    '0' bins
    '1' bins

octs
    '1' . '7'

hexes
    hex
    hex hexex

fraction
    ""
    '.' digits

exponent
    ""
    'E' sign digits
    'e' sign digits

sign
    ""
    '+'
    '-'

newline
    '000A'

ws
    ""
    '0020' ws
    '000D' ws
    '0009' ws
    newline ws

optws
    ""
    ws

any
    '0020' . '10ffff'
    '0020' . '10ffff' any

comment
    '#' ' ' any newline

optwscomment
    optws
    optws comment optws

wscomment
    ws
    optws comment optws
# json.diff -rw-r--r-- 1.5 KiB View raw
                                                                                
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--- /tmp/json
+++ /tmp/grammar
@@ -1,5 +1,6 @@
 json
     element
+    members
 
 value
     object
@@ -11,29 +12,36 @@
     "null"
 
 object
-    '{' ws '}'
+    '{' optwscomment '}'
     '{' members '}'
+    '{' members ',' '}'
 
 members
     member
     member ',' members
+    member newline members
 
 member
-    ws string ws ':' element
+    optwscomment string optwscomment ':' element
+    characters ':' element
 
 array
-    '[' ws ']'
+    '[' optwscomment ']'
     '[' elements ']'
+    '[' elements ',' ']'
 
 elements
     element
     element ',' elements
+    element wscomment elements
 
 element
-    ws value ws
+    optwscomment value optwscomment
 
 string
     '"' characters '"'
+    '<' characters '>'
+    '`' characters '`'
 
 characters
     ""
@@ -67,6 +75,9 @@
     onenine digits
     '-' digit
     '-' onenine digits
+    '0' 'x' hexes
+    '0' 'b' bins
+    '0' 'o' octs
 
 digits
     digit
@@ -77,8 +88,23 @@
     onenine
 
 onenine
-    '1' . '9'
+    octs
+    '8'
+    '9'
 
+bins
+    '0'
+    '1'
+    '0' bins
+    '1' bins
+
+octs
+    '1' . '7'
+
+hexes
+    hex
+    hex hexex
+
 fraction
     ""
     '.' digits
@@ -93,9 +119,31 @@
     '+'
     '-'
 
+newline
+    '000A'
+
 ws
     ""
     '0020' ws
     '000D' ws
-    '000A' ws
     '0009' ws
+    newline ws
+
+optws
+    ""
+    ws
+
+any
+    '0020' . '10ffff'
+    '0020' . '10ffff' any
+
+comment
+    '#' ' ' any newline
+
+optwscomment
+    optws
+    optws comment optws
+
+wscomment
+    ws
+    optws comment optws