Ruby  1.9.3p448(2013-06-27revision41675)
parser.c
Go to the documentation of this file.
1 
2 #line 1 "parser.rl"
3 #include "parser.h"
4 
5 /* unicode */
6 
7 static const char digit_values[256] = {
8  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
10  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
11  -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
12  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
13  10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
14  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
15  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
16  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
17  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
18  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
19  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
20  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
21  -1, -1, -1, -1, -1, -1, -1
22 };
23 
24 static UTF32 unescape_unicode(const unsigned char *p)
25 {
26  char b;
27  UTF32 result = 0;
28  b = digit_values[p[0]];
29  if (b < 0) return UNI_REPLACEMENT_CHAR;
30  result = (result << 4) | b;
31  b = digit_values[p[1]];
32  result = (result << 4) | b;
33  if (b < 0) return UNI_REPLACEMENT_CHAR;
34  b = digit_values[p[2]];
35  result = (result << 4) | b;
36  if (b < 0) return UNI_REPLACEMENT_CHAR;
37  b = digit_values[p[3]];
38  result = (result << 4) | b;
39  if (b < 0) return UNI_REPLACEMENT_CHAR;
40  return result;
41 }
42 
43 static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
44 {
45  int len = 1;
46  if (ch <= 0x7F) {
47  buf[0] = (char) ch;
48  } else if (ch <= 0x07FF) {
49  buf[0] = (char) ((ch >> 6) | 0xC0);
50  buf[1] = (char) ((ch & 0x3F) | 0x80);
51  len++;
52  } else if (ch <= 0xFFFF) {
53  buf[0] = (char) ((ch >> 12) | 0xE0);
54  buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
55  buf[2] = (char) ((ch & 0x3F) | 0x80);
56  len += 2;
57  } else if (ch <= 0x1fffff) {
58  buf[0] =(char) ((ch >> 18) | 0xF0);
59  buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
60  buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
61  buf[3] =(char) ((ch & 0x3F) | 0x80);
62  len += 3;
63  } else {
64  buf[0] = '?';
65  }
66  return len;
67 }
68 
69 #ifdef HAVE_RUBY_ENCODING_H
70 static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
71  CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
72 static ID i_encoding, i_encode;
73 #else
74 static ID i_iconv;
75 #endif
76 
79 
84 
85 
86 #line 109 "parser.rl"
87 
88 
89 
90 #line 91 "parser.c"
91 static const int JSON_object_start = 1;
92 static const int JSON_object_first_final = 27;
93 static const int JSON_object_error = 0;
94 
95 static const int JSON_object_en_main = 1;
96 
97 
98 #line 150 "parser.rl"
99 
100 
101 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
102 {
103  int cs = EVIL;
104  VALUE last_name = Qnil;
105  VALUE object_class = json->object_class;
106 
107  if (json->max_nesting && json->current_nesting > json->max_nesting) {
108  rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
109  }
110 
111  *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
112 
113 
114 #line 115 "parser.c"
115  {
116  cs = JSON_object_start;
117  }
118 
119 #line 165 "parser.rl"
120 
121 #line 122 "parser.c"
122  {
123  if ( p == pe )
124  goto _test_eof;
125  switch ( cs )
126  {
127 case 1:
128  if ( (*p) == 123 )
129  goto st2;
130  goto st0;
131 st0:
132 cs = 0;
133  goto _out;
134 st2:
135  if ( ++p == pe )
136  goto _test_eof2;
137 case 2:
138  switch( (*p) ) {
139  case 13: goto st2;
140  case 32: goto st2;
141  case 34: goto tr2;
142  case 47: goto st23;
143  case 125: goto tr4;
144  }
145  if ( 9 <= (*p) && (*p) <= 10 )
146  goto st2;
147  goto st0;
148 tr2:
149 #line 132 "parser.rl"
150  {
151  char *np;
152  json->parsing_name = 1;
153  np = JSON_parse_string(json, p, pe, &last_name);
154  json->parsing_name = 0;
155  if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
156  }
157  goto st3;
158 st3:
159  if ( ++p == pe )
160  goto _test_eof3;
161 case 3:
162 #line 163 "parser.c"
163  switch( (*p) ) {
164  case 13: goto st3;
165  case 32: goto st3;
166  case 47: goto st4;
167  case 58: goto st8;
168  }
169  if ( 9 <= (*p) && (*p) <= 10 )
170  goto st3;
171  goto st0;
172 st4:
173  if ( ++p == pe )
174  goto _test_eof4;
175 case 4:
176  switch( (*p) ) {
177  case 42: goto st5;
178  case 47: goto st7;
179  }
180  goto st0;
181 st5:
182  if ( ++p == pe )
183  goto _test_eof5;
184 case 5:
185  if ( (*p) == 42 )
186  goto st6;
187  goto st5;
188 st6:
189  if ( ++p == pe )
190  goto _test_eof6;
191 case 6:
192  switch( (*p) ) {
193  case 42: goto st6;
194  case 47: goto st3;
195  }
196  goto st5;
197 st7:
198  if ( ++p == pe )
199  goto _test_eof7;
200 case 7:
201  if ( (*p) == 10 )
202  goto st3;
203  goto st7;
204 st8:
205  if ( ++p == pe )
206  goto _test_eof8;
207 case 8:
208  switch( (*p) ) {
209  case 13: goto st8;
210  case 32: goto st8;
211  case 34: goto tr11;
212  case 45: goto tr11;
213  case 47: goto st19;
214  case 73: goto tr11;
215  case 78: goto tr11;
216  case 91: goto tr11;
217  case 102: goto tr11;
218  case 110: goto tr11;
219  case 116: goto tr11;
220  case 123: goto tr11;
221  }
222  if ( (*p) > 10 ) {
223  if ( 48 <= (*p) && (*p) <= 57 )
224  goto tr11;
225  } else if ( (*p) >= 9 )
226  goto st8;
227  goto st0;
228 tr11:
229 #line 117 "parser.rl"
230  {
231  VALUE v = Qnil;
232  char *np = JSON_parse_value(json, p, pe, &v);
233  if (np == NULL) {
234  p--; {p++; cs = 9; goto _out;}
235  } else {
236  if (NIL_P(json->object_class)) {
237  rb_hash_aset(*result, last_name, v);
238  } else {
239  rb_funcall(*result, i_aset, 2, last_name, v);
240  }
241  {p = (( np))-1;}
242  }
243  }
244  goto st9;
245 st9:
246  if ( ++p == pe )
247  goto _test_eof9;
248 case 9:
249 #line 250 "parser.c"
250  switch( (*p) ) {
251  case 13: goto st9;
252  case 32: goto st9;
253  case 44: goto st10;
254  case 47: goto st15;
255  case 125: goto tr4;
256  }
257  if ( 9 <= (*p) && (*p) <= 10 )
258  goto st9;
259  goto st0;
260 st10:
261  if ( ++p == pe )
262  goto _test_eof10;
263 case 10:
264  switch( (*p) ) {
265  case 13: goto st10;
266  case 32: goto st10;
267  case 34: goto tr2;
268  case 47: goto st11;
269  }
270  if ( 9 <= (*p) && (*p) <= 10 )
271  goto st10;
272  goto st0;
273 st11:
274  if ( ++p == pe )
275  goto _test_eof11;
276 case 11:
277  switch( (*p) ) {
278  case 42: goto st12;
279  case 47: goto st14;
280  }
281  goto st0;
282 st12:
283  if ( ++p == pe )
284  goto _test_eof12;
285 case 12:
286  if ( (*p) == 42 )
287  goto st13;
288  goto st12;
289 st13:
290  if ( ++p == pe )
291  goto _test_eof13;
292 case 13:
293  switch( (*p) ) {
294  case 42: goto st13;
295  case 47: goto st10;
296  }
297  goto st12;
298 st14:
299  if ( ++p == pe )
300  goto _test_eof14;
301 case 14:
302  if ( (*p) == 10 )
303  goto st10;
304  goto st14;
305 st15:
306  if ( ++p == pe )
307  goto _test_eof15;
308 case 15:
309  switch( (*p) ) {
310  case 42: goto st16;
311  case 47: goto st18;
312  }
313  goto st0;
314 st16:
315  if ( ++p == pe )
316  goto _test_eof16;
317 case 16:
318  if ( (*p) == 42 )
319  goto st17;
320  goto st16;
321 st17:
322  if ( ++p == pe )
323  goto _test_eof17;
324 case 17:
325  switch( (*p) ) {
326  case 42: goto st17;
327  case 47: goto st9;
328  }
329  goto st16;
330 st18:
331  if ( ++p == pe )
332  goto _test_eof18;
333 case 18:
334  if ( (*p) == 10 )
335  goto st9;
336  goto st18;
337 tr4:
338 #line 140 "parser.rl"
339  { p--; {p++; cs = 27; goto _out;} }
340  goto st27;
341 st27:
342  if ( ++p == pe )
343  goto _test_eof27;
344 case 27:
345 #line 346 "parser.c"
346  goto st0;
347 st19:
348  if ( ++p == pe )
349  goto _test_eof19;
350 case 19:
351  switch( (*p) ) {
352  case 42: goto st20;
353  case 47: goto st22;
354  }
355  goto st0;
356 st20:
357  if ( ++p == pe )
358  goto _test_eof20;
359 case 20:
360  if ( (*p) == 42 )
361  goto st21;
362  goto st20;
363 st21:
364  if ( ++p == pe )
365  goto _test_eof21;
366 case 21:
367  switch( (*p) ) {
368  case 42: goto st21;
369  case 47: goto st8;
370  }
371  goto st20;
372 st22:
373  if ( ++p == pe )
374  goto _test_eof22;
375 case 22:
376  if ( (*p) == 10 )
377  goto st8;
378  goto st22;
379 st23:
380  if ( ++p == pe )
381  goto _test_eof23;
382 case 23:
383  switch( (*p) ) {
384  case 42: goto st24;
385  case 47: goto st26;
386  }
387  goto st0;
388 st24:
389  if ( ++p == pe )
390  goto _test_eof24;
391 case 24:
392  if ( (*p) == 42 )
393  goto st25;
394  goto st24;
395 st25:
396  if ( ++p == pe )
397  goto _test_eof25;
398 case 25:
399  switch( (*p) ) {
400  case 42: goto st25;
401  case 47: goto st2;
402  }
403  goto st24;
404 st26:
405  if ( ++p == pe )
406  goto _test_eof26;
407 case 26:
408  if ( (*p) == 10 )
409  goto st2;
410  goto st26;
411  }
412  _test_eof2: cs = 2; goto _test_eof;
413  _test_eof3: cs = 3; goto _test_eof;
414  _test_eof4: cs = 4; goto _test_eof;
415  _test_eof5: cs = 5; goto _test_eof;
416  _test_eof6: cs = 6; goto _test_eof;
417  _test_eof7: cs = 7; goto _test_eof;
418  _test_eof8: cs = 8; goto _test_eof;
419  _test_eof9: cs = 9; goto _test_eof;
420  _test_eof10: cs = 10; goto _test_eof;
421  _test_eof11: cs = 11; goto _test_eof;
422  _test_eof12: cs = 12; goto _test_eof;
423  _test_eof13: cs = 13; goto _test_eof;
424  _test_eof14: cs = 14; goto _test_eof;
425  _test_eof15: cs = 15; goto _test_eof;
426  _test_eof16: cs = 16; goto _test_eof;
427  _test_eof17: cs = 17; goto _test_eof;
428  _test_eof18: cs = 18; goto _test_eof;
429  _test_eof27: cs = 27; goto _test_eof;
430  _test_eof19: cs = 19; goto _test_eof;
431  _test_eof20: cs = 20; goto _test_eof;
432  _test_eof21: cs = 21; goto _test_eof;
433  _test_eof22: cs = 22; goto _test_eof;
434  _test_eof23: cs = 23; goto _test_eof;
435  _test_eof24: cs = 24; goto _test_eof;
436  _test_eof25: cs = 25; goto _test_eof;
437  _test_eof26: cs = 26; goto _test_eof;
438 
439  _test_eof: {}
440  _out: {}
441  }
442 
443 #line 166 "parser.rl"
444 
445  if (cs >= JSON_object_first_final) {
446  if (json->create_additions) {
447  VALUE klassname;
448  if (NIL_P(json->object_class)) {
449  klassname = rb_hash_aref(*result, json->create_id);
450  } else {
451  klassname = rb_funcall(*result, i_aref, 1, json->create_id);
452  }
453  if (!NIL_P(klassname)) {
454  VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
455  if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
456  *result = rb_funcall(klass, i_json_create, 1, *result);
457  }
458  }
459  }
460  return p + 1;
461  } else {
462  return NULL;
463  }
464 }
465 
466 
467 
468 #line 464 "parser.c"
469 static const int JSON_value_start = 1;
470 static const int JSON_value_first_final = 21;
471 static const int JSON_value_error = 0;
472 
473 static const int JSON_value_en_main = 1;
474 
475 
476 #line 265 "parser.rl"
477 
478 
479 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
480 {
481  int cs = EVIL;
482 
483 
484 #line 480 "parser.c"
485  {
486  cs = JSON_value_start;
487  }
488 
489 #line 272 "parser.rl"
490 
491 #line 487 "parser.c"
492  {
493  if ( p == pe )
494  goto _test_eof;
495  switch ( cs )
496  {
497 case 1:
498  switch( (*p) ) {
499  case 34: goto tr0;
500  case 45: goto tr2;
501  case 73: goto st2;
502  case 78: goto st9;
503  case 91: goto tr5;
504  case 102: goto st11;
505  case 110: goto st15;
506  case 116: goto st18;
507  case 123: goto tr9;
508  }
509  if ( 48 <= (*p) && (*p) <= 57 )
510  goto tr2;
511  goto st0;
512 st0:
513 cs = 0;
514  goto _out;
515 tr0:
516 #line 213 "parser.rl"
517  {
518  char *np = JSON_parse_string(json, p, pe, result);
519  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
520  }
521  goto st21;
522 tr2:
523 #line 218 "parser.rl"
524  {
525  char *np;
526  if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
527  if (json->allow_nan) {
528  *result = CMinusInfinity;
529  {p = (( p + 10))-1;}
530  p--; {p++; cs = 21; goto _out;}
531  } else {
532  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
533  }
534  }
535  np = JSON_parse_float(json, p, pe, result);
536  if (np != NULL) {p = (( np))-1;}
537  np = JSON_parse_integer(json, p, pe, result);
538  if (np != NULL) {p = (( np))-1;}
539  p--; {p++; cs = 21; goto _out;}
540  }
541  goto st21;
542 tr5:
543 #line 236 "parser.rl"
544  {
545  char *np;
546  json->current_nesting++;
547  np = JSON_parse_array(json, p, pe, result);
548  json->current_nesting--;
549  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
550  }
551  goto st21;
552 tr9:
553 #line 244 "parser.rl"
554  {
555  char *np;
556  json->current_nesting++;
557  np = JSON_parse_object(json, p, pe, result);
558  json->current_nesting--;
559  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
560  }
561  goto st21;
562 tr16:
563 #line 206 "parser.rl"
564  {
565  if (json->allow_nan) {
566  *result = CInfinity;
567  } else {
568  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
569  }
570  }
571  goto st21;
572 tr18:
573 #line 199 "parser.rl"
574  {
575  if (json->allow_nan) {
576  *result = CNaN;
577  } else {
578  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
579  }
580  }
581  goto st21;
582 tr22:
583 #line 193 "parser.rl"
584  {
585  *result = Qfalse;
586  }
587  goto st21;
588 tr25:
589 #line 190 "parser.rl"
590  {
591  *result = Qnil;
592  }
593  goto st21;
594 tr28:
595 #line 196 "parser.rl"
596  {
597  *result = Qtrue;
598  }
599  goto st21;
600 st21:
601  if ( ++p == pe )
602  goto _test_eof21;
603 case 21:
604 #line 252 "parser.rl"
605  { p--; {p++; cs = 21; goto _out;} }
606 #line 602 "parser.c"
607  goto st0;
608 st2:
609  if ( ++p == pe )
610  goto _test_eof2;
611 case 2:
612  if ( (*p) == 110 )
613  goto st3;
614  goto st0;
615 st3:
616  if ( ++p == pe )
617  goto _test_eof3;
618 case 3:
619  if ( (*p) == 102 )
620  goto st4;
621  goto st0;
622 st4:
623  if ( ++p == pe )
624  goto _test_eof4;
625 case 4:
626  if ( (*p) == 105 )
627  goto st5;
628  goto st0;
629 st5:
630  if ( ++p == pe )
631  goto _test_eof5;
632 case 5:
633  if ( (*p) == 110 )
634  goto st6;
635  goto st0;
636 st6:
637  if ( ++p == pe )
638  goto _test_eof6;
639 case 6:
640  if ( (*p) == 105 )
641  goto st7;
642  goto st0;
643 st7:
644  if ( ++p == pe )
645  goto _test_eof7;
646 case 7:
647  if ( (*p) == 116 )
648  goto st8;
649  goto st0;
650 st8:
651  if ( ++p == pe )
652  goto _test_eof8;
653 case 8:
654  if ( (*p) == 121 )
655  goto tr16;
656  goto st0;
657 st9:
658  if ( ++p == pe )
659  goto _test_eof9;
660 case 9:
661  if ( (*p) == 97 )
662  goto st10;
663  goto st0;
664 st10:
665  if ( ++p == pe )
666  goto _test_eof10;
667 case 10:
668  if ( (*p) == 78 )
669  goto tr18;
670  goto st0;
671 st11:
672  if ( ++p == pe )
673  goto _test_eof11;
674 case 11:
675  if ( (*p) == 97 )
676  goto st12;
677  goto st0;
678 st12:
679  if ( ++p == pe )
680  goto _test_eof12;
681 case 12:
682  if ( (*p) == 108 )
683  goto st13;
684  goto st0;
685 st13:
686  if ( ++p == pe )
687  goto _test_eof13;
688 case 13:
689  if ( (*p) == 115 )
690  goto st14;
691  goto st0;
692 st14:
693  if ( ++p == pe )
694  goto _test_eof14;
695 case 14:
696  if ( (*p) == 101 )
697  goto tr22;
698  goto st0;
699 st15:
700  if ( ++p == pe )
701  goto _test_eof15;
702 case 15:
703  if ( (*p) == 117 )
704  goto st16;
705  goto st0;
706 st16:
707  if ( ++p == pe )
708  goto _test_eof16;
709 case 16:
710  if ( (*p) == 108 )
711  goto st17;
712  goto st0;
713 st17:
714  if ( ++p == pe )
715  goto _test_eof17;
716 case 17:
717  if ( (*p) == 108 )
718  goto tr25;
719  goto st0;
720 st18:
721  if ( ++p == pe )
722  goto _test_eof18;
723 case 18:
724  if ( (*p) == 114 )
725  goto st19;
726  goto st0;
727 st19:
728  if ( ++p == pe )
729  goto _test_eof19;
730 case 19:
731  if ( (*p) == 117 )
732  goto st20;
733  goto st0;
734 st20:
735  if ( ++p == pe )
736  goto _test_eof20;
737 case 20:
738  if ( (*p) == 101 )
739  goto tr28;
740  goto st0;
741  }
742  _test_eof21: cs = 21; goto _test_eof;
743  _test_eof2: cs = 2; goto _test_eof;
744  _test_eof3: cs = 3; goto _test_eof;
745  _test_eof4: cs = 4; goto _test_eof;
746  _test_eof5: cs = 5; goto _test_eof;
747  _test_eof6: cs = 6; goto _test_eof;
748  _test_eof7: cs = 7; goto _test_eof;
749  _test_eof8: cs = 8; goto _test_eof;
750  _test_eof9: cs = 9; goto _test_eof;
751  _test_eof10: cs = 10; goto _test_eof;
752  _test_eof11: cs = 11; goto _test_eof;
753  _test_eof12: cs = 12; goto _test_eof;
754  _test_eof13: cs = 13; goto _test_eof;
755  _test_eof14: cs = 14; goto _test_eof;
756  _test_eof15: cs = 15; goto _test_eof;
757  _test_eof16: cs = 16; goto _test_eof;
758  _test_eof17: cs = 17; goto _test_eof;
759  _test_eof18: cs = 18; goto _test_eof;
760  _test_eof19: cs = 19; goto _test_eof;
761  _test_eof20: cs = 20; goto _test_eof;
762 
763  _test_eof: {}
764  _out: {}
765  }
766 
767 #line 273 "parser.rl"
768 
769  if (cs >= JSON_value_first_final) {
770  return p;
771  } else {
772  return NULL;
773  }
774 }
775 
776 
777 #line 773 "parser.c"
778 static const int JSON_integer_start = 1;
779 static const int JSON_integer_first_final = 3;
780 static const int JSON_integer_error = 0;
781 
782 static const int JSON_integer_en_main = 1;
783 
784 
785 #line 289 "parser.rl"
786 
787 
788 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
789 {
790  int cs = EVIL;
791 
792 
793 #line 789 "parser.c"
794  {
795  cs = JSON_integer_start;
796  }
797 
798 #line 296 "parser.rl"
799  json->memo = p;
800 
801 #line 797 "parser.c"
802  {
803  if ( p == pe )
804  goto _test_eof;
805  switch ( cs )
806  {
807 case 1:
808  switch( (*p) ) {
809  case 45: goto st2;
810  case 48: goto st3;
811  }
812  if ( 49 <= (*p) && (*p) <= 57 )
813  goto st5;
814  goto st0;
815 st0:
816 cs = 0;
817  goto _out;
818 st2:
819  if ( ++p == pe )
820  goto _test_eof2;
821 case 2:
822  if ( (*p) == 48 )
823  goto st3;
824  if ( 49 <= (*p) && (*p) <= 57 )
825  goto st5;
826  goto st0;
827 st3:
828  if ( ++p == pe )
829  goto _test_eof3;
830 case 3:
831  if ( 48 <= (*p) && (*p) <= 57 )
832  goto st0;
833  goto tr4;
834 tr4:
835 #line 286 "parser.rl"
836  { p--; {p++; cs = 4; goto _out;} }
837  goto st4;
838 st4:
839  if ( ++p == pe )
840  goto _test_eof4;
841 case 4:
842 #line 838 "parser.c"
843  goto st0;
844 st5:
845  if ( ++p == pe )
846  goto _test_eof5;
847 case 5:
848  if ( 48 <= (*p) && (*p) <= 57 )
849  goto st5;
850  goto tr4;
851  }
852  _test_eof2: cs = 2; goto _test_eof;
853  _test_eof3: cs = 3; goto _test_eof;
854  _test_eof4: cs = 4; goto _test_eof;
855  _test_eof5: cs = 5; goto _test_eof;
856 
857  _test_eof: {}
858  _out: {}
859  }
860 
861 #line 298 "parser.rl"
862 
863  if (cs >= JSON_integer_first_final) {
864  long len = p - json->memo;
865  *result = rb_Integer(rb_str_new(json->memo, len));
866  return p + 1;
867  } else {
868  return NULL;
869  }
870 }
871 
872 
873 #line 869 "parser.c"
874 static const int JSON_float_start = 1;
875 static const int JSON_float_first_final = 8;
876 static const int JSON_float_error = 0;
877 
878 static const int JSON_float_en_main = 1;
879 
880 
881 #line 320 "parser.rl"
882 
883 
884 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
885 {
886  int cs = EVIL;
887 
888 
889 #line 885 "parser.c"
890  {
891  cs = JSON_float_start;
892  }
893 
894 #line 327 "parser.rl"
895  json->memo = p;
896 
897 #line 893 "parser.c"
898  {
899  if ( p == pe )
900  goto _test_eof;
901  switch ( cs )
902  {
903 case 1:
904  switch( (*p) ) {
905  case 45: goto st2;
906  case 48: goto st3;
907  }
908  if ( 49 <= (*p) && (*p) <= 57 )
909  goto st7;
910  goto st0;
911 st0:
912 cs = 0;
913  goto _out;
914 st2:
915  if ( ++p == pe )
916  goto _test_eof2;
917 case 2:
918  if ( (*p) == 48 )
919  goto st3;
920  if ( 49 <= (*p) && (*p) <= 57 )
921  goto st7;
922  goto st0;
923 st3:
924  if ( ++p == pe )
925  goto _test_eof3;
926 case 3:
927  switch( (*p) ) {
928  case 46: goto st4;
929  case 69: goto st5;
930  case 101: goto st5;
931  }
932  goto st0;
933 st4:
934  if ( ++p == pe )
935  goto _test_eof4;
936 case 4:
937  if ( 48 <= (*p) && (*p) <= 57 )
938  goto st8;
939  goto st0;
940 st8:
941  if ( ++p == pe )
942  goto _test_eof8;
943 case 8:
944  switch( (*p) ) {
945  case 69: goto st5;
946  case 101: goto st5;
947  }
948  if ( (*p) > 46 ) {
949  if ( 48 <= (*p) && (*p) <= 57 )
950  goto st8;
951  } else if ( (*p) >= 45 )
952  goto st0;
953  goto tr9;
954 tr9:
955 #line 314 "parser.rl"
956  { p--; {p++; cs = 9; goto _out;} }
957  goto st9;
958 st9:
959  if ( ++p == pe )
960  goto _test_eof9;
961 case 9:
962 #line 958 "parser.c"
963  goto st0;
964 st5:
965  if ( ++p == pe )
966  goto _test_eof5;
967 case 5:
968  switch( (*p) ) {
969  case 43: goto st6;
970  case 45: goto st6;
971  }
972  if ( 48 <= (*p) && (*p) <= 57 )
973  goto st10;
974  goto st0;
975 st6:
976  if ( ++p == pe )
977  goto _test_eof6;
978 case 6:
979  if ( 48 <= (*p) && (*p) <= 57 )
980  goto st10;
981  goto st0;
982 st10:
983  if ( ++p == pe )
984  goto _test_eof10;
985 case 10:
986  switch( (*p) ) {
987  case 69: goto st0;
988  case 101: goto st0;
989  }
990  if ( (*p) > 46 ) {
991  if ( 48 <= (*p) && (*p) <= 57 )
992  goto st10;
993  } else if ( (*p) >= 45 )
994  goto st0;
995  goto tr9;
996 st7:
997  if ( ++p == pe )
998  goto _test_eof7;
999 case 7:
1000  switch( (*p) ) {
1001  case 46: goto st4;
1002  case 69: goto st5;
1003  case 101: goto st5;
1004  }
1005  if ( 48 <= (*p) && (*p) <= 57 )
1006  goto st7;
1007  goto st0;
1008  }
1009  _test_eof2: cs = 2; goto _test_eof;
1010  _test_eof3: cs = 3; goto _test_eof;
1011  _test_eof4: cs = 4; goto _test_eof;
1012  _test_eof8: cs = 8; goto _test_eof;
1013  _test_eof9: cs = 9; goto _test_eof;
1014  _test_eof5: cs = 5; goto _test_eof;
1015  _test_eof6: cs = 6; goto _test_eof;
1016  _test_eof10: cs = 10; goto _test_eof;
1017  _test_eof7: cs = 7; goto _test_eof;
1018 
1019  _test_eof: {}
1020  _out: {}
1021  }
1022 
1023 #line 329 "parser.rl"
1024 
1025  if (cs >= JSON_float_first_final) {
1026  long len = p - json->memo;
1027  *result = rb_Float(rb_str_new(json->memo, len));
1028  return p + 1;
1029  } else {
1030  return NULL;
1031  }
1032 }
1033 
1034 
1035 
1036 #line 1032 "parser.c"
1037 static const int JSON_array_start = 1;
1038 static const int JSON_array_first_final = 17;
1039 static const int JSON_array_error = 0;
1040 
1041 static const int JSON_array_en_main = 1;
1042 
1043 
1044 #line 369 "parser.rl"
1045 
1046 
1047 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
1048 {
1049  int cs = EVIL;
1050  VALUE array_class = json->array_class;
1051 
1052  if (json->max_nesting && json->current_nesting > json->max_nesting) {
1053  rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
1054  }
1055  *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1056 
1057 
1058 #line 1054 "parser.c"
1059  {
1060  cs = JSON_array_start;
1061  }
1062 
1063 #line 382 "parser.rl"
1064 
1065 #line 1061 "parser.c"
1066  {
1067  if ( p == pe )
1068  goto _test_eof;
1069  switch ( cs )
1070  {
1071 case 1:
1072  if ( (*p) == 91 )
1073  goto st2;
1074  goto st0;
1075 st0:
1076 cs = 0;
1077  goto _out;
1078 st2:
1079  if ( ++p == pe )
1080  goto _test_eof2;
1081 case 2:
1082  switch( (*p) ) {
1083  case 13: goto st2;
1084  case 32: goto st2;
1085  case 34: goto tr2;
1086  case 45: goto tr2;
1087  case 47: goto st13;
1088  case 73: goto tr2;
1089  case 78: goto tr2;
1090  case 91: goto tr2;
1091  case 93: goto tr4;
1092  case 102: goto tr2;
1093  case 110: goto tr2;
1094  case 116: goto tr2;
1095  case 123: goto tr2;
1096  }
1097  if ( (*p) > 10 ) {
1098  if ( 48 <= (*p) && (*p) <= 57 )
1099  goto tr2;
1100  } else if ( (*p) >= 9 )
1101  goto st2;
1102  goto st0;
1103 tr2:
1104 #line 346 "parser.rl"
1105  {
1106  VALUE v = Qnil;
1107  char *np = JSON_parse_value(json, p, pe, &v);
1108  if (np == NULL) {
1109  p--; {p++; cs = 3; goto _out;}
1110  } else {
1111  if (NIL_P(json->array_class)) {
1112  rb_ary_push(*result, v);
1113  } else {
1114  rb_funcall(*result, i_leftshift, 1, v);
1115  }
1116  {p = (( np))-1;}
1117  }
1118  }
1119  goto st3;
1120 st3:
1121  if ( ++p == pe )
1122  goto _test_eof3;
1123 case 3:
1124 #line 1120 "parser.c"
1125  switch( (*p) ) {
1126  case 13: goto st3;
1127  case 32: goto st3;
1128  case 44: goto st4;
1129  case 47: goto st9;
1130  case 93: goto tr4;
1131  }
1132  if ( 9 <= (*p) && (*p) <= 10 )
1133  goto st3;
1134  goto st0;
1135 st4:
1136  if ( ++p == pe )
1137  goto _test_eof4;
1138 case 4:
1139  switch( (*p) ) {
1140  case 13: goto st4;
1141  case 32: goto st4;
1142  case 34: goto tr2;
1143  case 45: goto tr2;
1144  case 47: goto st5;
1145  case 73: goto tr2;
1146  case 78: goto tr2;
1147  case 91: goto tr2;
1148  case 102: goto tr2;
1149  case 110: goto tr2;
1150  case 116: goto tr2;
1151  case 123: goto tr2;
1152  }
1153  if ( (*p) > 10 ) {
1154  if ( 48 <= (*p) && (*p) <= 57 )
1155  goto tr2;
1156  } else if ( (*p) >= 9 )
1157  goto st4;
1158  goto st0;
1159 st5:
1160  if ( ++p == pe )
1161  goto _test_eof5;
1162 case 5:
1163  switch( (*p) ) {
1164  case 42: goto st6;
1165  case 47: goto st8;
1166  }
1167  goto st0;
1168 st6:
1169  if ( ++p == pe )
1170  goto _test_eof6;
1171 case 6:
1172  if ( (*p) == 42 )
1173  goto st7;
1174  goto st6;
1175 st7:
1176  if ( ++p == pe )
1177  goto _test_eof7;
1178 case 7:
1179  switch( (*p) ) {
1180  case 42: goto st7;
1181  case 47: goto st4;
1182  }
1183  goto st6;
1184 st8:
1185  if ( ++p == pe )
1186  goto _test_eof8;
1187 case 8:
1188  if ( (*p) == 10 )
1189  goto st4;
1190  goto st8;
1191 st9:
1192  if ( ++p == pe )
1193  goto _test_eof9;
1194 case 9:
1195  switch( (*p) ) {
1196  case 42: goto st10;
1197  case 47: goto st12;
1198  }
1199  goto st0;
1200 st10:
1201  if ( ++p == pe )
1202  goto _test_eof10;
1203 case 10:
1204  if ( (*p) == 42 )
1205  goto st11;
1206  goto st10;
1207 st11:
1208  if ( ++p == pe )
1209  goto _test_eof11;
1210 case 11:
1211  switch( (*p) ) {
1212  case 42: goto st11;
1213  case 47: goto st3;
1214  }
1215  goto st10;
1216 st12:
1217  if ( ++p == pe )
1218  goto _test_eof12;
1219 case 12:
1220  if ( (*p) == 10 )
1221  goto st3;
1222  goto st12;
1223 tr4:
1224 #line 361 "parser.rl"
1225  { p--; {p++; cs = 17; goto _out;} }
1226  goto st17;
1227 st17:
1228  if ( ++p == pe )
1229  goto _test_eof17;
1230 case 17:
1231 #line 1227 "parser.c"
1232  goto st0;
1233 st13:
1234  if ( ++p == pe )
1235  goto _test_eof13;
1236 case 13:
1237  switch( (*p) ) {
1238  case 42: goto st14;
1239  case 47: goto st16;
1240  }
1241  goto st0;
1242 st14:
1243  if ( ++p == pe )
1244  goto _test_eof14;
1245 case 14:
1246  if ( (*p) == 42 )
1247  goto st15;
1248  goto st14;
1249 st15:
1250  if ( ++p == pe )
1251  goto _test_eof15;
1252 case 15:
1253  switch( (*p) ) {
1254  case 42: goto st15;
1255  case 47: goto st2;
1256  }
1257  goto st14;
1258 st16:
1259  if ( ++p == pe )
1260  goto _test_eof16;
1261 case 16:
1262  if ( (*p) == 10 )
1263  goto st2;
1264  goto st16;
1265  }
1266  _test_eof2: cs = 2; goto _test_eof;
1267  _test_eof3: cs = 3; goto _test_eof;
1268  _test_eof4: cs = 4; goto _test_eof;
1269  _test_eof5: cs = 5; goto _test_eof;
1270  _test_eof6: cs = 6; goto _test_eof;
1271  _test_eof7: cs = 7; goto _test_eof;
1272  _test_eof8: cs = 8; goto _test_eof;
1273  _test_eof9: cs = 9; goto _test_eof;
1274  _test_eof10: cs = 10; goto _test_eof;
1275  _test_eof11: cs = 11; goto _test_eof;
1276  _test_eof12: cs = 12; goto _test_eof;
1277  _test_eof17: cs = 17; goto _test_eof;
1278  _test_eof13: cs = 13; goto _test_eof;
1279  _test_eof14: cs = 14; goto _test_eof;
1280  _test_eof15: cs = 15; goto _test_eof;
1281  _test_eof16: cs = 16; goto _test_eof;
1282 
1283  _test_eof: {}
1284  _out: {}
1285  }
1286 
1287 #line 383 "parser.rl"
1288 
1289  if(cs >= JSON_array_first_final) {
1290  return p + 1;
1291  } else {
1292  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1293  return NULL;
1294  }
1295 }
1296 
1297 static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1298 {
1299  char *p = string, *pe = string, *unescape;
1300  int unescape_len;
1301  char buf[4];
1302 
1303  while (pe < stringEnd) {
1304  if (*pe == '\\') {
1305  unescape = (char *) "?";
1306  unescape_len = 1;
1307  if (pe > p) rb_str_buf_cat(result, p, pe - p);
1308  switch (*++pe) {
1309  case 'n':
1310  unescape = (char *) "\n";
1311  break;
1312  case 'r':
1313  unescape = (char *) "\r";
1314  break;
1315  case 't':
1316  unescape = (char *) "\t";
1317  break;
1318  case '"':
1319  unescape = (char *) "\"";
1320  break;
1321  case '\\':
1322  unescape = (char *) "\\";
1323  break;
1324  case 'b':
1325  unescape = (char *) "\b";
1326  break;
1327  case 'f':
1328  unescape = (char *) "\f";
1329  break;
1330  case 'u':
1331  if (pe > stringEnd - 4) {
1332  return Qnil;
1333  } else {
1334  UTF32 ch = unescape_unicode((unsigned char *) ++pe);
1335  pe += 3;
1336  if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
1337  pe++;
1338  if (pe > stringEnd - 6) return Qnil;
1339  if (pe[0] == '\\' && pe[1] == 'u') {
1340  UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
1341  ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
1342  | (sur & 0x3FF));
1343  pe += 5;
1344  } else {
1345  unescape = (char *) "?";
1346  break;
1347  }
1348  }
1349  unescape_len = convert_UTF32_to_UTF8(buf, ch);
1350  unescape = buf;
1351  }
1352  break;
1353  default:
1354  p = pe;
1355  continue;
1356  }
1357  rb_str_buf_cat(result, unescape, unescape_len);
1358  p = ++pe;
1359  } else {
1360  pe++;
1361  }
1362  }
1363  rb_str_buf_cat(result, p, pe - p);
1364  return result;
1365 }
1366 
1367 
1368 #line 1364 "parser.c"
1369 static const int JSON_string_start = 1;
1370 static const int JSON_string_first_final = 8;
1371 static const int JSON_string_error = 0;
1372 
1373 static const int JSON_string_en_main = 1;
1374 
1375 
1376 #line 482 "parser.rl"
1377 
1378 
1379 static int
1380 match_i(VALUE regexp, VALUE klass, VALUE memo)
1381 {
1382  if (regexp == Qundef) return ST_STOP;
1383  if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
1384  RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
1385  rb_ary_push(memo, klass);
1386  return ST_STOP;
1387  }
1388  return ST_CONTINUE;
1389 }
1390 
1391 static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
1392 {
1393  int cs = EVIL;
1395 
1396  *result = rb_str_buf_new(0);
1397 
1398 #line 1394 "parser.c"
1399  {
1400  cs = JSON_string_start;
1401  }
1402 
1403 #line 503 "parser.rl"
1404  json->memo = p;
1405 
1406 #line 1402 "parser.c"
1407  {
1408  if ( p == pe )
1409  goto _test_eof;
1410  switch ( cs )
1411  {
1412 case 1:
1413  if ( (*p) == 34 )
1414  goto st2;
1415  goto st0;
1416 st0:
1417 cs = 0;
1418  goto _out;
1419 st2:
1420  if ( ++p == pe )
1421  goto _test_eof2;
1422 case 2:
1423  switch( (*p) ) {
1424  case 34: goto tr2;
1425  case 92: goto st3;
1426  }
1427  if ( 0 <= (*p) && (*p) <= 31 )
1428  goto st0;
1429  goto st2;
1430 tr2:
1431 #line 468 "parser.rl"
1432  {
1433  *result = json_string_unescape(*result, json->memo + 1, p);
1434  if (NIL_P(*result)) {
1435  p--;
1436  {p++; cs = 8; goto _out;}
1437  } else {
1438  FORCE_UTF8(*result);
1439  {p = (( p + 1))-1;}
1440  }
1441  }
1442 #line 479 "parser.rl"
1443  { p--; {p++; cs = 8; goto _out;} }
1444  goto st8;
1445 st8:
1446  if ( ++p == pe )
1447  goto _test_eof8;
1448 case 8:
1449 #line 1445 "parser.c"
1450  goto st0;
1451 st3:
1452  if ( ++p == pe )
1453  goto _test_eof3;
1454 case 3:
1455  if ( (*p) == 117 )
1456  goto st4;
1457  if ( 0 <= (*p) && (*p) <= 31 )
1458  goto st0;
1459  goto st2;
1460 st4:
1461  if ( ++p == pe )
1462  goto _test_eof4;
1463 case 4:
1464  if ( (*p) < 65 ) {
1465  if ( 48 <= (*p) && (*p) <= 57 )
1466  goto st5;
1467  } else if ( (*p) > 70 ) {
1468  if ( 97 <= (*p) && (*p) <= 102 )
1469  goto st5;
1470  } else
1471  goto st5;
1472  goto st0;
1473 st5:
1474  if ( ++p == pe )
1475  goto _test_eof5;
1476 case 5:
1477  if ( (*p) < 65 ) {
1478  if ( 48 <= (*p) && (*p) <= 57 )
1479  goto st6;
1480  } else if ( (*p) > 70 ) {
1481  if ( 97 <= (*p) && (*p) <= 102 )
1482  goto st6;
1483  } else
1484  goto st6;
1485  goto st0;
1486 st6:
1487  if ( ++p == pe )
1488  goto _test_eof6;
1489 case 6:
1490  if ( (*p) < 65 ) {
1491  if ( 48 <= (*p) && (*p) <= 57 )
1492  goto st7;
1493  } else if ( (*p) > 70 ) {
1494  if ( 97 <= (*p) && (*p) <= 102 )
1495  goto st7;
1496  } else
1497  goto st7;
1498  goto st0;
1499 st7:
1500  if ( ++p == pe )
1501  goto _test_eof7;
1502 case 7:
1503  if ( (*p) < 65 ) {
1504  if ( 48 <= (*p) && (*p) <= 57 )
1505  goto st2;
1506  } else if ( (*p) > 70 ) {
1507  if ( 97 <= (*p) && (*p) <= 102 )
1508  goto st2;
1509  } else
1510  goto st2;
1511  goto st0;
1512  }
1513  _test_eof2: cs = 2; goto _test_eof;
1514  _test_eof8: cs = 8; goto _test_eof;
1515  _test_eof3: cs = 3; goto _test_eof;
1516  _test_eof4: cs = 4; goto _test_eof;
1517  _test_eof5: cs = 5; goto _test_eof;
1518  _test_eof6: cs = 6; goto _test_eof;
1519  _test_eof7: cs = 7; goto _test_eof;
1520 
1521  _test_eof: {}
1522  _out: {}
1523  }
1524 
1525 #line 505 "parser.rl"
1526 
1527  if (json->create_additions && RTEST(match_string = json->match_string)) {
1528  VALUE klass;
1529  VALUE memo = rb_ary_new2(2);
1530  rb_ary_push(memo, *result);
1531  rb_hash_foreach(match_string, match_i, memo);
1532  klass = rb_ary_entry(memo, 1);
1533  if (RTEST(klass)) {
1534  *result = rb_funcall(klass, i_json_create, 1, *result);
1535  }
1536  }
1537 
1538  if (json->symbolize_names && json->parsing_name) {
1539  *result = rb_str_intern(*result);
1540  }
1541  if (cs >= JSON_string_first_final) {
1542  return p + 1;
1543  } else {
1544  return NULL;
1545  }
1546 }
1547 
1548 /*
1549  * Document-class: JSON::Ext::Parser
1550  *
1551  * This is the JSON parser implemented as a C extension. It can be configured
1552  * to be used by setting
1553  *
1554  * JSON.parser = JSON::Ext::Parser
1555  *
1556  * with the method parser= in JSON.
1557  *
1558  */
1559 
1561 {
1562  char *ptr = RSTRING_PTR(source);
1563  long len = RSTRING_LEN(source);
1564  if (len < 2) {
1565  rb_raise(eParserError, "A JSON text must at least contain two octets!");
1566  }
1567 #ifdef HAVE_RUBY_ENCODING_H
1568  {
1569  VALUE encoding = rb_funcall(source, i_encoding, 0);
1570  if (encoding == CEncoding_ASCII_8BIT) {
1571  if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1572  source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
1573  } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1574  source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
1575  } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1576  source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
1577  } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1578  source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
1579  } else {
1580  source = rb_str_dup(source);
1581  FORCE_UTF8(source);
1582  }
1583  } else {
1584  source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
1585  }
1586  }
1587 #else
1588  if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1589  source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
1590  } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1591  source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
1592  } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1593  source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
1594  } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1595  source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
1596  }
1597 #endif
1598  return source;
1599 }
1600 
1601 /*
1602  * call-seq: new(source, opts => {})
1603  *
1604  * Creates a new JSON::Ext::Parser instance for the string _source_.
1605  *
1606  * Creates a new JSON::Ext::Parser instance for the string _source_.
1607  *
1608  * It will be configured by the _opts_ hash. _opts_ can have the following
1609  * keys:
1610  *
1611  * _opts_ can have the following keys:
1612  * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
1613  * structures. Disable depth checking with :max_nesting => false|nil|0, it
1614  * defaults to 19.
1615  * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
1616  * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1617  * false.
1618  * * *symbolize_names*: If set to true, returns symbols for the names
1619  * (keys) in a JSON object. Otherwise strings are returned, which is also
1620  * the default.
1621  * * *create_additions*: If set to false, the Parser doesn't create
1622  * additions even if a matchin class and create_id was found. This option
1623  * defaults to true.
1624  * * *object_class*: Defaults to Hash
1625  * * *array_class*: Defaults to Array
1626  * * *quirks_mode*: Enables quirks_mode for parser, that is for example
1627  * parsing single JSON values instead of documents is possible.
1628  *
1629  */
1631 {
1632  VALUE source, opts;
1634 
1635  if (json->Vsource) {
1636  rb_raise(rb_eTypeError, "already initialized instance");
1637  }
1638  rb_scan_args(argc, argv, "11", &source, &opts);
1639  if (!NIL_P(opts)) {
1640  opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1641  if (NIL_P(opts)) {
1642  rb_raise(rb_eArgError, "opts needs to be like a hash");
1643  } else {
1644  VALUE tmp = ID2SYM(i_max_nesting);
1645  if (option_given_p(opts, tmp)) {
1646  VALUE max_nesting = rb_hash_aref(opts, tmp);
1647  if (RTEST(max_nesting)) {
1648  Check_Type(max_nesting, T_FIXNUM);
1649  json->max_nesting = FIX2INT(max_nesting);
1650  } else {
1651  json->max_nesting = 0;
1652  }
1653  } else {
1654  json->max_nesting = 19;
1655  }
1656  tmp = ID2SYM(i_allow_nan);
1657  if (option_given_p(opts, tmp)) {
1658  json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1659  } else {
1660  json->allow_nan = 0;
1661  }
1662  tmp = ID2SYM(i_symbolize_names);
1663  if (option_given_p(opts, tmp)) {
1664  json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1665  } else {
1666  json->symbolize_names = 0;
1667  }
1668  tmp = ID2SYM(i_quirks_mode);
1669  if (option_given_p(opts, tmp)) {
1670  VALUE quirks_mode = rb_hash_aref(opts, tmp);
1671  json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
1672  } else {
1673  json->quirks_mode = 0;
1674  }
1675  tmp = ID2SYM(i_create_additions);
1676  if (option_given_p(opts, tmp)) {
1677  json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1678  } else {
1679  json->create_additions = 0;
1680  }
1681  tmp = ID2SYM(i_create_id);
1682  if (option_given_p(opts, tmp)) {
1683  json->create_id = rb_hash_aref(opts, tmp);
1684  } else {
1685  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1686  }
1687  tmp = ID2SYM(i_object_class);
1688  if (option_given_p(opts, tmp)) {
1689  json->object_class = rb_hash_aref(opts, tmp);
1690  } else {
1691  json->object_class = Qnil;
1692  }
1693  tmp = ID2SYM(i_array_class);
1694  if (option_given_p(opts, tmp)) {
1695  json->array_class = rb_hash_aref(opts, tmp);
1696  } else {
1697  json->array_class = Qnil;
1698  }
1699  tmp = ID2SYM(i_match_string);
1700  if (option_given_p(opts, tmp)) {
1701  VALUE match_string = rb_hash_aref(opts, tmp);
1702  json->match_string = RTEST(match_string) ? match_string : Qnil;
1703  } else {
1704  json->match_string = Qnil;
1705  }
1706  }
1707  } else {
1708  json->max_nesting = 19;
1709  json->allow_nan = 0;
1710  json->create_additions = 1;
1711  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1712  json->object_class = Qnil;
1713  json->array_class = Qnil;
1714  }
1715  if (!json->quirks_mode) {
1716  source = convert_encoding(StringValue(source));
1717  }
1718  json->current_nesting = 0;
1719  json->len = RSTRING_LEN(source);
1720  json->source = RSTRING_PTR(source);;
1721  json->Vsource = source;
1722  return self;
1723 }
1724 
1725 
1726 #line 1722 "parser.c"
1727 static const int JSON_start = 1;
1728 static const int JSON_first_final = 10;
1729 static const int JSON_error = 0;
1730 
1731 static const int JSON_en_main = 1;
1732 
1733 
1734 #line 729 "parser.rl"
1735 
1736 
1738 {
1739  char *p, *pe;
1740  int cs = EVIL;
1741  VALUE result = Qnil;
1742  GET_PARSER;
1743 
1744 
1745 #line 1741 "parser.c"
1746  {
1747  cs = JSON_start;
1748  }
1749 
1750 #line 739 "parser.rl"
1751  p = json->source;
1752  pe = p + json->len;
1753 
1754 #line 1750 "parser.c"
1755  {
1756  if ( p == pe )
1757  goto _test_eof;
1758  switch ( cs )
1759  {
1760 st1:
1761  if ( ++p == pe )
1762  goto _test_eof1;
1763 case 1:
1764  switch( (*p) ) {
1765  case 13: goto st1;
1766  case 32: goto st1;
1767  case 47: goto st2;
1768  case 91: goto tr3;
1769  case 123: goto tr4;
1770  }
1771  if ( 9 <= (*p) && (*p) <= 10 )
1772  goto st1;
1773  goto st0;
1774 st0:
1775 cs = 0;
1776  goto _out;
1777 st2:
1778  if ( ++p == pe )
1779  goto _test_eof2;
1780 case 2:
1781  switch( (*p) ) {
1782  case 42: goto st3;
1783  case 47: goto st5;
1784  }
1785  goto st0;
1786 st3:
1787  if ( ++p == pe )
1788  goto _test_eof3;
1789 case 3:
1790  if ( (*p) == 42 )
1791  goto st4;
1792  goto st3;
1793 st4:
1794  if ( ++p == pe )
1795  goto _test_eof4;
1796 case 4:
1797  switch( (*p) ) {
1798  case 42: goto st4;
1799  case 47: goto st1;
1800  }
1801  goto st3;
1802 st5:
1803  if ( ++p == pe )
1804  goto _test_eof5;
1805 case 5:
1806  if ( (*p) == 10 )
1807  goto st1;
1808  goto st5;
1809 tr3:
1810 #line 718 "parser.rl"
1811  {
1812  char *np;
1813  json->current_nesting = 1;
1814  np = JSON_parse_array(json, p, pe, &result);
1815  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1816  }
1817  goto st10;
1818 tr4:
1819 #line 711 "parser.rl"
1820  {
1821  char *np;
1822  json->current_nesting = 1;
1823  np = JSON_parse_object(json, p, pe, &result);
1824  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1825  }
1826  goto st10;
1827 st10:
1828  if ( ++p == pe )
1829  goto _test_eof10;
1830 case 10:
1831 #line 1827 "parser.c"
1832  switch( (*p) ) {
1833  case 13: goto st10;
1834  case 32: goto st10;
1835  case 47: goto st6;
1836  }
1837  if ( 9 <= (*p) && (*p) <= 10 )
1838  goto st10;
1839  goto st0;
1840 st6:
1841  if ( ++p == pe )
1842  goto _test_eof6;
1843 case 6:
1844  switch( (*p) ) {
1845  case 42: goto st7;
1846  case 47: goto st9;
1847  }
1848  goto st0;
1849 st7:
1850  if ( ++p == pe )
1851  goto _test_eof7;
1852 case 7:
1853  if ( (*p) == 42 )
1854  goto st8;
1855  goto st7;
1856 st8:
1857  if ( ++p == pe )
1858  goto _test_eof8;
1859 case 8:
1860  switch( (*p) ) {
1861  case 42: goto st8;
1862  case 47: goto st10;
1863  }
1864  goto st7;
1865 st9:
1866  if ( ++p == pe )
1867  goto _test_eof9;
1868 case 9:
1869  if ( (*p) == 10 )
1870  goto st10;
1871  goto st9;
1872  }
1873  _test_eof1: cs = 1; goto _test_eof;
1874  _test_eof2: cs = 2; goto _test_eof;
1875  _test_eof3: cs = 3; goto _test_eof;
1876  _test_eof4: cs = 4; goto _test_eof;
1877  _test_eof5: cs = 5; goto _test_eof;
1878  _test_eof10: cs = 10; goto _test_eof;
1879  _test_eof6: cs = 6; goto _test_eof;
1880  _test_eof7: cs = 7; goto _test_eof;
1881  _test_eof8: cs = 8; goto _test_eof;
1882  _test_eof9: cs = 9; goto _test_eof;
1883 
1884  _test_eof: {}
1885  _out: {}
1886  }
1887 
1888 #line 742 "parser.rl"
1889 
1890  if (cs >= JSON_first_final && p == pe) {
1891  return result;
1892  } else {
1893  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1894  return Qnil;
1895  }
1896 }
1897 
1898 
1899 
1900 #line 1896 "parser.c"
1901 static const int JSON_quirks_mode_start = 1;
1902 static const int JSON_quirks_mode_first_final = 10;
1903 static const int JSON_quirks_mode_error = 0;
1904 
1905 static const int JSON_quirks_mode_en_main = 1;
1906 
1907 
1908 #line 767 "parser.rl"
1909 
1910 
1912 {
1913  char *p, *pe;
1914  int cs = EVIL;
1915  VALUE result = Qnil;
1916  GET_PARSER;
1917 
1918 
1919 #line 1915 "parser.c"
1920  {
1922  }
1923 
1924 #line 777 "parser.rl"
1925  p = json->source;
1926  pe = p + json->len;
1927 
1928 #line 1924 "parser.c"
1929  {
1930  if ( p == pe )
1931  goto _test_eof;
1932  switch ( cs )
1933  {
1934 st1:
1935  if ( ++p == pe )
1936  goto _test_eof1;
1937 case 1:
1938  switch( (*p) ) {
1939  case 13: goto st1;
1940  case 32: goto st1;
1941  case 34: goto tr2;
1942  case 45: goto tr2;
1943  case 47: goto st6;
1944  case 73: goto tr2;
1945  case 78: goto tr2;
1946  case 91: goto tr2;
1947  case 102: goto tr2;
1948  case 110: goto tr2;
1949  case 116: goto tr2;
1950  case 123: goto tr2;
1951  }
1952  if ( (*p) > 10 ) {
1953  if ( 48 <= (*p) && (*p) <= 57 )
1954  goto tr2;
1955  } else if ( (*p) >= 9 )
1956  goto st1;
1957  goto st0;
1958 st0:
1959 cs = 0;
1960  goto _out;
1961 tr2:
1962 #line 759 "parser.rl"
1963  {
1964  char *np = JSON_parse_value(json, p, pe, &result);
1965  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1966  }
1967  goto st10;
1968 st10:
1969  if ( ++p == pe )
1970  goto _test_eof10;
1971 case 10:
1972 #line 1968 "parser.c"
1973  switch( (*p) ) {
1974  case 13: goto st10;
1975  case 32: goto st10;
1976  case 47: goto st2;
1977  }
1978  if ( 9 <= (*p) && (*p) <= 10 )
1979  goto st10;
1980  goto st0;
1981 st2:
1982  if ( ++p == pe )
1983  goto _test_eof2;
1984 case 2:
1985  switch( (*p) ) {
1986  case 42: goto st3;
1987  case 47: goto st5;
1988  }
1989  goto st0;
1990 st3:
1991  if ( ++p == pe )
1992  goto _test_eof3;
1993 case 3:
1994  if ( (*p) == 42 )
1995  goto st4;
1996  goto st3;
1997 st4:
1998  if ( ++p == pe )
1999  goto _test_eof4;
2000 case 4:
2001  switch( (*p) ) {
2002  case 42: goto st4;
2003  case 47: goto st10;
2004  }
2005  goto st3;
2006 st5:
2007  if ( ++p == pe )
2008  goto _test_eof5;
2009 case 5:
2010  if ( (*p) == 10 )
2011  goto st10;
2012  goto st5;
2013 st6:
2014  if ( ++p == pe )
2015  goto _test_eof6;
2016 case 6:
2017  switch( (*p) ) {
2018  case 42: goto st7;
2019  case 47: goto st9;
2020  }
2021  goto st0;
2022 st7:
2023  if ( ++p == pe )
2024  goto _test_eof7;
2025 case 7:
2026  if ( (*p) == 42 )
2027  goto st8;
2028  goto st7;
2029 st8:
2030  if ( ++p == pe )
2031  goto _test_eof8;
2032 case 8:
2033  switch( (*p) ) {
2034  case 42: goto st8;
2035  case 47: goto st1;
2036  }
2037  goto st7;
2038 st9:
2039  if ( ++p == pe )
2040  goto _test_eof9;
2041 case 9:
2042  if ( (*p) == 10 )
2043  goto st1;
2044  goto st9;
2045  }
2046  _test_eof1: cs = 1; goto _test_eof;
2047  _test_eof10: cs = 10; goto _test_eof;
2048  _test_eof2: cs = 2; goto _test_eof;
2049  _test_eof3: cs = 3; goto _test_eof;
2050  _test_eof4: cs = 4; goto _test_eof;
2051  _test_eof5: cs = 5; goto _test_eof;
2052  _test_eof6: cs = 6; goto _test_eof;
2053  _test_eof7: cs = 7; goto _test_eof;
2054  _test_eof8: cs = 8; goto _test_eof;
2055  _test_eof9: cs = 9; goto _test_eof;
2056 
2057  _test_eof: {}
2058  _out: {}
2059  }
2060 
2061 #line 780 "parser.rl"
2062 
2063  if (cs >= JSON_quirks_mode_first_final && p == pe) {
2064  return result;
2065  } else {
2066  rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2067  return Qnil;
2068  }
2069 }
2070 
2071 /*
2072  * call-seq: parse()
2073  *
2074  * Parses the current JSON text _source_ and returns the complete data
2075  * structure as a result.
2076  */
2078 {
2079  GET_PARSER;
2080 
2081  if (json->quirks_mode) {
2082  return cParser_parse_quirks_mode(self);
2083  } else {
2084  return cParser_parse_strict(self);
2085  }
2086 }
2087 
2088 
2090 {
2091  JSON_Parser *json = ALLOC(JSON_Parser);
2092  MEMZERO(json, JSON_Parser, 1);
2093  return json;
2094 }
2095 
2096 static void JSON_mark(JSON_Parser *json)
2097 {
2098  rb_gc_mark_maybe(json->Vsource);
2099  rb_gc_mark_maybe(json->create_id);
2103 }
2104 
2105 static void JSON_free(JSON_Parser *json)
2106 {
2107  ruby_xfree(json);
2108 }
2109 
2111 {
2112  JSON_Parser *json = JSON_allocate();
2113  return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
2114 }
2115 
2116 /*
2117  * call-seq: source()
2118  *
2119  * Returns a copy of the current _source_ string, that was used to construct
2120  * this Parser.
2121  */
2123 {
2124  GET_PARSER;
2125  return rb_str_dup(json->Vsource);
2126 }
2127 
2128 /*
2129  * call-seq: quirks_mode?()
2130  *
2131  * Returns a true, if this parser is in quirks_mode, false otherwise.
2132  */
2134 {
2135  GET_PARSER;
2136  return json->quirks_mode ? Qtrue : Qfalse;
2137 }
2138 
2139 
2141 {
2142  rb_require("json/common");
2143  mJSON = rb_define_module("JSON");
2144  mExt = rb_define_module_under(mJSON, "Ext");
2146  eParserError = rb_path2class("JSON::ParserError");
2147  eNestingError = rb_path2class("JSON::NestingError");
2149  rb_define_method(cParser, "initialize", cParser_initialize, -1);
2150  rb_define_method(cParser, "parse", cParser_parse, 0);
2151  rb_define_method(cParser, "source", cParser_source, 0);
2152  rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
2153 
2154  CNaN = rb_const_get(mJSON, rb_intern("NaN"));
2155  CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
2156  CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
2157 
2158  i_json_creatable_p = rb_intern("json_creatable?");
2159  i_json_create = rb_intern("json_create");
2160  i_create_id = rb_intern("create_id");
2161  i_create_additions = rb_intern("create_additions");
2162  i_chr = rb_intern("chr");
2163  i_max_nesting = rb_intern("max_nesting");
2164  i_allow_nan = rb_intern("allow_nan");
2165  i_symbolize_names = rb_intern("symbolize_names");
2166  i_quirks_mode = rb_intern("quirks_mode");
2167  i_object_class = rb_intern("object_class");
2168  i_array_class = rb_intern("array_class");
2169  i_match = rb_intern("match");
2170  i_match_string = rb_intern("match_string");
2171  i_key_p = rb_intern("key?");
2172  i_deep_const_get = rb_intern("deep_const_get");
2173  i_aset = rb_intern("[]=");
2174  i_aref = rb_intern("[]");
2175  i_leftshift = rb_intern("<<");
2176 #ifdef HAVE_RUBY_ENCODING_H
2177  CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
2178  CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
2179  CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
2180  CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
2181  CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
2182  CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
2183  i_encoding = rb_intern("encoding");
2184  i_encode = rb_intern("encode");
2185 #else
2186  i_iconv = rb_intern("iconv");
2187 #endif
2188 }
2189 
2190 /*
2191  * Local variables:
2192  * mode: c
2193  * c-file-style: ruby
2194  * indent-tabs-mode: nil
2195  * End:
2196  */
#define RSTRING_LEN(string)
Definition: generator.h:45
int create_additions
Definition: parser.h:50
static const int JSON_string_error
Definition: parser.c:1371
static JSON_Parser * JSON_allocate()
Definition: parser.c:2089
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:956
char * memo
Definition: parser.h:40
#define GET_PARSER_INIT
Definition: parser.h:57
static const int JSON_value_error
Definition: parser.c:471
#define T_FIXNUM
Definition: ruby.h:425
static ID i_aref
Definition: parser.c:80
Definition: st.h:100
static const int JSON_float_first_final
Definition: parser.c:875
static VALUE cParser_source(VALUE self)
Definition: parser.c:2122
#define Qtrue
Definition: ruby.h:366
#define option_given_p(opts, key)
Definition: generator.h:25
static VALUE convert_encoding(VALUE source)
Definition: parser.c:1560
#define MinusInfinity
Definition: parser.h:61
static ID i_allow_nan
Definition: parser.c:80
VALUE rb_eTypeError
Definition: error.c:467
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:740
static VALUE eParserError
Definition: parser.c:77
static VALUE match_string(VALUE match)
Definition: re.c:1803
static ID i_max_nesting
Definition: parser.c:80
int parsing_name
Definition: parser.h:45
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:638
static ID i_iconv
Definition: parser.c:74
#define RSTRING_PTR(string)
Definition: generator.h:42
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:514
#define Check_Type(v, t)
Definition: ruby.h:459
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1574
static const int JSON_object_start
Definition: parser.c:91
VALUE rb_convert_type(VALUE, int, const char *, const char *)
Definition: object.c:2078
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define T_HASH
Definition: ruby.h:421
static VALUE cJSON_parser_s_allocate(VALUE klass)
Definition: parser.c:2110
static VALUE cParser_parse(VALUE self)
Definition: parser.c:2077
int current_nesting
Definition: parser.h:43
static VALUE CMinusInfinity
Definition: parser.c:78
static const int JSON_string_first_final
Definition: parser.c:1370
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
Definition: parser.c:43
#define EVIL
Definition: parser.h:62
VALUE rb_path2class(const char *)
Definition: variable.c:293
static const int JSON_float_en_main
Definition: parser.c:878
VALUE rb_Float(VALUE)
Definition: object.c:2351
#define ID2SYM(i)
Definition: cparse.c:63
static ID i_aset
Definition: parser.c:80
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
Definition: parser.c:1630
VALUE rb_str_buf_cat(VALUE, const char *, long)
Definition: string.c:1865
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:817
Win32OLEIDispatch * p
Definition: win32ole.c:778
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
Definition: hash.c:204
static const int JSON_array_first_final
Definition: parser.c:1038
static char * JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:101
static const int JSON_array_error
Definition: parser.c:1039
static char * JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:1391
#define MEMZERO(p, type, n)
Definition: ruby.h:1052
static ID i_chr
Definition: parser.c:80
VALUE rb_require(const char *)
Definition: load.c:652
static void JSON_mark(JSON_Parser *json)
Definition: parser.c:2096
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1638
static ID i_deep_const_get
Definition: parser.c:80
static VALUE eNestingError
Definition: parser.c:77
static const int JSON_value_start
Definition: parser.c:469
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1123
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1246
static ID i_match
Definition: parser.c:80
static char * JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:1047
static const int JSON_en_main
Definition: parser.c:1731
static const int JSON_integer_start
Definition: parser.c:778
VALUE rb_ary_new(void)
Definition: array.c:339
unsigned long UTF32
Definition: generator.h:84
#define NIL_P(v)
Definition: ruby.h:374
static ID i_object_class
Definition: parser.c:80
VALUE object_class
Definition: parser.h:48
static const int JSON_integer_error
Definition: parser.c:780
static VALUE cParser
Definition: parser.c:77
int argc
Definition: ruby.c:120
static const int JSON_quirks_mode_error
Definition: parser.c:1903
#define Qfalse
Definition: ruby.h:365
VALUE rb_Integer(VALUE)
Definition: object.c:2192
static ID i_match_string
Definition: parser.c:80
int symbolize_names
Definition: parser.h:46
static VALUE cParser_parse_strict(VALUE self)
Definition: parser.c:1737
static const int JSON_string_en_main
Definition: parser.c:1373
#define ALLOC(type)
Definition: ruby.h:1035
static VALUE CNaN
Definition: parser.c:78
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1635
static const int JSON_float_error
Definition: parser.c:876
static ID i_json_create
Definition: parser.c:80
static VALUE cParser_parse_quirks_mode(VALUE self)
Definition: parser.c:1911
static const int JSON_error
Definition: parser.c:1729
VALUE rb_hash_new(void)
Definition: hash.c:229
void ruby_xfree(void *x)
Definition: gc.c:914
static void JSON_free(JSON_Parser *json)
Definition: parser.c:2105
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1415
static const int JSON_float_start
Definition: parser.c:874
static VALUE cParser_quirks_mode_p(VALUE self)
Definition: parser.c:2133
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:3913
unsigned long ID
Definition: ruby.h:89
#define NULL
#define Qnil
Definition: ruby.h:367
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
static char * JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:479
static VALUE mJSON
Definition: parser.c:77
#define FIX2INT(x)
Definition: ruby.h:538
static ID i_key_p
Definition: parser.c:80
register unsigned int len
Definition: name2ctype.h:22210
#define UNI_SUR_HIGH_START
Definition: generator.h:94
VALUE rb_str_dup(VALUE)
Definition: string.c:905
static const int JSON_object_first_final
Definition: parser.c:92
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:606
void Init_parser()
Definition: parser.c:2140
static const int JSON_quirks_mode_first_final
Definition: parser.c:1902
static VALUE mExt
Definition: parser.c:77
static ID i_array_class
Definition: parser.c:80
static const int JSON_integer_en_main
Definition: parser.c:782
static const int JSON_start
Definition: parser.c:1727
static const int JSON_array_start
Definition: parser.c:1037
static const int JSON_integer_first_final
Definition: parser.c:779
static ID i_create_id
Definition: parser.c:80
static const int JSON_object_en_main
Definition: parser.c:95
static VALUE CInfinity
Definition: parser.c:78
static const int JSON_quirks_mode_en_main
Definition: parser.c:1905
static const int JSON_first_final
Definition: parser.c:1728
static char * JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:788
static UTF32 unescape_unicode(const unsigned char *p)
Definition: parser.c:24
VALUE rb_hash_aref(VALUE hash, VALUE key)
Definition: hash.c:508
static const int JSON_array_en_main
Definition: parser.c:1041
#define RTEST(v)
Definition: ruby.h:373
static const char digit_values[256]
Definition: parser.c:7
static const int JSON_string_start
Definition: parser.c:1369
v
Definition: win32ole.c:790
static const int JSON_value_first_final
Definition: parser.c:470
#define UNI_REPLACEMENT_CHAR
Definition: generator.h:88
VALUE rb_ary_new2(long capa)
Definition: array.c:332
static ID i_symbolize_names
Definition: parser.c:80
void rb_gc_mark_maybe(VALUE obj)
Definition: gc.c:1739
static const int JSON_quirks_mode_start
Definition: parser.c:1901
static const int JSON_value_en_main
Definition: parser.c:473
static const int JSON_object_error
Definition: parser.c:93
static ID i_json_creatable_p
Definition: parser.c:80
VALUE array_class
Definition: parser.h:49
static ID i_create_additions
Definition: parser.c:80
#define GET_PARSER
Definition: parser.h:54
VALUE Vsource
Definition: parser.h:37
VALUE match_string
Definition: parser.h:51
static char * JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
Definition: parser.c:884
VALUE rb_str_intern(VALUE)
Definition: string.c:6850
static int match_i(VALUE regexp, VALUE klass, VALUE memo)
Definition: parser.c:1380
static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
Definition: parser.c:1297
static ID i_leftshift
Definition: parser.c:80
VALUE rb_define_module(const char *name)
Definition: class.c:586
#define rb_intern(str)
VALUE rb_str_buf_new(long)
Definition: string.c:736
#define Qundef
Definition: ruby.h:368
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1209
static ID i_quirks_mode
Definition: parser.c:80
VALUE create_id
Definition: parser.h:41
VALUE rb_str_new2(const char *)
VALUE rb_eArgError
Definition: error.c:468
char ** argv
Definition: ruby.c:121
#define StringValue(v)
Definition: ruby.h:466
#define FORCE_UTF8(obj)
Definition: generator.h:22
VALUE rb_str_new(const char *, long)
Definition: string.c:410