yaji 0.2.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ /*
2
+ * Copyright 2010, Lloyd Hilaiel.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are
6
+ * met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
+ * contributors may be used to endorse or promote products derived
18
+ * from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ #ifndef __YAJL_LEX_H__
34
+ #define __YAJL_LEX_H__
35
+
36
+ #include "api/yajl_common.h"
37
+
38
+ typedef enum {
39
+ yajl_tok_bool,
40
+ yajl_tok_colon,
41
+ yajl_tok_comma,
42
+ yajl_tok_eof,
43
+ yajl_tok_error,
44
+ yajl_tok_left_brace,
45
+ yajl_tok_left_bracket,
46
+ yajl_tok_null,
47
+ yajl_tok_right_brace,
48
+ yajl_tok_right_bracket,
49
+
50
+ /* we differentiate between integers and doubles to allow the
51
+ * parser to interpret the number without re-scanning */
52
+ yajl_tok_integer,
53
+ yajl_tok_double,
54
+
55
+ /* we differentiate between strings which require further processing,
56
+ * and strings that do not */
57
+ yajl_tok_string,
58
+ yajl_tok_string_with_escapes,
59
+
60
+ /* comment tokens are not currently returned to the parser, ever */
61
+ yajl_tok_comment
62
+ } yajl_tok;
63
+
64
+ typedef struct yajl_lexer_t * yajl_lexer;
65
+
66
+ YAJL_API
67
+ yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc,
68
+ unsigned int allowComments,
69
+ unsigned int validateUTF8);
70
+
71
+ YAJL_API
72
+ void yajl_lex_free(yajl_lexer lexer);
73
+
74
+ /**
75
+ * run/continue a lex. "offset" is an input/output parameter.
76
+ * It should be initialized to zero for a
77
+ * new chunk of target text, and upon subsetquent calls with the same
78
+ * target text should passed with the value of the previous invocation.
79
+ *
80
+ * the client may be interested in the value of offset when an error is
81
+ * returned from the lexer. This allows the client to render useful
82
+ n * error messages.
83
+ *
84
+ * When you pass the next chunk of data, context should be reinitialized
85
+ * to zero.
86
+ *
87
+ * Finally, the output buffer is usually just a pointer into the jsonText,
88
+ * however in cases where the entity being lexed spans multiple chunks,
89
+ * the lexer will buffer the entity and the data returned will be
90
+ * a pointer into that buffer.
91
+ *
92
+ * This behavior is abstracted from client code except for the performance
93
+ * implications which require that the client choose a reasonable chunk
94
+ * size to get adequate performance.
95
+ */
96
+ YAJL_API
97
+ yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
98
+ unsigned int jsonTextLen, unsigned int * offset,
99
+ const unsigned char ** outBuf, unsigned int * outLen);
100
+
101
+ /** have a peek at the next token, but don't move the lexer forward */
102
+ YAJL_API
103
+ yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
104
+ unsigned int jsonTextLen, unsigned int offset);
105
+
106
+
107
+ typedef enum {
108
+ yajl_lex_e_ok = 0,
109
+ yajl_lex_string_invalid_utf8,
110
+ yajl_lex_string_invalid_escaped_char,
111
+ yajl_lex_string_invalid_json_char,
112
+ yajl_lex_string_invalid_hex_char,
113
+ yajl_lex_invalid_char,
114
+ yajl_lex_invalid_string,
115
+ yajl_lex_missing_integer_after_decimal,
116
+ yajl_lex_missing_integer_after_exponent,
117
+ yajl_lex_missing_integer_after_minus,
118
+ yajl_lex_unallowed_comment
119
+ } yajl_lex_error;
120
+
121
+ YAJL_API
122
+ const char * yajl_lex_error_to_string(yajl_lex_error error);
123
+
124
+ /** allows access to more specific information about the lexical
125
+ * error when yajl_lex_lex returns yajl_tok_error. */
126
+ YAJL_API
127
+ yajl_lex_error yajl_lex_get_error(yajl_lexer lexer);
128
+
129
+ /** get the current offset into the most recently lexed json string. */
130
+ YAJL_API
131
+ unsigned int yajl_lex_current_offset(yajl_lexer lexer);
132
+
133
+ /** get the number of lines lexed by this lexer instance */
134
+ YAJL_API
135
+ unsigned int yajl_lex_current_line(yajl_lexer lexer);
136
+
137
+ /** get the number of chars lexed by this lexer instance since the last
138
+ * \n or \r */
139
+ YAJL_API
140
+ unsigned int yajl_lex_current_char(yajl_lexer lexer);
141
+
142
+ #endif
@@ -0,0 +1,448 @@
1
+ /*
2
+ * Copyright 2010, Lloyd Hilaiel.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are
6
+ * met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
+ * contributors may be used to endorse or promote products derived
18
+ * from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ #include "yajl_lex.h"
34
+ #include "yajl_parser.h"
35
+ #include "yajl_encode.h"
36
+ #include "yajl_bytestack.h"
37
+
38
+ #include <stdlib.h>
39
+ #include <limits.h>
40
+ #include <errno.h>
41
+ #include <stdio.h>
42
+ #include <string.h>
43
+ #include <ctype.h>
44
+ #include <assert.h>
45
+ #include <math.h>
46
+
47
+ unsigned char *
48
+ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
49
+ unsigned int jsonTextLen, int verbose)
50
+ {
51
+ unsigned int offset = hand->bytesConsumed;
52
+ unsigned char * str;
53
+ const char * errorType = NULL;
54
+ const char * errorText = NULL;
55
+ char text[72];
56
+ const char * arrow = " (right here) ------^\n";
57
+
58
+ if (yajl_bs_current(hand->stateStack) == yajl_state_parse_error) {
59
+ errorType = "parse";
60
+ errorText = hand->parseError;
61
+ } else if (yajl_bs_current(hand->stateStack) == yajl_state_lexical_error) {
62
+ errorType = "lexical";
63
+ errorText = yajl_lex_error_to_string(yajl_lex_get_error(hand->lexer));
64
+ } else {
65
+ errorType = "unknown";
66
+ }
67
+
68
+ {
69
+ unsigned int memneeded = 0;
70
+ memneeded += strlen(errorType);
71
+ memneeded += strlen(" error");
72
+ if (errorText != NULL) {
73
+ memneeded += strlen(": ");
74
+ memneeded += strlen(errorText);
75
+ }
76
+ str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2);
77
+ str[0] = 0;
78
+ strcat((char *) str, errorType);
79
+ strcat((char *) str, " error");
80
+ if (errorText != NULL) {
81
+ strcat((char *) str, ": ");
82
+ strcat((char *) str, errorText);
83
+ }
84
+ strcat((char *) str, "\n");
85
+ }
86
+
87
+ /* now we append as many spaces as needed to make sure the error
88
+ * falls at char 41, if verbose was specified */
89
+ if (verbose) {
90
+ unsigned int start, end, i;
91
+ unsigned int spacesNeeded;
92
+
93
+ spacesNeeded = (offset < 30 ? 40 - offset : 10);
94
+ start = (offset >= 30 ? offset - 30 : 0);
95
+ end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
96
+
97
+ for (i=0;i<spacesNeeded;i++) text[i] = ' ';
98
+
99
+ for (;start < end;start++, i++) {
100
+ if (jsonText[start] != '\n' && jsonText[start] != '\r')
101
+ {
102
+ text[i] = jsonText[start];
103
+ }
104
+ else
105
+ {
106
+ text[i] = ' ';
107
+ }
108
+ }
109
+ assert(i <= 71);
110
+ text[i++] = '\n';
111
+ text[i] = 0;
112
+ {
113
+ char * newStr = (char *)
114
+ YA_MALLOC(&(hand->alloc), (unsigned int)(strlen((char *) str) +
115
+ strlen((char *) text) +
116
+ strlen(arrow) + 1));
117
+ newStr[0] = 0;
118
+ strcat((char *) newStr, (char *) str);
119
+ strcat((char *) newStr, text);
120
+ strcat((char *) newStr, arrow);
121
+ YA_FREE(&(hand->alloc), str);
122
+ str = (unsigned char *) newStr;
123
+ }
124
+ }
125
+ return str;
126
+ }
127
+
128
+ /* check for client cancelation */
129
+ #define _CC_CHK(x) \
130
+ if (!(x)) { \
131
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error); \
132
+ hand->parseError = \
133
+ "client cancelled parse via callback return value"; \
134
+ return yajl_status_client_canceled; \
135
+ }
136
+
137
+
138
+ yajl_status
139
+ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
140
+ unsigned int jsonTextLen)
141
+ {
142
+ yajl_tok tok;
143
+ const unsigned char * buf;
144
+ unsigned int bufLen;
145
+ unsigned int * offset = &(hand->bytesConsumed);
146
+
147
+ *offset = 0;
148
+
149
+
150
+ around_again:
151
+ switch (yajl_bs_current(hand->stateStack)) {
152
+ case yajl_state_parse_complete:
153
+ return yajl_status_ok;
154
+ case yajl_state_lexical_error:
155
+ case yajl_state_parse_error:
156
+ return yajl_status_error;
157
+ case yajl_state_start:
158
+ case yajl_state_map_need_val:
159
+ case yajl_state_array_need_val:
160
+ case yajl_state_array_start: {
161
+ /* for arrays and maps, we advance the state for this
162
+ * depth, then push the state of the next depth.
163
+ * If an error occurs during the parsing of the nesting
164
+ * enitity, the state at this level will not matter.
165
+ * a state that needs pushing will be anything other
166
+ * than state_start */
167
+ yajl_state stateToPush = yajl_state_start;
168
+
169
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
170
+ offset, &buf, &bufLen);
171
+
172
+ switch (tok) {
173
+ case yajl_tok_eof:
174
+ return yajl_status_insufficient_data;
175
+ case yajl_tok_error:
176
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
177
+ goto around_again;
178
+ case yajl_tok_string:
179
+ if (hand->callbacks && hand->callbacks->yajl_string) {
180
+ _CC_CHK(hand->callbacks->yajl_string(hand->ctx,
181
+ buf, bufLen));
182
+ }
183
+ break;
184
+ case yajl_tok_string_with_escapes:
185
+ if (hand->callbacks && hand->callbacks->yajl_string) {
186
+ yajl_buf_clear(hand->decodeBuf);
187
+ yajl_string_decode(hand->decodeBuf, buf, bufLen);
188
+ _CC_CHK(hand->callbacks->yajl_string(
189
+ hand->ctx, yajl_buf_data(hand->decodeBuf),
190
+ yajl_buf_len(hand->decodeBuf)));
191
+ }
192
+ break;
193
+ case yajl_tok_bool:
194
+ if (hand->callbacks && hand->callbacks->yajl_boolean) {
195
+ _CC_CHK(hand->callbacks->yajl_boolean(hand->ctx,
196
+ *buf == 't'));
197
+ }
198
+ break;
199
+ case yajl_tok_null:
200
+ if (hand->callbacks && hand->callbacks->yajl_null) {
201
+ _CC_CHK(hand->callbacks->yajl_null(hand->ctx));
202
+ }
203
+ break;
204
+ case yajl_tok_left_bracket:
205
+ if (hand->callbacks && hand->callbacks->yajl_start_map) {
206
+ _CC_CHK(hand->callbacks->yajl_start_map(hand->ctx));
207
+ }
208
+ stateToPush = yajl_state_map_start;
209
+ break;
210
+ case yajl_tok_left_brace:
211
+ if (hand->callbacks && hand->callbacks->yajl_start_array) {
212
+ _CC_CHK(hand->callbacks->yajl_start_array(hand->ctx));
213
+ }
214
+ stateToPush = yajl_state_array_start;
215
+ break;
216
+ case yajl_tok_integer:
217
+ /*
218
+ * note. strtol does not respect the length of
219
+ * the lexical token. in a corner case where the
220
+ * lexed number is a integer with a trailing zero,
221
+ * immediately followed by the end of buffer,
222
+ * sscanf could run off into oblivion and cause a
223
+ * crash. for this reason we copy the integer
224
+ * (and doubles), into our parse buffer (the same
225
+ * one used for unescaping strings), before
226
+ * calling strtol. yajl_buf ensures null padding,
227
+ * so we're safe.
228
+ */
229
+ if (hand->callbacks) {
230
+ if (hand->callbacks->yajl_number) {
231
+ _CC_CHK(hand->callbacks->yajl_number(
232
+ hand->ctx,(const char *) buf, bufLen));
233
+ } else if (hand->callbacks->yajl_integer) {
234
+ long int i = 0;
235
+ yajl_buf_clear(hand->decodeBuf);
236
+ yajl_buf_append(hand->decodeBuf, buf, bufLen);
237
+ buf = yajl_buf_data(hand->decodeBuf);
238
+ i = strtol((const char *) buf, NULL, 10);
239
+ if ((i == LONG_MIN || i == LONG_MAX) &&
240
+ errno == ERANGE)
241
+ {
242
+ yajl_bs_set(hand->stateStack,
243
+ yajl_state_parse_error);
244
+ hand->parseError = "integer overflow" ;
245
+ /* try to restore error offset */
246
+ if (*offset >= bufLen) *offset -= bufLen;
247
+ else *offset = 0;
248
+ goto around_again;
249
+ }
250
+ _CC_CHK(hand->callbacks->yajl_integer(hand->ctx,
251
+ i));
252
+ }
253
+ }
254
+ break;
255
+ case yajl_tok_double:
256
+ if (hand->callbacks) {
257
+ if (hand->callbacks->yajl_number) {
258
+ _CC_CHK(hand->callbacks->yajl_number(
259
+ hand->ctx, (const char *) buf, bufLen));
260
+ } else if (hand->callbacks->yajl_double) {
261
+ double d = 0.0;
262
+ yajl_buf_clear(hand->decodeBuf);
263
+ yajl_buf_append(hand->decodeBuf, buf, bufLen);
264
+ buf = yajl_buf_data(hand->decodeBuf);
265
+ d = strtod((char *) buf, NULL);
266
+ if ((d == HUGE_VAL || d == -HUGE_VAL) &&
267
+ errno == ERANGE)
268
+ {
269
+ yajl_bs_set(hand->stateStack,
270
+ yajl_state_parse_error);
271
+ hand->parseError = "numeric (floating point) "
272
+ "overflow";
273
+ /* try to restore error offset */
274
+ if (*offset >= bufLen) *offset -= bufLen;
275
+ else *offset = 0;
276
+ goto around_again;
277
+ }
278
+ _CC_CHK(hand->callbacks->yajl_double(hand->ctx,
279
+ d));
280
+ }
281
+ }
282
+ break;
283
+ case yajl_tok_right_brace: {
284
+ if (yajl_bs_current(hand->stateStack) ==
285
+ yajl_state_array_start)
286
+ {
287
+ if (hand->callbacks &&
288
+ hand->callbacks->yajl_end_array)
289
+ {
290
+ _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
291
+ }
292
+ yajl_bs_pop(hand->stateStack);
293
+ goto around_again;
294
+ }
295
+ /* intentional fall-through */
296
+ }
297
+ case yajl_tok_colon:
298
+ case yajl_tok_comma:
299
+ case yajl_tok_right_bracket:
300
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
301
+ hand->parseError =
302
+ "unallowed token at this point in JSON text";
303
+ goto around_again;
304
+ default:
305
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
306
+ hand->parseError = "invalid token, internal error";
307
+ goto around_again;
308
+ }
309
+ /* got a value. transition depends on the state we're in. */
310
+ {
311
+ yajl_state s = yajl_bs_current(hand->stateStack);
312
+ if (s == yajl_state_start) {
313
+ yajl_bs_set(hand->stateStack, yajl_state_parse_complete);
314
+ } else if (s == yajl_state_map_need_val) {
315
+ yajl_bs_set(hand->stateStack, yajl_state_map_got_val);
316
+ } else {
317
+ yajl_bs_set(hand->stateStack, yajl_state_array_got_val);
318
+ }
319
+ }
320
+ if (stateToPush != yajl_state_start) {
321
+ yajl_bs_push(hand->stateStack, stateToPush);
322
+ }
323
+
324
+ goto around_again;
325
+ }
326
+ case yajl_state_map_start:
327
+ case yajl_state_map_need_key: {
328
+ /* only difference between these two states is that in
329
+ * start '}' is valid, whereas in need_key, we've parsed
330
+ * a comma, and a string key _must_ follow */
331
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
332
+ offset, &buf, &bufLen);
333
+ switch (tok) {
334
+ case yajl_tok_eof:
335
+ return yajl_status_insufficient_data;
336
+ case yajl_tok_error:
337
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
338
+ goto around_again;
339
+ case yajl_tok_string_with_escapes:
340
+ if (hand->callbacks && hand->callbacks->yajl_map_key) {
341
+ yajl_buf_clear(hand->decodeBuf);
342
+ yajl_string_decode(hand->decodeBuf, buf, bufLen);
343
+ buf = yajl_buf_data(hand->decodeBuf);
344
+ bufLen = yajl_buf_len(hand->decodeBuf);
345
+ }
346
+ /* intentional fall-through */
347
+ case yajl_tok_string:
348
+ if (hand->callbacks && hand->callbacks->yajl_map_key) {
349
+ _CC_CHK(hand->callbacks->yajl_map_key(hand->ctx, buf,
350
+ bufLen));
351
+ }
352
+ yajl_bs_set(hand->stateStack, yajl_state_map_sep);
353
+ goto around_again;
354
+ case yajl_tok_right_bracket:
355
+ if (yajl_bs_current(hand->stateStack) ==
356
+ yajl_state_map_start)
357
+ {
358
+ if (hand->callbacks && hand->callbacks->yajl_end_map) {
359
+ _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
360
+ }
361
+ yajl_bs_pop(hand->stateStack);
362
+ goto around_again;
363
+ }
364
+ default:
365
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
366
+ hand->parseError =
367
+ "invalid object key (must be a string)";
368
+ goto around_again;
369
+ }
370
+ }
371
+ case yajl_state_map_sep: {
372
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
373
+ offset, &buf, &bufLen);
374
+ switch (tok) {
375
+ case yajl_tok_colon:
376
+ yajl_bs_set(hand->stateStack, yajl_state_map_need_val);
377
+ goto around_again;
378
+ case yajl_tok_eof:
379
+ return yajl_status_insufficient_data;
380
+ case yajl_tok_error:
381
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
382
+ goto around_again;
383
+ default:
384
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
385
+ hand->parseError = "object key and value must "
386
+ "be separated by a colon (':')";
387
+ goto around_again;
388
+ }
389
+ }
390
+ case yajl_state_map_got_val: {
391
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
392
+ offset, &buf, &bufLen);
393
+ switch (tok) {
394
+ case yajl_tok_right_bracket:
395
+ if (hand->callbacks && hand->callbacks->yajl_end_map) {
396
+ _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
397
+ }
398
+ yajl_bs_pop(hand->stateStack);
399
+ goto around_again;
400
+ case yajl_tok_comma:
401
+ yajl_bs_set(hand->stateStack, yajl_state_map_need_key);
402
+ goto around_again;
403
+ case yajl_tok_eof:
404
+ return yajl_status_insufficient_data;
405
+ case yajl_tok_error:
406
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
407
+ goto around_again;
408
+ default:
409
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
410
+ hand->parseError = "after key and value, inside map, "
411
+ "I expect ',' or '}'";
412
+ /* try to restore error offset */
413
+ if (*offset >= bufLen) *offset -= bufLen;
414
+ else *offset = 0;
415
+ goto around_again;
416
+ }
417
+ }
418
+ case yajl_state_array_got_val: {
419
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
420
+ offset, &buf, &bufLen);
421
+ switch (tok) {
422
+ case yajl_tok_right_brace:
423
+ if (hand->callbacks && hand->callbacks->yajl_end_array) {
424
+ _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
425
+ }
426
+ yajl_bs_pop(hand->stateStack);
427
+ goto around_again;
428
+ case yajl_tok_comma:
429
+ yajl_bs_set(hand->stateStack, yajl_state_array_need_val);
430
+ goto around_again;
431
+ case yajl_tok_eof:
432
+ return yajl_status_insufficient_data;
433
+ case yajl_tok_error:
434
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
435
+ goto around_again;
436
+ default:
437
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
438
+ hand->parseError =
439
+ "after array element, I expect ',' or ']'";
440
+ goto around_again;
441
+ }
442
+ }
443
+ }
444
+
445
+ abort();
446
+ return yajl_status_error;
447
+ }
448
+