-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathjsox-parser.ebnf
176 lines (171 loc) · 11.2 KB
/
jsox-parser.ebnf
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Name = "JSOX Parser".
Author = "d3x0r".
Version = "1.0".
Level0 = "gatherString" ( "while string not close; NC" )
| "gatherNumber" ( "while '0-9','.','E','e','+','-',':','T','Z'; NC" )
| "comment" ( "[state 0]" ( | ( "/" "state = 1; NC" ) )
| "[state 1]" ( ( "*" "state = 3; NC" )
| ( "/" "state=2; NC" )
| ( "else" "error - unexpected character" )
)
| "[state 2]" ( ( ("\n" | "\r") "state = 0; NC" ) | "NC" )
| "[state 3]" ( ( "*" "state=4; NC" ) | "NC" )
| "[state 4]" ( ( "/" "state=0; NC" )
| ( "not *" "state=3; NC" )
| ( "NC" ) )
)
( ( "{" ( "if gettingFieldName" "error - unexpected"
| "begin new object, expect gettingFieldName; NC"
)
)
| ( "[" ( "if gettingFieldName" "error - unexpected"
| "begin new array; NC"
)
)
| ( ":" ( "if getting field name" "Save field name; set gettingValue; NC"
| "if in array" "ERROR - no field labels in array"
| "else" "ERROR - unexpected token"
)
)
| ( "," ( "if getting field name" "error"
| "if in array" "push previous collected value; NC"
| "if gettingValue" "set previous collected field name to value; NC"
| "else" "ERROR - unexpected token"
)
)
| ( "]" ( "if in array" "close array, pop context to prior; NC"
)
)
| ( "}" ( "if gettingValue" "close object, pop prior context; NC"
| "else" "EEROR"
)
)
| ( ( '"'| "'" | "`" ) "Begin gather string; NC" )
| ( ( "\x20"| "\r"| "\n"| "\t"| "#2028"| "#2029" ) ( "[word 0] ignore; NC" | "[word 99] ignore; NC" | "recover text; end ident" ) )
| ( "t" ("[word 0] set word=1 '[t]rue'"
|"[word 18] set word=19 'Infini[t]y'"
| "recover text; set ident") )
| ( "r" ("[word 1] set word=2 't[r]ue'" | "recover text; set ident" ) )
| ( "u" ("[word 2] set word=3 'tr[u]e'"
| "[word 8] set word=9 'n[u]ll'"
| "recover text; set ident") )
| ( "e" ("[word 3] set value=true, word=99 'tru[e]'"
| "[word 7] set value=false, word=99 'fals[e]'"
| "[word 22] set word=23 'und[e]fined'"
| "[word 26] set word=27 'undefin[e]d'"
| "recover text; set ident") )
| ( "f" ("[word 0] set word=4 '[f]alse'"
| "[word 14] set word=15 'In[f]inity'"
| "[word 23] set word=24 'unde[f]ined'"
| "recover text; set ident") )
| ( "a" ("[word 4] set word=5 'f[a]lse'"
| "[word 11] set word=12 'N[a]N'"
| "recover text; set ident") )
| ( "l" ("[word 5] set word=6 'fa[l]se'"
| "[word 9] set word=10 'nu[l]l"
| "[word 10] set value=null, word=99 'nul[l]'"
| "recover text; set ident") )
| ( "s" ("[word 6] set word=7 'fal[s]e' "| "recover text; set ident") )
| ( "n" ("[word 6] set word=8 '[n]ull'"
| "[word 13] set word=14 'I[n]finity'"
| "[word 16] set word=17 'Infi[n]ity'"
| "[word 20] set word=21 'u[n]defined'"
| "[word 25] set word=26 'undefi[n]ed'"
| "recover text; set ident") )
| ( "u" ("[word 0] set word=20 'n[u]ll'" | "recover text; set ident") )
| ( "d" ("[word 21] set word=22 'un[d]efined'"
| "[word 27] set value=undefined, word=99 'undefine[d]'"
| "recover text; set ident") )
| ( "N" ("[word 0] set word=11 '[N]aN'"
| "[word 12] set value=(negative)NaN, word=99 'Na[N]'"
| "recover text; set ident") )
| ( "I" ("[word 0] set word=13 '[I]nfinity"
| "recover text; set ident") )
| ( "i" ("[word 15] set word=16 'Inf[i]nity'"
| "[word 17] set word=18 'Infin[i]ty'"
| "[word 24] set word=25 'undef[i]ned'"
| "recover text; set ident") )
| ( "y" ("[word 19] set value=(negative)Infinity 'Infinit[y]'"
| "recover text; set ident") )
| ( "-" ("[word 0] set negative=!negative" | "ERROR" ) )
| ( ( "0-9" | "+" | "." ) ( "[word 0] begin gathering number"
| "recover text; set ident" ) )
| "else" ( ( "[word 0]" ( "if not unicode-non-identifier, word=50"
| "error, unepected character" ) )
| ( "[word 50]" ( "add to identifier" ) )
| ( "[word 99]" "recover text; set ident" )
)
)
))
) "open/close object/array, update from ident to value, push collected field/value" )
|
.
Val = "(Value)" (|"whitespace") ( ("(Comment)" ( ( "/" "/" { "character not \n or \r" } ("\r"|"\n") )
| ( "/" "*" { "character" } "*" "/" )
))|
( "(whitespace)" ( "\x20" | "\r" | "\n" | "\t" | "\u07ec" | "\u07ed" ) ) |
( "(ident)" ( "String" | ( "non-digit" | "non-operator" | "not { [ ( ) ] } , : double-quote ' `" | "unicode non-identifier characters" | "a-z" "A-Z" ) { | "non-operator" | "not { [ ( ) ] } , : double-quote ' `" | "unicode non-identifier characters" | "a-z" "A-Z" "0-9" } )
)|
( "(Object)" "{" ( (|"whitespace")ident(|"whitespace") ":" Value ) { "," ( (|"whitespace") ident (|"whitespace") ":" Value) } "}" ) |
( "(typed-object-def)" ident "{" (|"whitespace")(ident (|"whitespace")) { "," (|"whitespace") (ident (|"whitespace")) } "}" ) |
( "(typed-object-use)" ident "{" ( Value ) { "," (Value) } "}" ) |
( "(Array)" "[" ( Value ) { "," Value } "]" ) |
( "(TypedArray)" ( "a" "b" | "u" "8" | "s" "8" | "u" "c" "8" | "u" "1" "6" | "s" "1" "6"
| "u" "3" "2"
| "s" "3" "2"
| "f" "3" "2"
| "f" "6" "4"
) "[" "base64 ArrayBuffer bytes" "]" ) |
( "(reference)" "r" "e" "f" "[" ( (|"whitespace")( "ident" | "int" ) (|"whitespace") { ("," (|"whitespace")( "ident" | "int" )(|"whitespace")) }) "]" ) |
( "(typed-array)" "ident" "[" ( Value ) { "," Value } "]" ) |
( "(typed-string)" "ident" String ) |
( |"-") ( "NaN" | "Infinity" |
( ( "-" | "+" ) { "-" | "+" } | ("0-9") ) "/*Number Parser Bgin*/"
( "/* underscore '_' between any following sequence's symbols */" | ( "(BigInt)" { "0-9" } "n" ) |
"(Number)"( "(int)"( "0" (
( ( "x" | "X" ) ("0-9" | "A-F" | "a-f") { "0-9" | "A-F" | "a-f" } ) |
( ( "o" | "O" ) "0-7" { "0-7" } ) |
( ( "b" | "B" ) "0-1" { "0-1" ) |
( "0-7" {"0-7"})
)
)
| "(float)" ( "0-9" | "." ) { "0-9" | "."} ( "(int) if no . "
| ( ( "e" | "E" ) ( "0-9" | "+" "0-9" | "-" "0-9" ) { "0-9" } ) )
) ( |"NOT THESE:" ( "0-9"| "-"| ":"| "+" | "A-F"| "a-f" ) ) "/*number terminator*/" ( "," | "}" | "]" | "whitespace /* outside of array or object */" )
| "(Date)" ( ( ("0-9" | ":" | "T" | "-" | "+")
{ "0-9" | ":" | "T" | "-" | "+" })
( ( |"NOT THESE:" ( "0-9"| "-"| ":"| "+" | "Z"| "T" ) ) "/*date terminator*/" ( "," | "}" | "]" | "whitespace /* outside of array or object */" )
| ( |"+"|"-") "0-9" "0-9" ":" "0-9" "0-9"
| "Z" ) )
)) |
("(String)" ( ( "(Legal Escapes)" ( "b" | "n" | "r" | "f" | "t" | ("'" | '"' | "`")
| ( "u" ( "{" {"0-9" | "A-F" | "a-f"} "}" | "4 hex digits" ) )
| ( "x" ("0-9" | "A-F" | "a-f") ("0-9" | "A-F" | "a-f") )
| ( "0-2" "0-7" "0-7" )
)
)|
( '"' (( 'character not " or \ ' ) | ( '\' '"' ) | ("\" "\" ) | ( "\" "Legal Escapes" ) ) { ( 'character not " or \ ' ) | ( '\' '"' ) | ("\" "\" ) | ( "\" "Legal Escapes" ) } '"' ) |
( "'" ( "character not ' or \" | ( "\" "'" ) | ("\" "\" ) | ( "\" "Legal Escapes" ) ) { "character not ' or \" | ( "\" "'" ) | ("\" "\" ) | ( "\" "Legal Escapes" ) } "'" ) |
( "`" ( "character not ` or \" | ( "\" '`' ) | ("\" "\" ) | ( "\" "Legal Escapes" ) ) { "character not ` or \" | ( "\" '`' ) | ("\" "\" ) | ( "\" "Legal Escapes" ) } "`" ) )
)|
true | false | null | undefined ) (|"whitespace").
NumberRule = ("(Number/Date/BigInt)"
( |"-") ( "NaN" | "Infinity" |
( ( "-" | "+" ) { "-" | "+" } | ("0-9") ) "/*Number Parser Bgin*/"
( "/* underscore '_' between any following sequence's symbols */" | ( "(BigInt)" { "0-9" } "n" ) |
"(Number)"( "(int)"( "0" (
( ( "x" | "X" ) ("0-9" | "A-F" | "a-f") { "0-9" | "A-F" | "a-f" } ) |
( ( "o" | "O" ) "0-7" { "0-7" } ) |
( ( "b" | "B" ) "0-1" { "0-1" ) |
( "0-7" {"0-7"})
)
)
| "(float)" ( "0-9" | "." ) { "0-9" | "."} ( "(int) if no . "
| ( ( "e" | "E" ) ( "0-9" | "+" "0-9" | "-" "0-9" ) { "0-9" } ) )
) ( |"NOT THESE:" ( "0-9"| "-"| ":"| "+" | "A-F"| "a-f" ) ) "/*number terminator*/" ( "," | "}" | "]" | "whitespace /* outside of array or object */" )
| "(Date)" ( ( ("0-9" | ":" | "T" | "-" | "+")
{ "0-9" | ":" | "T" | "-" | "+" })
( ( |"NOT THESE:" ( "0-9"| "-"| ":"| "+" | "Z"| "T" ) ) "/*date terminator*/" ( "," | "}" | "]" | "whitespace /* outside of array or object */" )
| ( |"+"|"-") "0-9" "0-9" ":" "0-9" "0-9"
| "Z" ) )
))).