2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
#line 1 "parser.rl"
|
|
|
|
#include "../fbuffer/fbuffer.h"
|
|
|
|
#include "parser.h"
|
|
|
|
|
2015-04-18 02:19:52 -04:00
|
|
|
#if defined HAVE_RUBY_ENCODING_H
|
2016-07-05 07:49:39 -04:00
|
|
|
# define EXC_ENCODING rb_utf8_encoding(),
|
2015-04-18 02:19:52 -04:00
|
|
|
# ifndef HAVE_RB_ENC_RAISE
|
|
|
|
static void
|
|
|
|
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
VALUE mesg;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
mesg = rb_enc_vsprintf(enc, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
rb_exc_raise(rb_exc_new3(exc, mesg));
|
|
|
|
}
|
2015-04-18 02:24:38 -04:00
|
|
|
# define rb_enc_raise enc_raise
|
2015-04-18 02:19:52 -04:00
|
|
|
# endif
|
2015-04-18 02:18:50 -04:00
|
|
|
#else
|
|
|
|
# define EXC_ENCODING /* nothing */
|
2015-04-18 02:19:52 -04:00
|
|
|
# define rb_enc_raise rb_raise
|
2015-04-18 02:18:50 -04:00
|
|
|
#endif
|
|
|
|
|
2015-04-12 04:36:37 -04:00
|
|
|
/* unicode */
|
|
|
|
|
|
|
|
static const char digit_values[256] = {
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1
|
|
|
|
};
|
|
|
|
|
|
|
|
static UTF32 unescape_unicode(const unsigned char *p)
|
|
|
|
{
|
|
|
|
char b;
|
|
|
|
UTF32 result = 0;
|
|
|
|
b = digit_values[p[0]];
|
|
|
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
|
|
result = (result << 4) | (unsigned char)b;
|
|
|
|
b = digit_values[p[1]];
|
|
|
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
|
|
result = (result << 4) | (unsigned char)b;
|
|
|
|
b = digit_values[p[2]];
|
|
|
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
|
|
result = (result << 4) | (unsigned char)b;
|
|
|
|
b = digit_values[p[3]];
|
|
|
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
|
|
result = (result << 4) | (unsigned char)b;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
|
|
{
|
|
|
|
int len = 1;
|
|
|
|
if (ch <= 0x7F) {
|
|
|
|
buf[0] = (char) ch;
|
|
|
|
} else if (ch <= 0x07FF) {
|
|
|
|
buf[0] = (char) ((ch >> 6) | 0xC0);
|
|
|
|
buf[1] = (char) ((ch & 0x3F) | 0x80);
|
|
|
|
len++;
|
|
|
|
} else if (ch <= 0xFFFF) {
|
|
|
|
buf[0] = (char) ((ch >> 12) | 0xE0);
|
|
|
|
buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
|
|
|
|
buf[2] = (char) ((ch & 0x3F) | 0x80);
|
|
|
|
len += 2;
|
|
|
|
} else if (ch <= 0x1fffff) {
|
|
|
|
buf[0] =(char) ((ch >> 18) | 0xF0);
|
|
|
|
buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
|
|
|
|
buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
|
|
|
|
buf[3] =(char) ((ch & 0x3F) | 0x80);
|
|
|
|
len += 3;
|
|
|
|
} else {
|
|
|
|
buf[0] = '?';
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
|
|
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
|
|
|
|
|
|
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
2016-07-05 07:49:39 -04:00
|
|
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
2017-06-15 23:04:46 -04:00
|
|
|
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
|
|
|
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
|
|
|
i_leftshift, i_new;
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 125 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 107 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_object_start = 1};
|
|
|
|
enum {JSON_object_first_final = 27};
|
|
|
|
enum {JSON_object_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_object_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 166 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
VALUE last_name = Qnil;
|
|
|
|
VALUE object_class = json->object_class;
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
if (json->max_nesting && current_nesting > json->max_nesting) {
|
|
|
|
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 131 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_object_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 181 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 138 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if ( (*p) == 123 )
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st2;
|
|
|
|
case 32: goto st2;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 47: goto st23;
|
|
|
|
case 125: goto tr4;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
tr2:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 148 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
char *np;
|
|
|
|
json->parsing_name = 1;
|
|
|
|
np = JSON_parse_string(json, p, pe, &last_name);
|
|
|
|
json->parsing_name = 0;
|
|
|
|
if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
|
|
|
|
}
|
|
|
|
goto st3;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 179 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st3;
|
|
|
|
case 32: goto st3;
|
|
|
|
case 47: goto st4;
|
|
|
|
case 58: goto st8;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st3;
|
|
|
|
goto st0;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st5;
|
|
|
|
case 47: goto st7;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st6;
|
|
|
|
goto st5;
|
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st6;
|
|
|
|
case 47: goto st3;
|
|
|
|
}
|
|
|
|
goto st5;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st3;
|
|
|
|
goto st7;
|
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st8;
|
|
|
|
case 32: goto st8;
|
|
|
|
case 34: goto tr11;
|
|
|
|
case 45: goto tr11;
|
|
|
|
case 47: goto st19;
|
|
|
|
case 73: goto tr11;
|
|
|
|
case 78: goto tr11;
|
|
|
|
case 91: goto tr11;
|
|
|
|
case 102: goto tr11;
|
|
|
|
case 110: goto tr11;
|
|
|
|
case 116: goto tr11;
|
|
|
|
case 123: goto tr11;
|
|
|
|
}
|
|
|
|
if ( (*p) > 10 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto tr11;
|
|
|
|
} else if ( (*p) >= 9 )
|
|
|
|
goto st8;
|
|
|
|
goto st0;
|
|
|
|
tr11:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 133 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
VALUE v = Qnil;
|
2016-07-05 07:49:39 -04:00
|
|
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
2015-04-12 04:36:37 -04:00
|
|
|
if (np == NULL) {
|
|
|
|
p--; {p++; cs = 9; goto _out;}
|
|
|
|
} else {
|
|
|
|
if (NIL_P(json->object_class)) {
|
|
|
|
rb_hash_aset(*result, last_name, v);
|
|
|
|
} else {
|
|
|
|
rb_funcall(*result, i_aset, 2, last_name, v);
|
|
|
|
}
|
|
|
|
{p = (( np))-1;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto st9;
|
|
|
|
st9:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof9;
|
|
|
|
case 9:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 266 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st9;
|
|
|
|
case 32: goto st9;
|
|
|
|
case 44: goto st10;
|
|
|
|
case 47: goto st15;
|
|
|
|
case 125: goto tr4;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st9;
|
|
|
|
goto st0;
|
|
|
|
st10:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof10;
|
|
|
|
case 10:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st10;
|
|
|
|
case 32: goto st10;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 47: goto st11;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st10;
|
|
|
|
goto st0;
|
|
|
|
st11:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof11;
|
|
|
|
case 11:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st12;
|
|
|
|
case 47: goto st14;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st12:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof12;
|
|
|
|
case 12:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st13;
|
|
|
|
goto st12;
|
|
|
|
st13:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof13;
|
|
|
|
case 13:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st13;
|
|
|
|
case 47: goto st10;
|
|
|
|
}
|
|
|
|
goto st12;
|
|
|
|
st14:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof14;
|
|
|
|
case 14:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st10;
|
|
|
|
goto st14;
|
|
|
|
st15:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof15;
|
|
|
|
case 15:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st16;
|
|
|
|
case 47: goto st18;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st16:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof16;
|
|
|
|
case 16:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st17;
|
|
|
|
goto st16;
|
|
|
|
st17:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof17;
|
|
|
|
case 17:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st17;
|
|
|
|
case 47: goto st9;
|
|
|
|
}
|
|
|
|
goto st16;
|
|
|
|
st18:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof18;
|
|
|
|
case 18:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st9;
|
|
|
|
goto st18;
|
|
|
|
tr4:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 156 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{ p--; {p++; cs = 27; goto _out;} }
|
|
|
|
goto st27;
|
|
|
|
st27:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof27;
|
|
|
|
case 27:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 362 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st19:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof19;
|
|
|
|
case 19:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st20;
|
|
|
|
case 47: goto st22;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st20:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof20;
|
|
|
|
case 20:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st21;
|
|
|
|
goto st20;
|
|
|
|
st21:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof21;
|
|
|
|
case 21:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st21;
|
|
|
|
case 47: goto st8;
|
|
|
|
}
|
|
|
|
goto st20;
|
|
|
|
st22:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof22;
|
|
|
|
case 22:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st8;
|
|
|
|
goto st22;
|
|
|
|
st23:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof23;
|
|
|
|
case 23:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st24;
|
|
|
|
case 47: goto st26;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st24:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof24;
|
|
|
|
case 24:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st25;
|
|
|
|
goto st24;
|
|
|
|
st25:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof25;
|
|
|
|
case 25:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st25;
|
|
|
|
case 47: goto st2;
|
|
|
|
}
|
|
|
|
goto st24;
|
|
|
|
st26:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof26;
|
|
|
|
case 26:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st2;
|
|
|
|
goto st26;
|
|
|
|
}
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
|
|
_test_eof11: cs = 11; goto _test_eof;
|
|
|
|
_test_eof12: cs = 12; goto _test_eof;
|
|
|
|
_test_eof13: cs = 13; goto _test_eof;
|
|
|
|
_test_eof14: cs = 14; goto _test_eof;
|
|
|
|
_test_eof15: cs = 15; goto _test_eof;
|
|
|
|
_test_eof16: cs = 16; goto _test_eof;
|
|
|
|
_test_eof17: cs = 17; goto _test_eof;
|
|
|
|
_test_eof18: cs = 18; goto _test_eof;
|
|
|
|
_test_eof27: cs = 27; goto _test_eof;
|
|
|
|
_test_eof19: cs = 19; goto _test_eof;
|
|
|
|
_test_eof20: cs = 20; goto _test_eof;
|
|
|
|
_test_eof21: cs = 21; goto _test_eof;
|
|
|
|
_test_eof22: cs = 22; goto _test_eof;
|
|
|
|
_test_eof23: cs = 23; goto _test_eof;
|
|
|
|
_test_eof24: cs = 24; goto _test_eof;
|
|
|
|
_test_eof25: cs = 25; goto _test_eof;
|
|
|
|
_test_eof26: cs = 26; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 182 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if (cs >= JSON_object_first_final) {
|
|
|
|
if (json->create_additions) {
|
|
|
|
VALUE klassname;
|
|
|
|
if (NIL_P(json->object_class)) {
|
|
|
|
klassname = rb_hash_aref(*result, json->create_id);
|
|
|
|
} else {
|
|
|
|
klassname = rb_funcall(*result, i_aref, 1, json->create_id);
|
|
|
|
}
|
|
|
|
if (!NIL_P(klassname)) {
|
|
|
|
VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
|
|
|
|
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
|
|
|
|
*result = rb_funcall(klass, i_json_create, 1, *result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p + 1;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 485 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_value_start = 1};
|
2016-07-05 07:49:39 -04:00
|
|
|
enum {JSON_value_first_final = 29};
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_value_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_value_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 282 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 501 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_value_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 289 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 508 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
2016-07-05 07:49:39 -04:00
|
|
|
st1:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof1;
|
2015-04-12 04:36:37 -04:00
|
|
|
case 1:
|
|
|
|
switch( (*p) ) {
|
2016-07-05 07:49:39 -04:00
|
|
|
case 13: goto st1;
|
|
|
|
case 32: goto st1;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 45: goto tr3;
|
|
|
|
case 47: goto st6;
|
|
|
|
case 73: goto st10;
|
|
|
|
case 78: goto st17;
|
|
|
|
case 91: goto tr7;
|
|
|
|
case 102: goto st19;
|
|
|
|
case 110: goto st23;
|
|
|
|
case 116: goto st26;
|
|
|
|
case 123: goto tr11;
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) > 10 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto tr3;
|
|
|
|
} else if ( (*p) >= 9 )
|
|
|
|
goto st1;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
2016-07-05 07:49:39 -04:00
|
|
|
tr2:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 234 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
char *np = JSON_parse_string(json, p, pe, result);
|
2016-07-05 07:49:39 -04:00
|
|
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr3:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 239 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
char *np;
|
2016-07-05 07:49:39 -04:00
|
|
|
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
2015-04-12 04:36:37 -04:00
|
|
|
if (json->allow_nan) {
|
|
|
|
*result = CMinusInfinity;
|
|
|
|
{p = (( p + 10))-1;}
|
2016-07-05 07:49:39 -04:00
|
|
|
p--; {p++; cs = 29; goto _out;}
|
2015-04-12 04:36:37 -04:00
|
|
|
} else {
|
2015-04-18 02:18:50 -04:00
|
|
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
np = JSON_parse_float(json, p, pe, result);
|
|
|
|
if (np != NULL) {p = (( np))-1;}
|
|
|
|
np = JSON_parse_integer(json, p, pe, result);
|
|
|
|
if (np != NULL) {p = (( np))-1;}
|
2016-07-05 07:49:39 -04:00
|
|
|
p--; {p++; cs = 29; goto _out;}
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr7:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 257 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
char *np;
|
2016-07-05 07:49:39 -04:00
|
|
|
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
|
|
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr11:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 263 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
char *np;
|
2016-07-05 07:49:39 -04:00
|
|
|
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
|
|
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr25:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 227 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if (json->allow_nan) {
|
|
|
|
*result = CInfinity;
|
|
|
|
} else {
|
2015-04-18 02:18:50 -04:00
|
|
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr27:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 220 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if (json->allow_nan) {
|
|
|
|
*result = CNaN;
|
|
|
|
} else {
|
2015-04-18 02:18:50 -04:00
|
|
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr31:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 214 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
*result = Qfalse;
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr34:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 211 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
*result = Qnil;
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
tr37:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 217 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
*result = Qtrue;
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st29;
|
|
|
|
st29:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof29;
|
|
|
|
case 29:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 269 "parser.rl"
|
2016-07-05 07:49:39 -04:00
|
|
|
{ p--; {p++; cs = 29; goto _out;} }
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 628 "parser.c"
|
2016-07-05 07:49:39 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st29;
|
|
|
|
case 32: goto st29;
|
|
|
|
case 47: goto st2;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st29;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
2016-07-05 07:49:39 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st3;
|
|
|
|
case 47: goto st5;
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 42 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st4;
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st3;
|
2015-04-12 04:36:37 -04:00
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
2016-07-05 07:49:39 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st4;
|
|
|
|
case 47: goto st29;
|
|
|
|
}
|
|
|
|
goto st3;
|
2015-04-12 04:36:37 -04:00
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st29;
|
|
|
|
goto st5;
|
2015-04-12 04:36:37 -04:00
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
2016-07-05 07:49:39 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st7;
|
|
|
|
case 47: goto st9;
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 42 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st8;
|
2016-07-05 07:49:39 -04:00
|
|
|
goto st7;
|
2015-04-12 04:36:37 -04:00
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
2016-07-05 07:49:39 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st8;
|
|
|
|
case 47: goto st1;
|
|
|
|
}
|
|
|
|
goto st7;
|
2015-04-12 04:36:37 -04:00
|
|
|
st9:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof9;
|
|
|
|
case 9:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st1;
|
|
|
|
goto st9;
|
2015-04-12 04:36:37 -04:00
|
|
|
st10:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof10;
|
|
|
|
case 10:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 110 )
|
|
|
|
goto st11;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st11:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof11;
|
|
|
|
case 11:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 102 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st12;
|
|
|
|
goto st0;
|
|
|
|
st12:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof12;
|
|
|
|
case 12:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 105 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st13;
|
|
|
|
goto st0;
|
|
|
|
st13:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof13;
|
|
|
|
case 13:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 110 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st14;
|
|
|
|
goto st0;
|
|
|
|
st14:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof14;
|
|
|
|
case 14:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 105 )
|
|
|
|
goto st15;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st15:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof15;
|
|
|
|
case 15:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 116 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st16;
|
|
|
|
goto st0;
|
|
|
|
st16:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof16;
|
|
|
|
case 16:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 121 )
|
|
|
|
goto tr25;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st17:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof17;
|
|
|
|
case 17:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 97 )
|
|
|
|
goto st18;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st18:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof18;
|
|
|
|
case 18:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 78 )
|
|
|
|
goto tr27;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st19:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof19;
|
|
|
|
case 19:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 97 )
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st20;
|
|
|
|
goto st0;
|
|
|
|
st20:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof20;
|
|
|
|
case 20:
|
2016-07-05 07:49:39 -04:00
|
|
|
if ( (*p) == 108 )
|
|
|
|
goto st21;
|
|
|
|
goto st0;
|
|
|
|
st21:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof21;
|
|
|
|
case 21:
|
|
|
|
if ( (*p) == 115 )
|
|
|
|
goto st22;
|
|
|
|
goto st0;
|
|
|
|
st22:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof22;
|
|
|
|
case 22:
|
2015-04-12 04:36:37 -04:00
|
|
|
if ( (*p) == 101 )
|
2016-07-05 07:49:39 -04:00
|
|
|
goto tr31;
|
|
|
|
goto st0;
|
|
|
|
st23:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof23;
|
|
|
|
case 23:
|
|
|
|
if ( (*p) == 117 )
|
|
|
|
goto st24;
|
|
|
|
goto st0;
|
|
|
|
st24:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof24;
|
|
|
|
case 24:
|
|
|
|
if ( (*p) == 108 )
|
|
|
|
goto st25;
|
|
|
|
goto st0;
|
|
|
|
st25:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof25;
|
|
|
|
case 25:
|
|
|
|
if ( (*p) == 108 )
|
|
|
|
goto tr34;
|
|
|
|
goto st0;
|
|
|
|
st26:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof26;
|
|
|
|
case 26:
|
|
|
|
if ( (*p) == 114 )
|
|
|
|
goto st27;
|
|
|
|
goto st0;
|
|
|
|
st27:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof27;
|
|
|
|
case 27:
|
|
|
|
if ( (*p) == 117 )
|
|
|
|
goto st28;
|
|
|
|
goto st0;
|
|
|
|
st28:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof28;
|
|
|
|
case 28:
|
|
|
|
if ( (*p) == 101 )
|
|
|
|
goto tr37;
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
_test_eof1: cs = 1; goto _test_eof;
|
|
|
|
_test_eof29: cs = 29; goto _test_eof;
|
2015-04-12 04:36:37 -04:00
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
|
|
_test_eof11: cs = 11; goto _test_eof;
|
|
|
|
_test_eof12: cs = 12; goto _test_eof;
|
|
|
|
_test_eof13: cs = 13; goto _test_eof;
|
|
|
|
_test_eof14: cs = 14; goto _test_eof;
|
|
|
|
_test_eof15: cs = 15; goto _test_eof;
|
|
|
|
_test_eof16: cs = 16; goto _test_eof;
|
|
|
|
_test_eof17: cs = 17; goto _test_eof;
|
|
|
|
_test_eof18: cs = 18; goto _test_eof;
|
|
|
|
_test_eof19: cs = 19; goto _test_eof;
|
|
|
|
_test_eof20: cs = 20; goto _test_eof;
|
2016-07-05 07:49:39 -04:00
|
|
|
_test_eof21: cs = 21; goto _test_eof;
|
|
|
|
_test_eof22: cs = 22; goto _test_eof;
|
|
|
|
_test_eof23: cs = 23; goto _test_eof;
|
|
|
|
_test_eof24: cs = 24; goto _test_eof;
|
|
|
|
_test_eof25: cs = 25; goto _test_eof;
|
|
|
|
_test_eof26: cs = 26; goto _test_eof;
|
|
|
|
_test_eof27: cs = 27; goto _test_eof;
|
|
|
|
_test_eof28: cs = 28; goto _test_eof;
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 290 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if (cs >= JSON_value_first_final) {
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 879 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_integer_start = 1};
|
|
|
|
enum {JSON_integer_first_final = 3};
|
|
|
|
enum {JSON_integer_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_integer_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 306 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 895 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_integer_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 313 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
json->memo = p;
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 903 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 45: goto st2;
|
|
|
|
case 48: goto st3;
|
|
|
|
}
|
|
|
|
if ( 49 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st5;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
if ( (*p) == 48 )
|
|
|
|
goto st3;
|
|
|
|
if ( 49 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st5;
|
|
|
|
goto st0;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st0;
|
|
|
|
goto tr4;
|
|
|
|
tr4:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 303 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{ p--; {p++; cs = 4; goto _out;} }
|
|
|
|
goto st4;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 944 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st5;
|
|
|
|
goto tr4;
|
|
|
|
}
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 315 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if (cs >= JSON_integer_first_final) {
|
|
|
|
long len = p - json->memo;
|
|
|
|
fbuffer_clear(json->fbuffer);
|
|
|
|
fbuffer_append(json->fbuffer, json->memo, len);
|
|
|
|
fbuffer_append_char(json->fbuffer, '\0');
|
|
|
|
*result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
|
|
|
|
return p + 1;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 978 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_float_start = 1};
|
|
|
|
enum {JSON_float_first_final = 8};
|
|
|
|
enum {JSON_float_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_float_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 340 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 994 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_float_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 347 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
json->memo = p;
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1002 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 45: goto st2;
|
|
|
|
case 48: goto st3;
|
|
|
|
}
|
|
|
|
if ( 49 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st7;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
if ( (*p) == 48 )
|
|
|
|
goto st3;
|
|
|
|
if ( 49 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st7;
|
|
|
|
goto st0;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 46: goto st4;
|
|
|
|
case 69: goto st5;
|
|
|
|
case 101: goto st5;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st8;
|
|
|
|
goto st0;
|
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 69: goto st5;
|
|
|
|
case 101: goto st5;
|
|
|
|
}
|
|
|
|
if ( (*p) > 46 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st8;
|
|
|
|
} else if ( (*p) >= 45 )
|
|
|
|
goto st0;
|
|
|
|
goto tr9;
|
|
|
|
tr9:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 334 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{ p--; {p++; cs = 9; goto _out;} }
|
|
|
|
goto st9;
|
|
|
|
st9:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof9;
|
|
|
|
case 9:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1067 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 43: goto st6;
|
|
|
|
case 45: goto st6;
|
|
|
|
}
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st10;
|
|
|
|
goto st0;
|
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st10;
|
|
|
|
goto st0;
|
|
|
|
st10:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof10;
|
|
|
|
case 10:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 69: goto st0;
|
|
|
|
case 101: goto st0;
|
|
|
|
}
|
|
|
|
if ( (*p) > 46 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st10;
|
|
|
|
} else if ( (*p) >= 45 )
|
|
|
|
goto st0;
|
|
|
|
goto tr9;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 46: goto st4;
|
|
|
|
case 69: goto st5;
|
|
|
|
case 101: goto st5;
|
|
|
|
}
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st7;
|
|
|
|
goto st0;
|
|
|
|
}
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 349 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if (cs >= JSON_float_first_final) {
|
|
|
|
long len = p - json->memo;
|
|
|
|
fbuffer_clear(json->fbuffer);
|
|
|
|
fbuffer_append(json->fbuffer, json->memo, len);
|
|
|
|
fbuffer_append_char(json->fbuffer, '\0');
|
2017-06-15 23:04:46 -04:00
|
|
|
if (NIL_P(json->decimal_class)) {
|
|
|
|
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
|
|
|
} else {
|
|
|
|
VALUE text;
|
|
|
|
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
|
|
|
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
return p + 1;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1150 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_array_start = 1};
|
|
|
|
enum {JSON_array_first_final = 17};
|
|
|
|
enum {JSON_array_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_array_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 398 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
VALUE array_class = json->array_class;
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
if (json->max_nesting && current_nesting > json->max_nesting) {
|
|
|
|
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1172 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_array_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 411 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1179 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if ( (*p) == 91 )
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st2;
|
|
|
|
case 32: goto st2;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 45: goto tr2;
|
|
|
|
case 47: goto st13;
|
|
|
|
case 73: goto tr2;
|
|
|
|
case 78: goto tr2;
|
|
|
|
case 91: goto tr2;
|
|
|
|
case 93: goto tr4;
|
|
|
|
case 102: goto tr2;
|
|
|
|
case 110: goto tr2;
|
|
|
|
case 116: goto tr2;
|
|
|
|
case 123: goto tr2;
|
|
|
|
}
|
|
|
|
if ( (*p) > 10 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto tr2;
|
|
|
|
} else if ( (*p) >= 9 )
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
tr2:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 375 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
VALUE v = Qnil;
|
2016-07-05 07:49:39 -04:00
|
|
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
2015-04-12 04:36:37 -04:00
|
|
|
if (np == NULL) {
|
|
|
|
p--; {p++; cs = 3; goto _out;}
|
|
|
|
} else {
|
|
|
|
if (NIL_P(json->array_class)) {
|
|
|
|
rb_ary_push(*result, v);
|
|
|
|
} else {
|
|
|
|
rb_funcall(*result, i_leftshift, 1, v);
|
|
|
|
}
|
|
|
|
{p = (( np))-1;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto st3;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1238 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st3;
|
|
|
|
case 32: goto st3;
|
|
|
|
case 44: goto st4;
|
|
|
|
case 47: goto st9;
|
|
|
|
case 93: goto tr4;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st3;
|
|
|
|
goto st0;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st4;
|
|
|
|
case 32: goto st4;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 45: goto tr2;
|
|
|
|
case 47: goto st5;
|
|
|
|
case 73: goto tr2;
|
|
|
|
case 78: goto tr2;
|
|
|
|
case 91: goto tr2;
|
|
|
|
case 102: goto tr2;
|
|
|
|
case 110: goto tr2;
|
|
|
|
case 116: goto tr2;
|
|
|
|
case 123: goto tr2;
|
|
|
|
}
|
|
|
|
if ( (*p) > 10 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto tr2;
|
|
|
|
} else if ( (*p) >= 9 )
|
|
|
|
goto st4;
|
|
|
|
goto st0;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st6;
|
|
|
|
case 47: goto st8;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st7;
|
|
|
|
goto st6;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st7;
|
|
|
|
case 47: goto st4;
|
|
|
|
}
|
|
|
|
goto st6;
|
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st4;
|
|
|
|
goto st8;
|
|
|
|
st9:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof9;
|
|
|
|
case 9:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st10;
|
|
|
|
case 47: goto st12;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st10:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof10;
|
|
|
|
case 10:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st11;
|
|
|
|
goto st10;
|
|
|
|
st11:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof11;
|
|
|
|
case 11:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st11;
|
|
|
|
case 47: goto st3;
|
|
|
|
}
|
|
|
|
goto st10;
|
|
|
|
st12:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof12;
|
|
|
|
case 12:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st3;
|
|
|
|
goto st12;
|
|
|
|
tr4:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 390 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{ p--; {p++; cs = 17; goto _out;} }
|
|
|
|
goto st17;
|
|
|
|
st17:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof17;
|
|
|
|
case 17:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1345 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st13:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof13;
|
|
|
|
case 13:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st14;
|
|
|
|
case 47: goto st16;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st14:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof14;
|
|
|
|
case 14:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st15;
|
|
|
|
goto st14;
|
|
|
|
st15:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof15;
|
|
|
|
case 15:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st15;
|
|
|
|
case 47: goto st2;
|
|
|
|
}
|
|
|
|
goto st14;
|
|
|
|
st16:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof16;
|
|
|
|
case 16:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st2;
|
|
|
|
goto st16;
|
|
|
|
}
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
|
|
_test_eof11: cs = 11; goto _test_eof;
|
|
|
|
_test_eof12: cs = 12; goto _test_eof;
|
|
|
|
_test_eof17: cs = 17; goto _test_eof;
|
|
|
|
_test_eof13: cs = 13; goto _test_eof;
|
|
|
|
_test_eof14: cs = 14; goto _test_eof;
|
|
|
|
_test_eof15: cs = 15; goto _test_eof;
|
|
|
|
_test_eof16: cs = 16; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 412 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if(cs >= JSON_array_first_final) {
|
|
|
|
return p + 1;
|
|
|
|
} else {
|
2015-04-18 02:18:50 -04:00
|
|
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
2015-04-12 04:36:37 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
|
|
{
|
|
|
|
char *p = string, *pe = string, *unescape;
|
|
|
|
int unescape_len;
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
while (pe < stringEnd) {
|
|
|
|
if (*pe == '\\') {
|
|
|
|
unescape = (char *) "?";
|
|
|
|
unescape_len = 1;
|
|
|
|
if (pe > p) rb_str_buf_cat(result, p, pe - p);
|
|
|
|
switch (*++pe) {
|
|
|
|
case 'n':
|
|
|
|
unescape = (char *) "\n";
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
unescape = (char *) "\r";
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
unescape = (char *) "\t";
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
unescape = (char *) "\"";
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
unescape = (char *) "\\";
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
unescape = (char *) "\b";
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
unescape = (char *) "\f";
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
if (pe > stringEnd - 4) {
|
2017-04-11 20:21:18 -04:00
|
|
|
rb_enc_raise(
|
|
|
|
EXC_ENCODING eParserError,
|
|
|
|
"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
|
|
|
|
);
|
2015-04-12 04:36:37 -04:00
|
|
|
} else {
|
|
|
|
UTF32 ch = unescape_unicode((unsigned char *) ++pe);
|
|
|
|
pe += 3;
|
|
|
|
if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
|
|
|
|
pe++;
|
2017-04-11 20:21:18 -04:00
|
|
|
if (pe > stringEnd - 6) {
|
|
|
|
rb_enc_raise(
|
|
|
|
EXC_ENCODING eParserError,
|
|
|
|
"%u: incomplete surrogate pair at '%s'", __LINE__, p
|
|
|
|
);
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
if (pe[0] == '\\' && pe[1] == 'u') {
|
|
|
|
UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
|
|
|
|
ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
|
|
|
|
| (sur & 0x3FF));
|
|
|
|
pe += 5;
|
|
|
|
} else {
|
|
|
|
unescape = (char *) "?";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unescape_len = convert_UTF32_to_UTF8(buf, ch);
|
|
|
|
unescape = buf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p = pe;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rb_str_buf_cat(result, unescape, unescape_len);
|
|
|
|
p = ++pe;
|
|
|
|
} else {
|
|
|
|
pe++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_str_buf_cat(result, p, pe - p);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1490 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_string_start = 1};
|
|
|
|
enum {JSON_string_first_final = 8};
|
|
|
|
enum {JSON_string_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_string_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 519 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
match_i(VALUE regexp, VALUE klass, VALUE memo)
|
|
|
|
{
|
|
|
|
if (regexp == Qundef) return ST_STOP;
|
|
|
|
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
|
|
|
|
RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
|
|
|
|
rb_ary_push(memo, klass);
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
|
|
{
|
|
|
|
int cs = EVIL;
|
|
|
|
VALUE match_string;
|
|
|
|
|
|
|
|
*result = rb_str_buf_new(0);
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1520 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_string_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 540 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
json->memo = p;
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1528 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if ( (*p) == 34 )
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 92: goto st3;
|
|
|
|
}
|
|
|
|
if ( 0 <= (*p) && (*p) <= 31 )
|
|
|
|
goto st0;
|
|
|
|
goto st2;
|
|
|
|
tr2:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 505 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
|
|
|
if (NIL_P(*result)) {
|
|
|
|
p--;
|
|
|
|
{p++; cs = 8; goto _out;}
|
|
|
|
} else {
|
|
|
|
FORCE_UTF8(*result);
|
|
|
|
{p = (( p + 1))-1;}
|
|
|
|
}
|
|
|
|
}
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 516 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{ p--; {p++; cs = 8; goto _out;} }
|
|
|
|
goto st8;
|
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1571 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
goto st0;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
|
|
|
if ( (*p) == 117 )
|
|
|
|
goto st4;
|
|
|
|
if ( 0 <= (*p) && (*p) <= 31 )
|
|
|
|
goto st0;
|
|
|
|
goto st2;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
|
|
|
if ( (*p) < 65 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st5;
|
|
|
|
} else if ( (*p) > 70 ) {
|
|
|
|
if ( 97 <= (*p) && (*p) <= 102 )
|
|
|
|
goto st5;
|
|
|
|
} else
|
|
|
|
goto st5;
|
|
|
|
goto st0;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
if ( (*p) < 65 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st6;
|
|
|
|
} else if ( (*p) > 70 ) {
|
|
|
|
if ( 97 <= (*p) && (*p) <= 102 )
|
|
|
|
goto st6;
|
|
|
|
} else
|
|
|
|
goto st6;
|
|
|
|
goto st0;
|
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
|
|
|
if ( (*p) < 65 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st7;
|
|
|
|
} else if ( (*p) > 70 ) {
|
|
|
|
if ( 97 <= (*p) && (*p) <= 102 )
|
|
|
|
goto st7;
|
|
|
|
} else
|
|
|
|
goto st7;
|
|
|
|
goto st0;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
|
|
|
if ( (*p) < 65 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto st2;
|
|
|
|
} else if ( (*p) > 70 ) {
|
|
|
|
if ( 97 <= (*p) && (*p) <= 102 )
|
|
|
|
goto st2;
|
|
|
|
} else
|
|
|
|
goto st2;
|
|
|
|
goto st0;
|
|
|
|
}
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 542 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
|
|
|
VALUE klass;
|
|
|
|
VALUE memo = rb_ary_new2(2);
|
|
|
|
rb_ary_push(memo, *result);
|
|
|
|
rb_hash_foreach(match_string, match_i, memo);
|
|
|
|
klass = rb_ary_entry(memo, 1);
|
|
|
|
if (RTEST(klass)) {
|
|
|
|
*result = rb_funcall(klass, i_json_create, 1, *result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (json->symbolize_names && json->parsing_name) {
|
|
|
|
*result = rb_str_intern(*result);
|
2016-07-05 07:49:39 -04:00
|
|
|
} else {
|
|
|
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
if (cs >= JSON_string_first_final) {
|
|
|
|
return p + 1;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: JSON::Ext::Parser
|
|
|
|
*
|
|
|
|
* This is the JSON parser implemented as a C extension. It can be configured
|
|
|
|
* to be used by setting
|
|
|
|
*
|
|
|
|
* JSON.parser = JSON::Ext::Parser
|
|
|
|
*
|
|
|
|
* with the method parser= in JSON.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE convert_encoding(VALUE source)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_RUBY_ENCODING_H
|
2016-07-05 07:49:39 -04:00
|
|
|
rb_encoding *enc = rb_enc_get(source);
|
|
|
|
if (enc == rb_ascii8bit_encoding()) {
|
2016-07-31 23:16:30 -04:00
|
|
|
if (OBJ_FROZEN(source)) {
|
|
|
|
source = rb_str_dup(source);
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
FORCE_UTF8(source);
|
|
|
|
} else {
|
2017-04-11 20:21:18 -04:00
|
|
|
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
|
2016-07-05 07:49:39 -04:00
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
#endif
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: new(source, opts => {})
|
|
|
|
*
|
|
|
|
* Creates a new JSON::Ext::Parser instance for the string _source_.
|
|
|
|
*
|
|
|
|
* Creates a new JSON::Ext::Parser instance for the string _source_.
|
|
|
|
*
|
|
|
|
* It will be configured by the _opts_ hash. _opts_ can have the following
|
|
|
|
* keys:
|
|
|
|
*
|
|
|
|
* _opts_ can have the following keys:
|
|
|
|
* * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
|
|
|
* structures. Disable depth checking with :max_nesting => false|nil|0, it
|
|
|
|
* defaults to 100.
|
|
|
|
* * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
|
|
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
|
|
|
* false.
|
|
|
|
* * *symbolize_names*: If set to true, returns symbols for the names
|
2016-07-05 07:49:39 -04:00
|
|
|
* (keys) in a JSON object. Otherwise strings are returned, which is
|
|
|
|
* also the default. It's not possible to use this option in
|
|
|
|
* conjunction with the *create_additions* option.
|
2015-04-12 04:36:37 -04:00
|
|
|
* * *create_additions*: If set to false, the Parser doesn't create
|
|
|
|
* additions even if a matching class and create_id was found. This option
|
|
|
|
* defaults to false.
|
|
|
|
* * *object_class*: Defaults to Hash
|
|
|
|
* * *array_class*: Defaults to Array
|
|
|
|
*/
|
|
|
|
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE source, opts;
|
|
|
|
GET_PARSER_INIT;
|
|
|
|
|
|
|
|
if (json->Vsource) {
|
|
|
|
rb_raise(rb_eTypeError, "already initialized instance");
|
|
|
|
}
|
2015-09-25 04:08:58 -04:00
|
|
|
#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
|
|
|
rb_scan_args(argc, argv, "1:", &source, &opts);
|
|
|
|
#else
|
2015-04-12 04:36:37 -04:00
|
|
|
rb_scan_args(argc, argv, "11", &source, &opts);
|
2015-09-25 04:08:58 -04:00
|
|
|
#endif
|
2015-04-12 04:36:37 -04:00
|
|
|
if (!NIL_P(opts)) {
|
2015-09-25 04:08:58 -04:00
|
|
|
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
2015-04-12 04:36:37 -04:00
|
|
|
opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
|
|
|
|
if (NIL_P(opts)) {
|
|
|
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
|
|
|
} else {
|
2015-09-25 04:08:58 -04:00
|
|
|
#endif
|
2015-04-12 04:36:37 -04:00
|
|
|
VALUE tmp = ID2SYM(i_max_nesting);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
|
|
|
if (RTEST(max_nesting)) {
|
|
|
|
Check_Type(max_nesting, T_FIXNUM);
|
|
|
|
json->max_nesting = FIX2INT(max_nesting);
|
|
|
|
} else {
|
|
|
|
json->max_nesting = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
json->max_nesting = 100;
|
|
|
|
}
|
|
|
|
tmp = ID2SYM(i_allow_nan);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
json->allow_nan = 0;
|
|
|
|
}
|
|
|
|
tmp = ID2SYM(i_symbolize_names);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
json->symbolize_names = 0;
|
|
|
|
}
|
|
|
|
tmp = ID2SYM(i_create_additions);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->create_additions = RTEST(rb_hash_aref(opts, tmp));
|
|
|
|
} else {
|
|
|
|
json->create_additions = 0;
|
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
if (json->symbolize_names && json->create_additions) {
|
|
|
|
rb_raise(rb_eArgError,
|
|
|
|
"options :symbolize_names and :create_additions cannot be "
|
|
|
|
" used in conjunction");
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
tmp = ID2SYM(i_create_id);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->create_id = rb_hash_aref(opts, tmp);
|
|
|
|
} else {
|
|
|
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
|
|
|
}
|
|
|
|
tmp = ID2SYM(i_object_class);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->object_class = rb_hash_aref(opts, tmp);
|
|
|
|
} else {
|
|
|
|
json->object_class = Qnil;
|
|
|
|
}
|
|
|
|
tmp = ID2SYM(i_array_class);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->array_class = rb_hash_aref(opts, tmp);
|
|
|
|
} else {
|
|
|
|
json->array_class = Qnil;
|
|
|
|
}
|
2017-06-15 23:04:46 -04:00
|
|
|
tmp = ID2SYM(i_decimal_class);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
json->decimal_class = rb_hash_aref(opts, tmp);
|
|
|
|
} else {
|
|
|
|
json->decimal_class = Qnil;
|
|
|
|
}
|
2015-04-12 04:36:37 -04:00
|
|
|
tmp = ID2SYM(i_match_string);
|
|
|
|
if (option_given_p(opts, tmp)) {
|
|
|
|
VALUE match_string = rb_hash_aref(opts, tmp);
|
|
|
|
json->match_string = RTEST(match_string) ? match_string : Qnil;
|
|
|
|
} else {
|
|
|
|
json->match_string = Qnil;
|
|
|
|
}
|
2015-09-25 04:08:58 -04:00
|
|
|
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2015-09-25 04:08:58 -04:00
|
|
|
#endif
|
2015-04-12 04:36:37 -04:00
|
|
|
} else {
|
|
|
|
json->max_nesting = 100;
|
|
|
|
json->allow_nan = 0;
|
|
|
|
json->create_additions = 1;
|
|
|
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
|
|
|
json->object_class = Qnil;
|
|
|
|
json->array_class = Qnil;
|
2017-06-15 23:04:46 -04:00
|
|
|
json->decimal_class = Qnil;
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
2016-07-05 07:49:39 -04:00
|
|
|
source = convert_encoding(StringValue(source));
|
2015-04-18 02:18:37 -04:00
|
|
|
StringValue(source);
|
2015-04-12 04:36:37 -04:00
|
|
|
json->len = RSTRING_LEN(source);
|
|
|
|
json->source = RSTRING_PTR(source);;
|
|
|
|
json->Vsource = source;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1834 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
enum {JSON_start = 1};
|
|
|
|
enum {JSON_first_final = 10};
|
|
|
|
enum {JSON_error = 0};
|
|
|
|
|
|
|
|
enum {JSON_en_main = 1};
|
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 742 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
/*
|
|
|
|
* call-seq: parse()
|
|
|
|
*
|
|
|
|
* Parses the current JSON text _source_ and returns the complete data
|
|
|
|
* structure as a result.
|
|
|
|
*/
|
|
|
|
static VALUE cParser_parse(VALUE self)
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
2016-07-05 07:49:39 -04:00
|
|
|
char *p, *pe;
|
|
|
|
int cs = EVIL;
|
|
|
|
VALUE result = Qnil;
|
|
|
|
GET_PARSER;
|
2015-04-12 04:36:37 -04:00
|
|
|
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1859 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
cs = JSON_start;
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 758 "parser.rl"
|
2016-07-05 07:49:39 -04:00
|
|
|
p = json->source;
|
|
|
|
pe = p + json->len;
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1868 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
|
|
|
if ( p == pe )
|
|
|
|
goto _test_eof;
|
|
|
|
switch ( cs )
|
|
|
|
{
|
|
|
|
st1:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof1;
|
|
|
|
case 1:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st1;
|
|
|
|
case 32: goto st1;
|
|
|
|
case 34: goto tr2;
|
|
|
|
case 45: goto tr2;
|
|
|
|
case 47: goto st6;
|
|
|
|
case 73: goto tr2;
|
|
|
|
case 78: goto tr2;
|
|
|
|
case 91: goto tr2;
|
|
|
|
case 102: goto tr2;
|
|
|
|
case 110: goto tr2;
|
|
|
|
case 116: goto tr2;
|
|
|
|
case 123: goto tr2;
|
|
|
|
}
|
|
|
|
if ( (*p) > 10 ) {
|
|
|
|
if ( 48 <= (*p) && (*p) <= 57 )
|
|
|
|
goto tr2;
|
|
|
|
} else if ( (*p) >= 9 )
|
|
|
|
goto st1;
|
|
|
|
goto st0;
|
|
|
|
st0:
|
|
|
|
cs = 0;
|
|
|
|
goto _out;
|
|
|
|
tr2:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 734 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
{
|
2016-07-05 07:49:39 -04:00
|
|
|
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
2015-04-12 04:36:37 -04:00
|
|
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
|
|
|
}
|
|
|
|
goto st10;
|
|
|
|
st10:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof10;
|
|
|
|
case 10:
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 1912 "parser.c"
|
2015-04-12 04:36:37 -04:00
|
|
|
switch( (*p) ) {
|
|
|
|
case 13: goto st10;
|
|
|
|
case 32: goto st10;
|
|
|
|
case 47: goto st2;
|
|
|
|
}
|
|
|
|
if ( 9 <= (*p) && (*p) <= 10 )
|
|
|
|
goto st10;
|
|
|
|
goto st0;
|
|
|
|
st2:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof2;
|
|
|
|
case 2:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st3;
|
|
|
|
case 47: goto st5;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st3:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof3;
|
|
|
|
case 3:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st4;
|
|
|
|
goto st3;
|
|
|
|
st4:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof4;
|
|
|
|
case 4:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st4;
|
|
|
|
case 47: goto st10;
|
|
|
|
}
|
|
|
|
goto st3;
|
|
|
|
st5:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof5;
|
|
|
|
case 5:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st10;
|
|
|
|
goto st5;
|
|
|
|
st6:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof6;
|
|
|
|
case 6:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st7;
|
|
|
|
case 47: goto st9;
|
|
|
|
}
|
|
|
|
goto st0;
|
|
|
|
st7:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof7;
|
|
|
|
case 7:
|
|
|
|
if ( (*p) == 42 )
|
|
|
|
goto st8;
|
|
|
|
goto st7;
|
|
|
|
st8:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof8;
|
|
|
|
case 8:
|
|
|
|
switch( (*p) ) {
|
|
|
|
case 42: goto st8;
|
|
|
|
case 47: goto st1;
|
|
|
|
}
|
|
|
|
goto st7;
|
|
|
|
st9:
|
|
|
|
if ( ++p == pe )
|
|
|
|
goto _test_eof9;
|
|
|
|
case 9:
|
|
|
|
if ( (*p) == 10 )
|
|
|
|
goto st1;
|
|
|
|
goto st9;
|
|
|
|
}
|
|
|
|
_test_eof1: cs = 1; goto _test_eof;
|
|
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
|
|
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:04:46 -04:00
|
|
|
#line 761 "parser.rl"
|
2015-04-12 04:36:37 -04:00
|
|
|
|
2016-07-05 07:49:39 -04:00
|
|
|
if (cs >= JSON_first_final && p == pe) {
|
|
|
|
return result;
|
2015-04-12 04:36:37 -04:00
|
|
|
} else {
|
2016-07-05 07:49:39 -04:00
|
|
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
|
|
|
return Qnil;
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void JSON_mark(void *ptr)
|
|
|
|
{
|
|
|
|
JSON_Parser *json = ptr;
|
|
|
|
rb_gc_mark_maybe(json->Vsource);
|
|
|
|
rb_gc_mark_maybe(json->create_id);
|
|
|
|
rb_gc_mark_maybe(json->object_class);
|
|
|
|
rb_gc_mark_maybe(json->array_class);
|
2017-06-15 23:04:46 -04:00
|
|
|
rb_gc_mark_maybe(json->decimal_class);
|
2015-04-12 04:36:37 -04:00
|
|
|
rb_gc_mark_maybe(json->match_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void JSON_free(void *ptr)
|
|
|
|
{
|
|
|
|
JSON_Parser *json = ptr;
|
|
|
|
fbuffer_free(json->fbuffer);
|
|
|
|
ruby_xfree(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t JSON_memsize(const void *ptr)
|
|
|
|
{
|
|
|
|
const JSON_Parser *json = ptr;
|
|
|
|
return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEW_TYPEDDATA_WRAPPER
|
|
|
|
static const rb_data_type_t JSON_Parser_type = {
|
|
|
|
"JSON/Parser",
|
|
|
|
{JSON_mark, JSON_free, JSON_memsize,},
|
|
|
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
|
|
|
0, 0,
|
|
|
|
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE cJSON_parser_s_allocate(VALUE klass)
|
|
|
|
{
|
2015-05-28 03:17:42 -04:00
|
|
|
JSON_Parser *json;
|
|
|
|
VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
|
|
|
|
json->fbuffer = fbuffer_alloc(0);
|
|
|
|
return obj;
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: source()
|
|
|
|
*
|
|
|
|
* Returns a copy of the current _source_ string, that was used to construct
|
|
|
|
* this Parser.
|
|
|
|
*/
|
|
|
|
static VALUE cParser_source(VALUE self)
|
|
|
|
{
|
|
|
|
GET_PARSER;
|
|
|
|
return rb_str_dup(json->Vsource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init_parser(void)
|
|
|
|
{
|
|
|
|
rb_require("json/common");
|
|
|
|
mJSON = rb_define_module("JSON");
|
|
|
|
mExt = rb_define_module_under(mJSON, "Ext");
|
|
|
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
|
|
|
eParserError = rb_path2class("JSON::ParserError");
|
|
|
|
eNestingError = rb_path2class("JSON::NestingError");
|
|
|
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
|
|
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
|
|
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
|
|
|
rb_define_method(cParser, "source", cParser_source, 0);
|
|
|
|
|
|
|
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
|
|
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
|
|
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
|
|
|
|
|
|
|
i_json_creatable_p = rb_intern("json_creatable?");
|
|
|
|
i_json_create = rb_intern("json_create");
|
|
|
|
i_create_id = rb_intern("create_id");
|
|
|
|
i_create_additions = rb_intern("create_additions");
|
|
|
|
i_chr = rb_intern("chr");
|
|
|
|
i_max_nesting = rb_intern("max_nesting");
|
|
|
|
i_allow_nan = rb_intern("allow_nan");
|
|
|
|
i_symbolize_names = rb_intern("symbolize_names");
|
|
|
|
i_object_class = rb_intern("object_class");
|
|
|
|
i_array_class = rb_intern("array_class");
|
2017-06-15 23:04:46 -04:00
|
|
|
i_decimal_class = rb_intern("decimal_class");
|
2015-04-12 04:36:37 -04:00
|
|
|
i_match = rb_intern("match");
|
|
|
|
i_match_string = rb_intern("match_string");
|
|
|
|
i_key_p = rb_intern("key?");
|
|
|
|
i_deep_const_get = rb_intern("deep_const_get");
|
|
|
|
i_aset = rb_intern("[]=");
|
|
|
|
i_aref = rb_intern("[]");
|
|
|
|
i_leftshift = rb_intern("<<");
|
2017-06-15 23:04:46 -04:00
|
|
|
i_new = rb_intern("new");
|
2015-04-12 04:36:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* mode: c
|
|
|
|
* c-file-style: ruby
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*/
|