Ruby: ext/json/parser/parser.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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