-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.tx
75 lines (65 loc) · 2.06 KB
/
json.tx
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
/* Javascript Object Notation (JSON)
https://www.rfc-editor.org/rfc/rfc8259
TextX version by Jean-François Baget (Boreal, Inria, 2024)
*/
JsonText:
value = JsonValue
;
JsonValue:
JsonObject | JsonArray | JsonLiteral | JsonNumber | JsonString
;
JsonObject:
"{"
value *= __Member [","]
"}"
;
__Member:
name = JsonString
":"
value = JsonValue
;
JsonArray:
"["
value *= JsonValue [","]
"]"
;
JsonLiteral:
value = "true" | value = "false" | value = "null"
;
JsonNumber:
/*
number = [ minus ] int [ frac ] [ exp ]
decimal-point = %x2E ; .
digit1-9 = %x31-39 ; 1-9
e = %x65 / %x45 ; e E
exp = e [ minus / plus ] 1*DIGIT
frac = decimal-point 1*DIGIT
int = zero / ( digit1-9 *DIGIT )
minus = %x2D ; -
plus = %x2B ; +
zero = %x30 ; 0
*/
value = /-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-\+]?[0-9]+)?/
;
JsonString:
/*
string = quotation-mark *char quotation-mark
char = unescaped /
escape (
%x22 / ; " quotation mark U+0022
%x5C / ; \ reverse solidus U+005C
%x2F / ; / solidus U+002F
%x62 / ; b backspace U+0008
%x66 / ; f form feed U+000C
%x6E / ; n line feed U+000A
%x72 / ; r carriage return U+000D
%x74 / ; t tab U+0009
%x75 4HEXDIG ) ; uXXXX U+XXXX
escape = %x5C ; \
quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
NOTE: HEXDIG not defined in https://www.rfc-editor.org/rfc/rfc8259
I assumed [0-9A-F] (only uppercase).
*/
value = /"([\u0020\u0021\u0023-\u005B\u005D-\uFFFF\U00010000-\U0010FFFF]|\\["\\/bfnrt]|\\u[0-9A-F]{4})*"/
;