Skip to content
Newer
Older
100644 496 lines (452 sloc) 20.6 KB
955caa8 initial barely working json parser
Chris Anderson authored
1 %% The source of this file is part of leex distribution, as such it
2 %% has the same Copyright as the other files in the leex
3 %% distribution. The Copyright is defined in the accompanying file
4 %% COPYRIGHT. However, the resultant scanner generated by leex is the
5 %% property of the creator of the scanner and is not covered by that
6 %% Copyright.
7
5e1c937 parser for eep
Chris Anderson authored
8 -module(json_lex2).
955caa8 initial barely working json parser
Chris Anderson authored
9
10 -export([string/1,string/2,token/2,token/3,tokens/2,tokens/3]).
11 -export([format_error/1]).
12
13 %% User code. This is placed here to allow extra attributes.
5e1c937 parser for eep
Chris Anderson authored
14 % "
15
16 -define(LOG(Name, Value),
17 io:format("{~p:~p}: ~p -> ~s~n", [?MODULE, ?LINE, Name, Value])).
18 -define(PLOG(Name, Value),
19 io:format("{~p:~p}: ~p -> ~p~n", [?MODULE, ?LINE, Name, Value])).
20
21 strip(TokenChars,TokenLen) -> lists:sublist(TokenChars, 2, TokenLen - 2).
22
2673dc0 Richard O'Keefe's whole float DFA
Chris Anderson authored
23 whole_float(Token_Chars) ->
24 list_to_float(insert_point_zero(Token_Chars)).
25
26 insert_point_zero([$e|Cs]) -> ".0e" ++ Cs;
27 insert_point_zero([$E|Cs]) -> ".0e" ++ Cs;
28 insert_point_zero([C |Cs]) -> [C | insert_point_zero(Cs)].
5e1c937 parser for eep
Chris Anderson authored
29
30 unescape([$\\,$\"|Cs]) -> [$\"|unescape(Cs)];
31 unescape([$\\,$\\|Cs]) -> [$\\|unescape(Cs)];
32 unescape([$\\,$/|Cs]) -> [$/|unescape(Cs)];
33 unescape([$\\,$b|Cs]) -> [$\b|unescape(Cs)];
34 unescape([$\\,$f|Cs]) -> [$\f|unescape(Cs)];
35 unescape([$\\,$n|Cs]) -> [$\n|unescape(Cs)];
36 unescape([$\\,$r|Cs]) -> [$\r|unescape(Cs)];
37 unescape([$\\,$t|Cs]) -> [$\t|unescape(Cs)];
38 unescape([$\\,$u,C0,C1,C2,C3|Cs]) ->
39 C = dehex(C3) bor
40 (dehex(C2) bsl 4) bor
41 (dehex(C1) bsl 8) bor
42 (dehex(C0) bsl 12),
43 [C|unescape(Cs)];
44 unescape([C|Cs]) -> [C|unescape(Cs)];
45 unescape([]) -> [].
46
47 dehex(C) when C >= $0, C =< $9 -> C - $0;
48 dehex(C) when C >= $a, C =< $f -> C - $a + 10;
49 dehex(C) when C >= $A, C =< $F -> C - $A + 10.
50
51 parse_string(StringChars) ->
52 unescape(StringChars).
955caa8 initial barely working json parser
Chris Anderson authored
53
54 format_error({illegal,S}) -> ["illegal characters ",io_lib:write_string(S)];
55 format_error({user,S}) -> S.
56
57 string(String) -> string(String, 1).
58
59 string(String, Line) -> string(String, Line, String, []).
60
61 %% string(InChars, Line, TokenChars, Tokens) ->
62 %% {ok,Tokens,Line} | {error,ErrorInfo,Line}.
63
64 string([], L, [], Ts) -> %No partial tokens!
65 {ok,yyrev(Ts),L};
66 string(Ics0, L0, Tcs, Ts) ->
67 case yystate(yystate(), Ics0, L0, 0, reject, 0) of
68 {A,Alen,Ics1,L1} -> %Accepting end state
69 string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L1), Ts);
70 {A,Alen,Ics1,L1,_S1} -> %After an accepting state
71 string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L1), Ts);
72 {reject,_Alen,Clen,_Ics1,L1,_S1} -> %After a non-accepting state
73 {error,{L1,?MODULE,{illegal,yypre(Tcs, Clen+1)}},L1};
74 {A,Alen,_Clen,_Ics1,L1,_S1} ->
75 string_cont(yysuf(Tcs, Alen), L1, yyaction(A, Alen, Tcs, L1), Ts)
76 end.
77
78 %% string_cont(RestChars, Line, Token, Tokens)
79 %% Test for and remove the end token wrapper.
80
81 string_cont(Rest, Line, {token,T}, Ts) ->
82 string(Rest, Line, Rest, [T|Ts]);
83 string_cont(Rest, Line, {end_token,T}, Ts) ->
84 string(Rest, Line, Rest, [T|Ts]);
85 string_cont(Rest, Line, skip_token, Ts) ->
86 string(Rest, Line, Rest, Ts);
87 string_cont(_Rest, Line, {error,S}, _Ts) ->
88 {error,{Line,?MODULE,{user,S}},Line}.
89
90 %% token(Continuation, Chars, Line) ->
91 %% {more,Continuation} | {done,ReturnVal,RestChars}.
92 %% Must be careful when re-entering to append the latest characters to the
93 %% after characters in an accept.
94
95 token(Cont, Chars) -> token(Cont, Chars, 1).
96
97 token([], Chars, Line) ->
98 token(Chars, Line, yystate(), Chars, 0, reject, 0);
99 token({token,Line,State,Tcs,Clen,Action,Alen}, Chars, _) ->
100 token(Chars, Line, State, Tcs ++ Chars, Clen, Action, Alen).
101
102 %% token(InChars, Line, State, TokenChars, CurrTokLen,
103 %% AcceptAction, AcceptLen) ->
104 %% {more,Continuation} | {done,ReturnVal,RestChars}.
105
106 token(Ics0, L0, S0, Tcs, Clen0, A0, Alen0) ->
107 case yystate(S0, Ics0, L0, Clen0, A0, Alen0) of
108 {A1,Alen1,Ics1,L1} -> %Accepting end state
109 token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1));
110 {A1,Alen1,[],L1,S1} -> %After an accepting state
111 {more,{token,L1,S1,Tcs,Alen1,A1,Alen1}};
112 {A1,Alen1,Ics1,L1,_S1} ->
113 token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1));
114 {A1,Alen1,Clen1,[],L1,S1} -> %After a non-accepting state
115 {more,{token,L1,S1,Tcs,Clen1,A1,Alen1}};
116 {reject,_Alen1,_Clen1,eof,L1,_S1} ->
117 {done,{eof,L1},[]};
118 {reject,_Alen1,Clen1,Ics1,L1,_S1} ->
119 {done,{error,{L1,?MODULE,{illegal,yypre(Tcs, Clen1+1)}},L1},Ics1};
120 {A1,Alen1,_Clen1,_Ics1,L1,_S1} ->
121 token_cont(yysuf(Tcs, Alen1), L1, yyaction(A1, Alen1, Tcs, L1))
122 end.
123
124 %% tokens_cont(RestChars, Line, Token)
125 %% If we have a token or error then return done, else if we have a
126 %% skip_token then continue.
127
128 token_cont(Rest, Line, {token,T}) ->
129 {done,{ok,T,Line},Rest};
130 token_cont(Rest, Line, {end_token,T}) ->
131 {done,{ok,T,Line},Rest};
132 token_cont(Rest, Line, skip_token) ->
133 token(Rest, Line, yystate(), Rest, 0, reject, 0);
134 token_cont(Rest, Line, {error,S}) ->
135 {done,{error,{Line,?MODULE,{user,S}},Line},Rest}.
136
137 %% tokens(Continuation, Chars, Line) ->
138 %% {more,Continuation} | {done,ReturnVal,RestChars}.
139 %% Must be careful when re-entering to append the latest characters to the
140 %% after characters in an accept.
141
142 tokens(Cont, Chars) -> tokens(Cont, Chars, 1).
143
144 tokens([], Chars, Line) ->
145 tokens(Chars, Line, yystate(), Chars, 0, [], reject, 0);
146 tokens({tokens,Line,State,Tcs,Clen,Ts,Action,Alen}, Chars, _) ->
147 tokens(Chars, Line, State, Tcs ++ Chars, Clen, Ts, Action, Alen);
148 tokens({skip_tokens,Line,State,Tcs,Clen,Error,Action,Alen}, Chars, _) ->
149 skip_tokens(Chars, Line, State, Tcs ++ Chars, Clen, Error, Action, Alen).
150
151 %% tokens(InChars, Line, State, TokenChars, CurrTokLen, Tokens,
152 %% AcceptAction, AcceptLen) ->
153 %% {more,Continuation} | {done,ReturnVal,RestChars}.
154
155 tokens(Ics0, L0, S0, Tcs, Clen0, Ts, A0, Alen0) ->
156 case yystate(S0, Ics0, L0, Clen0, A0, Alen0) of
157 {A1,Alen1,Ics1,L1} -> %Accepting end state
158 tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1), Ts);
159 {A1,Alen1,[],L1,S1} -> %After an accepting state
160 {more,{tokens,L1,S1,Tcs,Alen1,Ts,A1,Alen1}};
161 {A1,Alen1,Ics1,L1,_S1} ->
162 tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1), Ts);
163 {A1,Alen1,Clen1,[],L1,S1} -> %After a non-accepting state
164 {more,{tokens,L1,S1,Tcs,Clen1,Ts,A1,Alen1}};
165 {reject,_Alen1,_Clen1,eof,L1,_S1} ->
166 {done,if Ts == [] -> {eof,L1};
167 true -> {ok,yyrev(Ts),L1} end,[]};
168 {reject,_Alen1,Clen1,_Ics1,L1,_S1} ->
169 %% Skip rest of tokens.
170 skip_tokens(yysuf(Tcs, Clen1+1), L1,
171 {L1,?MODULE,{illegal,yypre(Tcs, Clen1+1)}});
172 {A1,Alen1,_Clen1,_Ics1,L1,_S1} ->
173 tokens_cont(yysuf(Tcs, Alen1), L1, yyaction(A1, Alen1, Tcs, L1), Ts)
174 end.
175
176 %% tokens_cont(RestChars, Line, Token, Tokens)
177 %% If we have a end_token or error then return done, else if we have
178 %% a token then save it and continue, else if we have a skip_token
179 %% just continue.
180
181 tokens_cont(Rest, Line, {token,T}, Ts) ->
182 tokens(Rest, Line, yystate(), Rest, 0, [T|Ts], reject, 0);
183 tokens_cont(Rest, Line, {end_token,T}, Ts) ->
184 {done,{ok,yyrev(Ts, [T]),Line},Rest};
185 tokens_cont(Rest, Line, skip_token, Ts) ->
186 tokens(Rest, Line, yystate(), Rest, 0, Ts, reject, 0);
187 tokens_cont(Rest, Line, {error,S}, _Ts) ->
188 skip_tokens(Rest, Line, {Line,?MODULE,{user,S}}).
189
190 %%skip_tokens(InChars, Line, Error) -> {done,{error,Error,Line},Ics}.
191 %% Skip tokens until an end token, junk everything and return the error.
192
193 skip_tokens(Ics, Line, Error) ->
194 skip_tokens(Ics, Line, yystate(), Ics, 0, Error, reject, 0).
195
196 %% skip_tokens(InChars, Line, State, TokenChars, CurrTokLen, Tokens,
197 %% AcceptAction, AcceptLen) ->
198 %% {more,Continuation} | {done,ReturnVal,RestChars}.
199
200 skip_tokens(Ics0, L0, S0, Tcs, Clen0, Error, A0, Alen0) ->
201 case yystate(S0, Ics0, L0, Clen0, A0, Alen0) of
202 {A1,Alen1,Ics1,L1} -> %Accepting end state
203 skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1), Error);
204 {A1,Alen1,[],L1,S1} -> %After an accepting state
205 {more,{skip_tokens,L1,S1,Tcs,Alen1,Error,A1,Alen1}};
206 {A1,Alen1,Ics1,L1,_S1} ->
207 skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, L1), Error);
208 {A1,Alen1,Clen1,[],L1,S1} -> %After a non-accepting state
209 {more,{skip_tokens,L1,S1,Tcs,Clen1,Error,A1,Alen1}};
210 {reject,_Alen1,_Clen1,eof,L1,_S1} ->
211 {done,{error,Error,L1},[]};
212 {reject,_Alen1,Clen1,_Ics1,L1,_S1} ->
213 skip_tokens(yysuf(Tcs, Clen1+1), L1, Error);
214 {A1,Alen1,_Clen1,_Ics1,L1,_S1} ->
215 skip_cont(yysuf(Tcs, Alen1), L1, yyaction(A1, Alen1, Tcs, L1), Error)
216 end.
217
218 %% skip_cont(RestChars, Line, Token, Error)
219 %% Skip tokens until we have an end_token or error then return done
220 %% with the original rror.
221
222 skip_cont(Rest, Line, {token,_T}, Error) ->
223 skip_tokens(Rest, Line, yystate(), Rest, 0, Error, reject, 0);
224 skip_cont(Rest, Line, {end_token,_T}, Error) ->
225 {done,{error,Error,Line},Rest};
226 skip_cont(Rest, Line, {error,_S}, Error) ->
227 skip_tokens(Rest, Line, yystate(), Rest, 0, Error, reject, 0);
228 skip_cont(Rest, Line, skip_token, Error) ->
229 skip_tokens(Rest, Line, yystate(), Rest, 0, Error, reject, 0).
230
231 yyrev(List) -> lists:reverse(List).
232 yyrev(List, Tail) -> lists:reverse(List, Tail).
233 yypre(List, N) -> lists:sublist(List, N).
234 yysuf(List, N) -> lists:nthtail(N, List).
235
236 %% yystate() -> InitialState.
237 %% yystate(State, InChars, Line, CurrTokLen, AcceptAction, AcceptLen) ->
238 %% {Action, AcceptLen, RestChars, Line} |
239 %% {Action, AcceptLen, RestChars, Line, State} |
240 %% {reject, AcceptLen, CurrTokLen, RestChars, Line, State} |
241 %% {Action, AcceptLen, CurrTokLen, RestChars, Line, State}.
242 %% Generated state transition functions. The non-accepting end state
243 %% return signal either an unrecognised character or end of current
244 %% input.
245
5e1c937 parser for eep
Chris Anderson authored
246 yystate() -> 32.
955caa8 initial barely working json parser
Chris Anderson authored
247
5e1c937 parser for eep
Chris Anderson authored
248 yystate(35, [C|Ics], Line, Tlen, _, _) when C >= $0, C =< $9 ->
249 yystate(35, Ics, Line, Tlen+1, 5, Tlen);
250 yystate(35, Ics, Line, Tlen, _, _) ->
251 {5,Tlen,Ics,Line,35};
252 yystate(34, Ics, Line, Tlen, _, _) ->
955caa8 initial barely working json parser
Chris Anderson authored
253 {1,Tlen,Ics,Line};
5e1c937 parser for eep
Chris Anderson authored
254 yystate(33, Ics, Line, Tlen, _, _) ->
255 {11,Tlen,Ics,Line};
256 yystate(32, [$\n|Ics], Line, Tlen, Action, Alen) ->
257 yystate(28, Ics, Line+1, Tlen+1, Action, Alen);
258 yystate(32, [$"|Ics], Line, Tlen, Action, Alen) ->
259 yystate(24, Ics, Line, Tlen+1, Action, Alen);
260 yystate(32, [$%|Ics], Line, Tlen, Action, Alen) ->
261 yystate(8, Ics, Line, Tlen+1, Action, Alen);
262 yystate(32, [$,|Ics], Line, Tlen, Action, Alen) ->
263 yystate(4, Ics, Line, Tlen+1, Action, Alen);
264 yystate(32, [$-|Ics], Line, Tlen, Action, Alen) ->
955caa8 initial barely working json parser
Chris Anderson authored
265 yystate(0, Ics, Line, Tlen+1, Action, Alen);
5e1c937 parser for eep
Chris Anderson authored
266 yystate(32, [$:|Ics], Line, Tlen, Action, Alen) ->
267 yystate(33, Ics, Line, Tlen+1, Action, Alen);
268 yystate(32, [$[|Ics], Line, Tlen, Action, Alen) ->
269 yystate(29, Ics, Line, Tlen+1, Action, Alen);
270 yystate(32, [$]|Ics], Line, Tlen, Action, Alen) ->
271 yystate(25, Ics, Line, Tlen+1, Action, Alen);
272 yystate(32, [$f|Ics], Line, Tlen, Action, Alen) ->
273 yystate(21, Ics, Line, Tlen+1, Action, Alen);
274 yystate(32, [$n|Ics], Line, Tlen, Action, Alen) ->
275 yystate(1, Ics, Line, Tlen+1, Action, Alen);
276 yystate(32, [$t|Ics], Line, Tlen, Action, Alen) ->
277 yystate(14, Ics, Line, Tlen+1, Action, Alen);
278 yystate(32, [${|Ics], Line, Tlen, Action, Alen) ->
955caa8 initial barely working json parser
Chris Anderson authored
279 yystate(30, Ics, Line, Tlen+1, Action, Alen);
5e1c937 parser for eep
Chris Anderson authored
280 yystate(32, [$}|Ics], Line, Tlen, Action, Alen) ->
281 yystate(34, Ics, Line, Tlen+1, Action, Alen);
282 yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= $\000, C =< $\t ->
283 yystate(28, Ics, Line, Tlen+1, Action, Alen);
284 yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= $\v, C =< $\s ->
285 yystate(28, Ics, Line, Tlen+1, Action, Alen);
286 yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
287 yystate(3, Ics, Line, Tlen+1, Action, Alen);
288 yystate(32, Ics, Line, Tlen, Action, Alen) ->
289 {Action,Alen,Tlen,Ics,Line,32};
955caa8 initial barely working json parser
Chris Anderson authored
290 yystate(31, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
5e1c937 parser for eep
Chris Anderson authored
291 yystate(35, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
292 yystate(31, Ics, Line, Tlen, Action, Alen) ->
293 {Action,Alen,Tlen,Ics,Line,31};
294 yystate(30, Ics, Line, Tlen, _, _) ->
5e1c937 parser for eep
Chris Anderson authored
295 {0,Tlen,Ics,Line};
296 yystate(29, Ics, Line, Tlen, _, _) ->
297 {2,Tlen,Ics,Line};
298 yystate(28, [$\n|Ics], Line, Tlen, _, _) ->
299 yystate(28, Ics, Line+1, Tlen+1, 13, Tlen);
300 yystate(28, [$%|Ics], Line, Tlen, _, _) ->
301 yystate(8, Ics, Line, Tlen+1, 13, Tlen);
302 yystate(28, [C|Ics], Line, Tlen, _, _) when C >= $\000, C =< $\t ->
303 yystate(28, Ics, Line, Tlen+1, 13, Tlen);
304 yystate(28, [C|Ics], Line, Tlen, _, _) when C >= $\v, C =< $\s ->
305 yystate(28, Ics, Line, Tlen+1, 13, Tlen);
955caa8 initial barely working json parser
Chris Anderson authored
306 yystate(28, Ics, Line, Tlen, _, _) ->
5e1c937 parser for eep
Chris Anderson authored
307 {13,Tlen,Ics,Line,28};
308 yystate(27, [$+|Ics], Line, Tlen, Action, Alen) ->
309 yystate(31, Ics, Line, Tlen+1, Action, Alen);
310 yystate(27, [$-|Ics], Line, Tlen, Action, Alen) ->
311 yystate(31, Ics, Line, Tlen+1, Action, Alen);
312 yystate(27, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
313 yystate(35, Ics, Line, Tlen+1, Action, Alen);
314 yystate(27, Ics, Line, Tlen, Action, Alen) ->
315 {Action,Alen,Tlen,Ics,Line,27};
316 yystate(26, Ics, Line, Tlen, _, _) ->
955caa8 initial barely working json parser
Chris Anderson authored
317 {8,Tlen,Ics,Line};
318 yystate(25, Ics, Line, Tlen, _, _) ->
5e1c937 parser for eep
Chris Anderson authored
319 {3,Tlen,Ics,Line};
320 yystate(24, [$\n|Ics], Line, Tlen, Action, Alen) ->
321 yystate(24, Ics, Line+1, Tlen+1, Action, Alen);
322 yystate(24, [$"|Ics], Line, Tlen, Action, Alen) ->
323 yystate(20, Ics, Line, Tlen+1, Action, Alen);
324 yystate(24, [$\\|Ics], Line, Tlen, Action, Alen) ->
325 yystate(16, Ics, Line, Tlen+1, Action, Alen);
326 yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= $\000, C =< $\t ->
327 yystate(24, Ics, Line, Tlen+1, Action, Alen);
328 yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= $\v, C =< $! ->
329 yystate(24, Ics, Line, Tlen+1, Action, Alen);
330 yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= $#, C =< $[ ->
331 yystate(24, Ics, Line, Tlen+1, Action, Alen);
332 yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= $], C =< $ÿ ->
333 yystate(24, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
334 yystate(24, Ics, Line, Tlen, Action, Alen) ->
335 {Action,Alen,Tlen,Ics,Line,24};
5e1c937 parser for eep
Chris Anderson authored
336 yystate(23, [C|Ics], Line, Tlen, _, _) when C >= $0, C =< $9 ->
337 yystate(23, Ics, Line, Tlen+1, 4, Tlen);
955caa8 initial barely working json parser
Chris Anderson authored
338 yystate(23, Ics, Line, Tlen, _, _) ->
5e1c937 parser for eep
Chris Anderson authored
339 {4,Tlen,Ics,Line,23};
340 yystate(22, [$e|Ics], Line, Tlen, Action, Alen) ->
341 yystate(26, Ics, Line, Tlen+1, Action, Alen);
342 yystate(22, Ics, Line, Tlen, Action, Alen) ->
343 {Action,Alen,Tlen,Ics,Line,22};
344 yystate(21, [$a|Ics], Line, Tlen, Action, Alen) ->
345 yystate(17, Ics, Line, Tlen+1, Action, Alen);
346 yystate(21, Ics, Line, Tlen, Action, Alen) ->
347 {Action,Alen,Tlen,Ics,Line,21};
348 yystate(20, Ics, Line, Tlen, _, _) ->
349 {7,Tlen,Ics,Line};
350 yystate(19, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
351 yystate(23, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
352 yystate(19, Ics, Line, Tlen, Action, Alen) ->
353 {Action,Alen,Tlen,Ics,Line,19};
5e1c937 parser for eep
Chris Anderson authored
354 yystate(18, [$u|Ics], Line, Tlen, Action, Alen) ->
355 yystate(22, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
356 yystate(18, Ics, Line, Tlen, Action, Alen) ->
357 {Action,Alen,Tlen,Ics,Line,18};
5e1c937 parser for eep
Chris Anderson authored
358 yystate(17, [$l|Ics], Line, Tlen, Action, Alen) ->
359 yystate(13, Ics, Line, Tlen+1, Action, Alen);
360 yystate(17, Ics, Line, Tlen, Action, Alen) ->
361 {Action,Alen,Tlen,Ics,Line,17};
362 yystate(16, [C|Ics], Line, Tlen, Action, Alen) when C >= $\000, C =< $\t ->
363 yystate(12, Ics, Line, Tlen+1, Action, Alen);
364 yystate(16, [C|Ics], Line, Tlen, Action, Alen) when C >= $\v, C =< $ÿ ->
365 yystate(12, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
366 yystate(16, Ics, Line, Tlen, Action, Alen) ->
367 {Action,Alen,Tlen,Ics,Line,16};
5e1c937 parser for eep
Chris Anderson authored
368 yystate(15, [$+|Ics], Line, Tlen, Action, Alen) ->
369 yystate(19, Ics, Line, Tlen+1, Action, Alen);
370 yystate(15, [$-|Ics], Line, Tlen, Action, Alen) ->
371 yystate(19, Ics, Line, Tlen+1, Action, Alen);
372 yystate(15, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
373 yystate(23, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
374 yystate(15, Ics, Line, Tlen, Action, Alen) ->
375 {Action,Alen,Tlen,Ics,Line,15};
5e1c937 parser for eep
Chris Anderson authored
376 yystate(14, [$r|Ics], Line, Tlen, Action, Alen) ->
955caa8 initial barely working json parser
Chris Anderson authored
377 yystate(18, Ics, Line, Tlen+1, Action, Alen);
378 yystate(14, Ics, Line, Tlen, Action, Alen) ->
379 {Action,Alen,Tlen,Ics,Line,14};
5e1c937 parser for eep
Chris Anderson authored
380 yystate(13, [$s|Ics], Line, Tlen, Action, Alen) ->
381 yystate(9, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
382 yystate(13, Ics, Line, Tlen, Action, Alen) ->
383 {Action,Alen,Tlen,Ics,Line,13};
5e1c937 parser for eep
Chris Anderson authored
384 yystate(12, [$\n|Ics], Line, Tlen, Action, Alen) ->
385 yystate(12, Ics, Line+1, Tlen+1, Action, Alen);
386 yystate(12, [$"|Ics], Line, Tlen, Action, Alen) ->
387 yystate(20, Ics, Line, Tlen+1, Action, Alen);
388 yystate(12, [$\\|Ics], Line, Tlen, Action, Alen) ->
389 yystate(16, Ics, Line, Tlen+1, Action, Alen);
390 yystate(12, [C|Ics], Line, Tlen, Action, Alen) when C >= $\000, C =< $\t ->
391 yystate(12, Ics, Line, Tlen+1, Action, Alen);
392 yystate(12, [C|Ics], Line, Tlen, Action, Alen) when C >= $\v, C =< $! ->
393 yystate(12, Ics, Line, Tlen+1, Action, Alen);
394 yystate(12, [C|Ics], Line, Tlen, Action, Alen) when C >= $#, C =< $[ ->
395 yystate(12, Ics, Line, Tlen+1, Action, Alen);
396 yystate(12, [C|Ics], Line, Tlen, Action, Alen) when C >= $], C =< $ÿ ->
397 yystate(12, Ics, Line, Tlen+1, Action, Alen);
398 yystate(12, Ics, Line, Tlen, Action, Alen) ->
399 {Action,Alen,Tlen,Ics,Line,12};
400 yystate(11, [$E|Ics], Line, Tlen, _, _) ->
401 yystate(15, Ics, Line, Tlen+1, 4, Tlen);
402 yystate(11, [$e|Ics], Line, Tlen, _, _) ->
403 yystate(15, Ics, Line, Tlen+1, 4, Tlen);
404 yystate(11, [C|Ics], Line, Tlen, _, _) when C >= $0, C =< $9 ->
405 yystate(11, Ics, Line, Tlen+1, 4, Tlen);
406 yystate(11, Ics, Line, Tlen, _, _) ->
407 {4,Tlen,Ics,Line,11};
955caa8 initial barely working json parser
Chris Anderson authored
408 yystate(10, Ics, Line, Tlen, _, _) ->
5e1c937 parser for eep
Chris Anderson authored
409 {10,Tlen,Ics,Line};
410 yystate(9, [$e|Ics], Line, Tlen, Action, Alen) ->
411 yystate(5, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
412 yystate(9, Ics, Line, Tlen, Action, Alen) ->
413 {Action,Alen,Tlen,Ics,Line,9};
5e1c937 parser for eep
Chris Anderson authored
414 yystate(8, [$\n|Ics], Line, Tlen, _, _) ->
415 yystate(28, Ics, Line+1, Tlen+1, 13, Tlen);
416 yystate(8, [C|Ics], Line, Tlen, _, _) when C >= $\000, C =< $\t ->
417 yystate(8, Ics, Line, Tlen+1, 13, Tlen);
418 yystate(8, [C|Ics], Line, Tlen, _, _) when C >= $\v, C =< $ÿ ->
419 yystate(8, Ics, Line, Tlen+1, 13, Tlen);
420 yystate(8, Ics, Line, Tlen, _, _) ->
421 {13,Tlen,Ics,Line,8};
422 yystate(7, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
423 yystate(11, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
424 yystate(7, Ics, Line, Tlen, Action, Alen) ->
425 {Action,Alen,Tlen,Ics,Line,7};
5e1c937 parser for eep
Chris Anderson authored
426 yystate(6, [$l|Ics], Line, Tlen, Action, Alen) ->
427 yystate(10, Ics, Line, Tlen+1, Action, Alen);
428 yystate(6, Ics, Line, Tlen, Action, Alen) ->
429 {Action,Alen,Tlen,Ics,Line,6};
955caa8 initial barely working json parser
Chris Anderson authored
430 yystate(5, Ics, Line, Tlen, _, _) ->
431 {9,Tlen,Ics,Line};
5e1c937 parser for eep
Chris Anderson authored
432 yystate(4, Ics, Line, Tlen, _, _) ->
433 {12,Tlen,Ics,Line};
434 yystate(3, [$.|Ics], Line, Tlen, _, _) ->
435 yystate(7, Ics, Line, Tlen+1, 6, Tlen);
436 yystate(3, [$E|Ics], Line, Tlen, _, _) ->
437 yystate(27, Ics, Line, Tlen+1, 6, Tlen);
438 yystate(3, [$e|Ics], Line, Tlen, _, _) ->
439 yystate(27, Ics, Line, Tlen+1, 6, Tlen);
440 yystate(3, [C|Ics], Line, Tlen, _, _) when C >= $0, C =< $9 ->
441 yystate(3, Ics, Line, Tlen+1, 6, Tlen);
442 yystate(3, Ics, Line, Tlen, _, _) ->
443 {6,Tlen,Ics,Line,3};
444 yystate(2, [$l|Ics], Line, Tlen, Action, Alen) ->
445 yystate(6, Ics, Line, Tlen+1, Action, Alen);
446 yystate(2, Ics, Line, Tlen, Action, Alen) ->
447 {Action,Alen,Tlen,Ics,Line,2};
448 yystate(1, [$u|Ics], Line, Tlen, Action, Alen) ->
449 yystate(2, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
450 yystate(1, Ics, Line, Tlen, Action, Alen) ->
451 {Action,Alen,Tlen,Ics,Line,1};
5e1c937 parser for eep
Chris Anderson authored
452 yystate(0, [C|Ics], Line, Tlen, Action, Alen) when C >= $0, C =< $9 ->
453 yystate(3, Ics, Line, Tlen+1, Action, Alen);
955caa8 initial barely working json parser
Chris Anderson authored
454 yystate(0, Ics, Line, Tlen, Action, Alen) ->
455 {Action,Alen,Tlen,Ics,Line,0};
456 yystate(S, Ics, Line, Tlen, Action, Alen) ->
457 {Action,Alen,Tlen,Ics,Line,S}.
458
459 %% yyaction(Action, TokenLength, TokenChars, TokenLine) ->
460 %% {token,Token} | {end_token, Token} | skip_token | {error,String}.
461 %% Generated action function.
462
463 yyaction(0, _, _, TokenLine) ->
464 {token,{'{',TokenLine}};
465 yyaction(1, _, _, TokenLine) ->
466 {token,{'}',TokenLine}};
467 yyaction(2, _, _, TokenLine) ->
468 {token,{'[',TokenLine}};
469 yyaction(3, _, _, TokenLine) ->
470 {token,{']',TokenLine}};
471 yyaction(4, TokenLen, YYtcs, TokenLine) ->
472 TokenChars = yypre(YYtcs, TokenLen),
473 {token,{float,TokenLine,list_to_float(TokenChars)}};
474 yyaction(5, TokenLen, YYtcs, TokenLine) ->
475 TokenChars = yypre(YYtcs, TokenLen),
5e1c937 parser for eep
Chris Anderson authored
476 {token,{float,TokenLine,whole_float(TokenChars)}};
955caa8 initial barely working json parser
Chris Anderson authored
477 yyaction(6, TokenLen, YYtcs, TokenLine) ->
478 TokenChars = yypre(YYtcs, TokenLen),
5e1c937 parser for eep
Chris Anderson authored
479 {token,{integer,TokenLine,list_to_integer(TokenChars)}};
955caa8 initial barely working json parser
Chris Anderson authored
480 yyaction(7, TokenLen, YYtcs, TokenLine) ->
481 TokenChars = yypre(YYtcs, TokenLen),
5e1c937 parser for eep
Chris Anderson authored
482 {token,{string,TokenLine,parse_string(strip(TokenChars, TokenLen))}};
955caa8 initial barely working json parser
Chris Anderson authored
483 yyaction(8, _, _, TokenLine) ->
484 {token,{true,TokenLine}};
485 yyaction(9, _, _, TokenLine) ->
486 {token,{false,TokenLine}};
487 yyaction(10, _, _, TokenLine) ->
488 {token,{null,TokenLine}};
489 yyaction(11, _, _, TokenLine) ->
490 {token,{':',TokenLine}};
491 yyaction(12, _, _, TokenLine) ->
492 {token,{',',TokenLine}};
493 yyaction(13, _, _, _) ->
494 skip_token;
495 yyaction(_, _, _, _) -> error.
Something went wrong with that request. Please try again.