ext/json/ext/parser/parser.c in json-1.1.2 vs ext/json/ext/parser/parser.c in json-1.1.3

- old
+ new

@@ -1,8 +1,6 @@ #line 1 "parser.rl" -/* vim: set cin et sw=4 ts=4: */ - #include "ruby.h" #include "re.h" #include "st.h" #include "unicode.h" @@ -36,22 +34,22 @@ #define GET_STRUCT \ JSON_Parser *json; \ Data_Get_Struct(self, JSON_Parser, json); -#line 66 "parser.rl" +#line 64 "parser.rl" -#line 46 "parser.c" +#line 44 "parser.c" static const int JSON_object_start = 1; static const int JSON_object_first_final = 27; static const int JSON_object_error = 0; static const int JSON_object_en_main = 1; -#line 99 "parser.rl" +#line 97 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; @@ -62,31 +60,32 @@ } *result = rb_hash_new(); -#line 68 "parser.c" +#line 66 "parser.c" { cs = JSON_object_start; } -#line 113 "parser.rl" +#line 111 "parser.rl" -#line 74 "parser.c" +#line 72 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: if ( (*p) == 123 ) goto st2; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: switch( (*p) ) { case 13: goto st2; case 32: goto st2; case 34: goto tr2; @@ -95,21 +94,21 @@ } if ( 9 <= (*p) && (*p) <= 10 ) goto st2; goto st0; tr2: -#line 85 "parser.rl" +#line 83 "parser.rl" { char *np = JSON_parse_string(json, p, pe, &last_name); - if (np == NULL) goto _out3; else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;} } goto st3; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: -#line 111 "parser.c" +#line 110 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; case 47: goto st4; case 58: goto st8; @@ -117,43 +116,43 @@ if ( 9 <= (*p) && (*p) <= 10 ) goto st3; goto st0; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: switch( (*p) ) { case 42: goto st5; case 47: goto st7; } goto st0; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: if ( (*p) == 42 ) goto st6; goto st5; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: switch( (*p) ) { case 42: goto st6; case 47: goto st3; } goto st5; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: if ( (*p) == 10 ) goto st3; goto st7; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: switch( (*p) ) { case 13: goto st8; case 32: goto st8; case 34: goto tr11; @@ -172,27 +171,27 @@ goto tr11; } else if ( (*p) >= 9 ) goto st8; goto st0; tr11: -#line 74 "parser.rl" +#line 72 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); if (np == NULL) { - goto _out9; + p--; {p++; cs = 9; goto _out;} } else { rb_hash_aset(*result, last_name, v); {p = (( np))-1;} } } goto st9; st9: if ( ++p == pe ) - goto _out9; + goto _test_eof9; case 9: -#line 194 "parser.c" +#line 193 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; case 44: goto st10; case 47: goto st15; @@ -201,11 +200,11 @@ if ( 9 <= (*p) && (*p) <= 10 ) goto st9; goto st0; st10: if ( ++p == pe ) - goto _out10; + goto _test_eof10; case 10: switch( (*p) ) { case 13: goto st10; case 32: goto st10; case 34: goto tr2; @@ -214,178 +213,178 @@ if ( 9 <= (*p) && (*p) <= 10 ) goto st10; goto st0; st11: if ( ++p == pe ) - goto _out11; + goto _test_eof11; case 11: switch( (*p) ) { case 42: goto st12; case 47: goto st14; } goto st0; st12: if ( ++p == pe ) - goto _out12; + goto _test_eof12; case 12: if ( (*p) == 42 ) goto st13; goto st12; st13: if ( ++p == pe ) - goto _out13; + goto _test_eof13; case 13: switch( (*p) ) { case 42: goto st13; case 47: goto st10; } goto st12; st14: if ( ++p == pe ) - goto _out14; + goto _test_eof14; case 14: if ( (*p) == 10 ) goto st10; goto st14; st15: if ( ++p == pe ) - goto _out15; + goto _test_eof15; case 15: switch( (*p) ) { case 42: goto st16; case 47: goto st18; } goto st0; st16: if ( ++p == pe ) - goto _out16; + goto _test_eof16; case 16: if ( (*p) == 42 ) goto st17; goto st16; st17: if ( ++p == pe ) - goto _out17; + goto _test_eof17; case 17: switch( (*p) ) { case 42: goto st17; case 47: goto st9; } goto st16; st18: if ( ++p == pe ) - goto _out18; + goto _test_eof18; case 18: if ( (*p) == 10 ) goto st9; goto st18; tr4: -#line 90 "parser.rl" - { goto _out27; } +#line 88 "parser.rl" + { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) - goto _out27; + goto _test_eof27; case 27: -#line 290 "parser.c" +#line 289 "parser.c" goto st0; st19: if ( ++p == pe ) - goto _out19; + goto _test_eof19; case 19: switch( (*p) ) { case 42: goto st20; case 47: goto st22; } goto st0; st20: if ( ++p == pe ) - goto _out20; + goto _test_eof20; case 20: if ( (*p) == 42 ) goto st21; goto st20; st21: if ( ++p == pe ) - goto _out21; + goto _test_eof21; case 21: switch( (*p) ) { case 42: goto st21; case 47: goto st8; } goto st20; st22: if ( ++p == pe ) - goto _out22; + goto _test_eof22; case 22: if ( (*p) == 10 ) goto st8; goto st22; st23: if ( ++p == pe ) - goto _out23; + goto _test_eof23; case 23: switch( (*p) ) { case 42: goto st24; case 47: goto st26; } goto st0; st24: if ( ++p == pe ) - goto _out24; + goto _test_eof24; case 24: if ( (*p) == 42 ) goto st25; goto st24; st25: if ( ++p == pe ) - goto _out25; + goto _test_eof25; case 25: switch( (*p) ) { case 42: goto st25; case 47: goto st2; } goto st24; st26: if ( ++p == pe ) - goto _out26; + goto _test_eof26; case 26: if ( (*p) == 10 ) goto st2; goto st26; } - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; - _out8: cs = 8; goto _out; - _out9: cs = 9; goto _out; - _out10: cs = 10; goto _out; - _out11: cs = 11; goto _out; - _out12: cs = 12; goto _out; - _out13: cs = 13; goto _out; - _out14: cs = 14; goto _out; - _out15: cs = 15; goto _out; - _out16: cs = 16; goto _out; - _out17: cs = 17; goto _out; - _out18: cs = 18; goto _out; - _out27: cs = 27; goto _out; - _out19: cs = 19; goto _out; - _out20: cs = 20; goto _out; - _out21: cs = 21; goto _out; - _out22: cs = 22; goto _out; - _out23: cs = 23; goto _out; - _out24: cs = 24; goto _out; - _out25: cs = 25; goto _out; - _out26: cs = 26; goto _out; + _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: {} } -#line 114 "parser.rl" +#line 112 "parser.rl" if (cs >= JSON_object_first_final) { if (RTEST(json->create_id)) { VALUE klassname = rb_hash_aref(*result, json->create_id); if (!NIL_P(klassname)) { @@ -400,35 +399,35 @@ return NULL; } } -#line 406 "parser.c" +#line 405 "parser.c" static const int JSON_value_start = 1; static const int JSON_value_first_final = 21; static const int JSON_value_error = 0; static const int JSON_value_en_main = 1; -#line 212 "parser.rl" +#line 210 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; -#line 421 "parser.c" +#line 420 "parser.c" { cs = JSON_value_start; } -#line 219 "parser.rl" +#line 217 "parser.rl" -#line 427 "parser.c" +#line 426 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: switch( (*p) ) { case 34: goto tr0; @@ -443,263 +442,264 @@ } if ( 48 <= (*p) && (*p) <= 57 ) goto tr2; goto st0; st0: - goto _out0; +cs = 0; + goto _out; tr0: -#line 160 "parser.rl" +#line 158 "parser.rl" { char *np = JSON_parse_string(json, p, pe, result); - if (np == NULL) goto _out21; else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} } goto st21; tr2: -#line 165 "parser.rl" +#line 163 "parser.rl" { char *np; if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) { if (json->allow_nan) { *result = CMinusInfinity; {p = (( p + 10))-1;} - goto _out21; + p--; {p++; cs = 21; goto _out;} } else { - rb_raise(eParserError, "unexpected token at '%s'", p); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); } } 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;} - goto _out21; + p--; {p++; cs = 21; goto _out;} } goto st21; tr5: -#line 183 "parser.rl" +#line 181 "parser.rl" { char *np; - json->current_nesting += 1; + json->current_nesting++; np = JSON_parse_array(json, p, pe, result); - json->current_nesting -= 1; - if (np == NULL) goto _out21; else {p = (( np))-1;} + json->current_nesting--; + if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} } goto st21; tr9: -#line 191 "parser.rl" +#line 189 "parser.rl" { char *np; - json->current_nesting += 1; + json->current_nesting++; np = JSON_parse_object(json, p, pe, result); - json->current_nesting -= 1; - if (np == NULL) goto _out21; else {p = (( np))-1;} + json->current_nesting--; + if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} } goto st21; tr16: -#line 153 "parser.rl" +#line 151 "parser.rl" { if (json->allow_nan) { *result = CInfinity; } else { - rb_raise(eParserError, "unexpected token at '%s'", p - 8); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); } } goto st21; tr18: -#line 146 "parser.rl" +#line 144 "parser.rl" { if (json->allow_nan) { *result = CNaN; } else { - rb_raise(eParserError, "unexpected token at '%s'", p - 2); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); } } goto st21; tr22: -#line 140 "parser.rl" +#line 138 "parser.rl" { *result = Qfalse; } goto st21; tr25: -#line 137 "parser.rl" +#line 135 "parser.rl" { *result = Qnil; } goto st21; tr28: -#line 143 "parser.rl" +#line 141 "parser.rl" { *result = Qtrue; } goto st21; st21: if ( ++p == pe ) - goto _out21; + goto _test_eof21; case 21: -#line 199 "parser.rl" - { goto _out21; } +#line 197 "parser.rl" + { p--; {p++; cs = 21; goto _out;} } #line 541 "parser.c" goto st0; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: if ( (*p) == 110 ) goto st3; goto st0; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: if ( (*p) == 102 ) goto st4; goto st0; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: if ( (*p) == 105 ) goto st5; goto st0; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: if ( (*p) == 110 ) goto st6; goto st0; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: if ( (*p) == 105 ) goto st7; goto st0; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: if ( (*p) == 116 ) goto st8; goto st0; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: if ( (*p) == 121 ) goto tr16; goto st0; st9: if ( ++p == pe ) - goto _out9; + goto _test_eof9; case 9: if ( (*p) == 97 ) goto st10; goto st0; st10: if ( ++p == pe ) - goto _out10; + goto _test_eof10; case 10: if ( (*p) == 78 ) goto tr18; goto st0; st11: if ( ++p == pe ) - goto _out11; + goto _test_eof11; case 11: if ( (*p) == 97 ) goto st12; goto st0; st12: if ( ++p == pe ) - goto _out12; + goto _test_eof12; case 12: if ( (*p) == 108 ) goto st13; goto st0; st13: if ( ++p == pe ) - goto _out13; + goto _test_eof13; case 13: if ( (*p) == 115 ) goto st14; goto st0; st14: if ( ++p == pe ) - goto _out14; + goto _test_eof14; case 14: if ( (*p) == 101 ) goto tr22; goto st0; st15: if ( ++p == pe ) - goto _out15; + goto _test_eof15; case 15: if ( (*p) == 117 ) goto st16; goto st0; st16: if ( ++p == pe ) - goto _out16; + goto _test_eof16; case 16: if ( (*p) == 108 ) goto st17; goto st0; st17: if ( ++p == pe ) - goto _out17; + goto _test_eof17; case 17: if ( (*p) == 108 ) goto tr25; goto st0; st18: if ( ++p == pe ) - goto _out18; + goto _test_eof18; case 18: if ( (*p) == 114 ) goto st19; goto st0; st19: if ( ++p == pe ) - goto _out19; + goto _test_eof19; case 19: if ( (*p) == 117 ) goto st20; goto st0; st20: if ( ++p == pe ) - goto _out20; + goto _test_eof20; case 20: if ( (*p) == 101 ) goto tr28; goto st0; } - _out0: cs = 0; goto _out; - _out21: cs = 21; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; - _out8: cs = 8; goto _out; - _out9: cs = 9; goto _out; - _out10: cs = 10; goto _out; - _out11: cs = 11; goto _out; - _out12: cs = 12; goto _out; - _out13: cs = 13; goto _out; - _out14: cs = 14; goto _out; - _out15: cs = 15; goto _out; - _out16: cs = 16; goto _out; - _out17: cs = 17; goto _out; - _out18: cs = 18; goto _out; - _out19: cs = 19; goto _out; - _out20: cs = 20; goto _out; + _test_eof21: cs = 21; 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_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; + _test_eof: {} _out: {} } -#line 220 "parser.rl" +#line 218 "parser.rl" if (cs >= JSON_value_first_final) { return p; } else { return NULL; @@ -712,11 +712,11 @@ static const int JSON_integer_first_final = 5; static const int JSON_integer_error = 0; static const int JSON_integer_en_main = 1; -#line 236 "parser.rl" +#line 234 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; @@ -724,17 +724,17 @@ #line 726 "parser.c" { cs = JSON_integer_start; } -#line 243 "parser.rl" +#line 241 "parser.rl" json->memo = p; #line 733 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: switch( (*p) ) { case 45: goto st2; @@ -742,54 +742,55 @@ } if ( 49 <= (*p) && (*p) <= 57 ) goto st4; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: if ( (*p) == 48 ) goto st3; if ( 49 <= (*p) && (*p) <= 57 ) goto st4; goto st0; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: if ( 48 <= (*p) && (*p) <= 57 ) goto st0; goto tr4; tr4: -#line 233 "parser.rl" - { goto _out5; } +#line 231 "parser.rl" + { p--; {p++; cs = 5; goto _out;} } goto st5; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: -#line 773 "parser.c" +#line 774 "parser.c" goto st0; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: if ( 48 <= (*p) && (*p) <= 57 ) goto st4; goto tr4; } - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out5: cs = 5; goto _out; - _out4: cs = 4; goto _out; + _test_eof2: cs = 2; goto _test_eof; + _test_eof3: cs = 3; goto _test_eof; + _test_eof5: cs = 5; goto _test_eof; + _test_eof4: cs = 4; goto _test_eof; + _test_eof: {} _out: {} } -#line 245 "parser.rl" +#line 243 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; *result = rb_Integer(rb_str_new(json->memo, len)); return p + 1; @@ -797,36 +798,36 @@ return NULL; } } -#line 803 "parser.c" +#line 804 "parser.c" static const int JSON_float_start = 1; static const int JSON_float_first_final = 10; static const int JSON_float_error = 0; static const int JSON_float_en_main = 1; -#line 267 "parser.rl" +#line 265 "parser.rl" static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; -#line 818 "parser.c" +#line 819 "parser.c" { cs = JSON_float_start; } -#line 274 "parser.rl" +#line 272 "parser.rl" json->memo = p; -#line 825 "parser.c" +#line 826 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: switch( (*p) ) { case 45: goto st2; @@ -834,40 +835,41 @@ } if ( 49 <= (*p) && (*p) <= 57 ) goto st9; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: if ( (*p) == 48 ) goto st3; if ( 49 <= (*p) && (*p) <= 57 ) goto st9; goto st0; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: switch( (*p) ) { case 46: goto st4; case 69: goto st6; case 101: goto st6; } goto st0; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: if ( 48 <= (*p) && (*p) <= 57 ) goto st5; goto st0; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: switch( (*p) ) { case 69: goto st6; case 101: goto st6; } @@ -876,40 +878,40 @@ goto st5; } else if ( (*p) >= 45 ) goto st0; goto tr7; tr7: -#line 261 "parser.rl" - { goto _out10; } +#line 259 "parser.rl" + { p--; {p++; cs = 10; goto _out;} } goto st10; st10: if ( ++p == pe ) - goto _out10; + goto _test_eof10; case 10: -#line 889 "parser.c" +#line 891 "parser.c" goto st0; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: switch( (*p) ) { case 43: goto st7; case 45: goto st7; } if ( 48 <= (*p) && (*p) <= 57 ) goto st8; goto st0; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: if ( 48 <= (*p) && (*p) <= 57 ) goto st8; goto st0; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: switch( (*p) ) { case 69: goto st0; case 101: goto st0; } @@ -919,35 +921,35 @@ } else if ( (*p) >= 45 ) goto st0; goto tr7; st9: if ( ++p == pe ) - goto _out9; + goto _test_eof9; case 9: switch( (*p) ) { case 46: goto st4; case 69: goto st6; case 101: goto st6; } if ( 48 <= (*p) && (*p) <= 57 ) goto st9; goto st0; } - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out10: cs = 10; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; - _out8: cs = 8; goto _out; - _out9: cs = 9; goto _out; + _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_eof10: cs = 10; 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: {} } -#line 276 "parser.rl" +#line 274 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; *result = rb_Float(rb_str_new(json->memo, len)); return p + 1; @@ -956,18 +958,18 @@ } } -#line 962 "parser.c" +#line 964 "parser.c" static const int JSON_array_start = 1; static const int JSON_array_first_final = 17; static const int JSON_array_error = 0; static const int JSON_array_en_main = 1; -#line 312 "parser.rl" +#line 310 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; @@ -976,31 +978,32 @@ rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting); } *result = rb_ary_new(); -#line 982 "parser.c" +#line 984 "parser.c" { cs = JSON_array_start; } -#line 324 "parser.rl" +#line 322 "parser.rl" -#line 988 "parser.c" +#line 990 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: if ( (*p) == 91 ) goto st2; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: switch( (*p) ) { case 13: goto st2; case 32: goto st2; case 34: goto tr2; @@ -1020,27 +1023,27 @@ goto tr2; } else if ( (*p) >= 9 ) goto st2; goto st0; tr2: -#line 293 "parser.rl" +#line 291 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); if (np == NULL) { - goto _out3; + p--; {p++; cs = 3; goto _out;} } else { rb_ary_push(*result, v); {p = (( np))-1;} } } goto st3; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: -#line 1042 "parser.c" +#line 1045 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; case 44: goto st4; case 47: goto st9; @@ -1049,11 +1052,11 @@ if ( 9 <= (*p) && (*p) <= 10 ) goto st3; goto st0; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: switch( (*p) ) { case 13: goto st4; case 32: goto st4; case 34: goto tr2; @@ -1073,141 +1076,141 @@ } else if ( (*p) >= 9 ) goto st4; goto st0; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: switch( (*p) ) { case 42: goto st6; case 47: goto st8; } goto st0; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: if ( (*p) == 42 ) goto st7; goto st6; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: switch( (*p) ) { case 42: goto st7; case 47: goto st4; } goto st6; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: if ( (*p) == 10 ) goto st4; goto st8; st9: if ( ++p == pe ) - goto _out9; + goto _test_eof9; case 9: switch( (*p) ) { case 42: goto st10; case 47: goto st12; } goto st0; st10: if ( ++p == pe ) - goto _out10; + goto _test_eof10; case 10: if ( (*p) == 42 ) goto st11; goto st10; st11: if ( ++p == pe ) - goto _out11; + goto _test_eof11; case 11: switch( (*p) ) { case 42: goto st11; case 47: goto st3; } goto st10; st12: if ( ++p == pe ) - goto _out12; + goto _test_eof12; case 12: if ( (*p) == 10 ) goto st3; goto st12; tr4: -#line 304 "parser.rl" - { goto _out17; } +#line 302 "parser.rl" + { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) - goto _out17; + goto _test_eof17; case 17: -#line 1149 "parser.c" +#line 1152 "parser.c" goto st0; st13: if ( ++p == pe ) - goto _out13; + goto _test_eof13; case 13: switch( (*p) ) { case 42: goto st14; case 47: goto st16; } goto st0; st14: if ( ++p == pe ) - goto _out14; + goto _test_eof14; case 14: if ( (*p) == 42 ) goto st15; goto st14; st15: if ( ++p == pe ) - goto _out15; + goto _test_eof15; case 15: switch( (*p) ) { case 42: goto st15; case 47: goto st2; } goto st14; st16: if ( ++p == pe ) - goto _out16; + goto _test_eof16; case 16: if ( (*p) == 10 ) goto st2; goto st16; } - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; - _out8: cs = 8; goto _out; - _out9: cs = 9; goto _out; - _out10: cs = 10; goto _out; - _out11: cs = 11; goto _out; - _out12: cs = 12; goto _out; - _out17: cs = 17; goto _out; - _out13: cs = 13; goto _out; - _out14: cs = 14; goto _out; - _out15: cs = 15; goto _out; - _out16: cs = 16; goto _out; + _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: {} } -#line 325 "parser.rl" +#line 323 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; } else { - rb_raise(eParserError, "unexpected token at '%s'", p); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); } } static VALUE json_string_unescape(char *p, char *pe) { @@ -1264,83 +1267,84 @@ } return result; } -#line 1270 "parser.c" +#line 1273 "parser.c" static const int JSON_string_start = 1; static const int JSON_string_first_final = 8; static const int JSON_string_error = 0; static const int JSON_string_en_main = 1; -#line 403 "parser.rl" +#line 401 "parser.rl" static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; *result = rb_str_new("", 0); -#line 1286 "parser.c" +#line 1289 "parser.c" { cs = JSON_string_start; } -#line 411 "parser.rl" +#line 409 "parser.rl" json->memo = p; -#line 1293 "parser.c" +#line 1296 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { case 1: if ( (*p) == 34 ) goto st2; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + 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: -#line 395 "parser.rl" +#line 393 "parser.rl" { *result = json_string_unescape(json->memo + 1, p); - if (NIL_P(*result)) goto _out8; else {p = (( p + 1))-1;} + if (NIL_P(*result)) { p--; {p++; cs = 8; goto _out;} } else {p = (( p + 1))-1;} } -#line 400 "parser.rl" - { goto _out8; } +#line 398 "parser.rl" + { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: -#line 1329 "parser.c" +#line 1333 "parser.c" goto st0; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: if ( (*p) == 117 ) goto st4; if ( 0 <= (*p) && (*p) <= 31 ) goto st0; goto st2; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st5; } else if ( (*p) > 70 ) { @@ -1349,11 +1353,11 @@ } else goto st5; goto st0; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st6; } else if ( (*p) > 70 ) { @@ -1362,11 +1366,11 @@ } else goto st6; goto st0; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st7; } else if ( (*p) > 70 ) { @@ -1375,11 +1379,11 @@ } else goto st7; goto st0; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: if ( (*p) < 65 ) { if ( 48 <= (*p) && (*p) <= 57 ) goto st2; } else if ( (*p) > 70 ) { @@ -1387,40 +1391,40 @@ goto st2; } else goto st2; goto st0; } - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out8: cs = 8; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; + _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: {} } -#line 413 "parser.rl" +#line 411 "parser.rl" if (cs >= JSON_string_first_final) { return p + 1; } else { return NULL; } } -#line 1415 "parser.c" +#line 1419 "parser.c" static const int JSON_start = 1; static const int JSON_first_final = 10; static const int JSON_error = 0; static const int JSON_en_main = 1; -#line 447 "parser.rl" +#line 445 "parser.rl" /* * Document-class: JSON::Ext::Parser * @@ -1539,27 +1543,27 @@ int cs = EVIL; VALUE result = Qnil; GET_STRUCT; -#line 1545 "parser.c" +#line 1549 "parser.c" { cs = JSON_start; } -#line 569 "parser.rl" +#line 567 "parser.rl" p = json->source; pe = p + json->len; -#line 1553 "parser.c" +#line 1557 "parser.c" { if ( p == pe ) - goto _out; + goto _test_eof; switch ( cs ) { st1: if ( ++p == pe ) - goto _out1; + goto _test_eof1; case 1: switch( (*p) ) { case 13: goto st1; case 32: goto st1; case 47: goto st2; @@ -1568,127 +1572,128 @@ } if ( 9 <= (*p) && (*p) <= 10 ) goto st1; goto st0; st0: - goto _out0; +cs = 0; + goto _out; st2: if ( ++p == pe ) - goto _out2; + goto _test_eof2; case 2: switch( (*p) ) { case 42: goto st3; case 47: goto st5; } goto st0; st3: if ( ++p == pe ) - goto _out3; + goto _test_eof3; case 3: if ( (*p) == 42 ) goto st4; goto st3; st4: if ( ++p == pe ) - goto _out4; + goto _test_eof4; case 4: switch( (*p) ) { case 42: goto st4; case 47: goto st1; } goto st3; st5: if ( ++p == pe ) - goto _out5; + goto _test_eof5; case 5: if ( (*p) == 10 ) goto st1; goto st5; tr3: -#line 436 "parser.rl" +#line 434 "parser.rl" { char *np; json->current_nesting = 1; np = JSON_parse_array(json, p, pe, &result); - if (np == NULL) goto _out10; else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} } goto st10; tr4: -#line 429 "parser.rl" +#line 427 "parser.rl" { char *np; json->current_nesting = 1; np = JSON_parse_object(json, p, pe, &result); - if (np == NULL) goto _out10; else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} } goto st10; st10: if ( ++p == pe ) - goto _out10; + goto _test_eof10; case 10: -#line 1629 "parser.c" +#line 1634 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; case 47: goto st6; } if ( 9 <= (*p) && (*p) <= 10 ) goto st10; goto st0; st6: if ( ++p == pe ) - goto _out6; + goto _test_eof6; case 6: switch( (*p) ) { case 42: goto st7; case 47: goto st9; } goto st0; st7: if ( ++p == pe ) - goto _out7; + goto _test_eof7; case 7: if ( (*p) == 42 ) goto st8; goto st7; st8: if ( ++p == pe ) - goto _out8; + goto _test_eof8; case 8: switch( (*p) ) { case 42: goto st8; case 47: goto st10; } goto st7; st9: if ( ++p == pe ) - goto _out9; + goto _test_eof9; case 9: if ( (*p) == 10 ) goto st10; goto st9; } - _out1: cs = 1; goto _out; - _out0: cs = 0; goto _out; - _out2: cs = 2; goto _out; - _out3: cs = 3; goto _out; - _out4: cs = 4; goto _out; - _out5: cs = 5; goto _out; - _out10: cs = 10; goto _out; - _out6: cs = 6; goto _out; - _out7: cs = 7; goto _out; - _out8: cs = 8; goto _out; - _out9: cs = 9; goto _out; + _test_eof1: cs = 1; 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_eof10: cs = 10; 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: {} } -#line 572 "parser.rl" +#line 570 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; } else { - rb_raise(eParserError, "unexpected token at '%s'", p); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); } } inline static JSON_Parser *JSON_allocate() { @@ -1726,9 +1731,10 @@ return rb_str_dup(json->Vsource); } void Init_parser() { + 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");