java/src/json/ext/Parser.java in json_pure-1.5.5 vs java/src/json/ext/Parser.java in json_pure-1.6.0

- old
+ new

@@ -134,10 +134,14 @@ * <dt><code>:object_class</code> * <dd>Defaults to Hash. * * <dt><code>:array_class</code> * <dd>Defaults to Array. + * + * <dt><code>:quirks_mode</code> + * <dd>Enables quirks_mode for parser, that is for example parsing single + * JSON values instead of documents is possible. * </dl> */ @JRubyMethod(name = "new", required = 1, optional = 1, meta = true) public static IRubyObject newInstance(IRubyObject clazz, IRubyObject[] args, Block block) { Parser parser = (Parser)((RubyClass)clazz).allocate(); @@ -158,11 +162,11 @@ this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING); this.allowNaN = opts.getBool("allow_nan", false); this.symbolizeNames = opts.getBool("symbolize_names", false); this.quirksMode = opts.getBool("quirks_mode", false); this.createId = opts.getString("create_id", getCreateId(context)); - this.createAdditions = opts.getBool("create_additions", false); + this.createAdditions = opts.getBool("create_additions", true); this.objectClass = opts.getClass("object_class", runtime.getHash()); this.arrayClass = opts.getClass("array_class", runtime.getArray()); this.match_string = opts.getHash("match_string"); this.vSource = args[0].convertToString(); @@ -325,15 +329,15 @@ private Ruby getRuntime() { return context.getRuntime(); } -// line 353 "Parser.rl" +// line 357 "Parser.rl" -// line 335 "Parser.java" +// line 339 "Parser.java" private static byte[] init__JSON_value_actions_0() { return new byte [] { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9 @@ -443,26 +447,26 @@ static final int JSON_value_error = 0; static final int JSON_value_en_main = 1; -// line 459 "Parser.rl" +// line 463 "Parser.rl" ParserResult parseValue(int p, int pe) { int cs = EVIL; IRubyObject result = null; -// line 457 "Parser.java" +// line 461 "Parser.java" { cs = JSON_value_start; } -// line 466 "Parser.rl" +// line 470 "Parser.rl" -// line 464 "Parser.java" +// line 468 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -484,17 +488,17 @@ _acts = _JSON_value_from_state_actions[cs]; _nacts = (int) _JSON_value_actions[_acts++]; while ( _nacts-- > 0 ) { switch ( _JSON_value_actions[_acts++] ) { case 9: -// line 444 "Parser.rl" +// line 448 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 496 "Parser.java" +// line 500 "Parser.java" } } _match: do { _keys = _JSON_value_key_offsets[cs]; @@ -553,49 +557,49 @@ while ( _nacts-- > 0 ) { switch ( _JSON_value_actions[_acts++] ) { case 0: -// line 361 "Parser.rl" +// line 365 "Parser.rl" { result = getRuntime().getNil(); } break; case 1: -// line 364 "Parser.rl" +// line 368 "Parser.rl" { result = getRuntime().getFalse(); } break; case 2: -// line 367 "Parser.rl" +// line 371 "Parser.rl" { result = getRuntime().getTrue(); } break; case 3: -// line 370 "Parser.rl" +// line 374 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_NAN); } else { throw unexpectedToken(p - 2, pe); } } break; case 4: -// line 377 "Parser.rl" +// line 381 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_INFINITY); } else { throw unexpectedToken(p - 7, pe); } } break; case 5: -// line 384 "Parser.rl" +// line 388 "Parser.rl" { if (pe > p + 9 - (parser.quirksMode ? 1 : 0) && absSubSequence(p, p + 9).toString().equals(JSON_MINUS_INFINITY)) { if (parser.allowNaN) { @@ -620,11 +624,11 @@ p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; case 6: -// line 410 "Parser.rl" +// line 414 "Parser.rl" { ParserResult res = parseString(p, pe); if (res == null) { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} @@ -633,11 +637,11 @@ {p = (( res.p))-1;} } } break; case 7: -// line 420 "Parser.rl" +// line 424 "Parser.rl" { currentNesting++; ParserResult res = parseArray(p, pe); currentNesting--; if (res == null) { @@ -648,11 +652,11 @@ {p = (( res.p))-1;} } } break; case 8: -// line 432 "Parser.rl" +// line 436 "Parser.rl" { currentNesting++; ParserResult res = parseObject(p, pe); currentNesting--; if (res == null) { @@ -662,11 +666,11 @@ result = res.result; {p = (( res.p))-1;} } } break; -// line 668 "Parser.java" +// line 672 "Parser.java" } } } case 2: @@ -682,21 +686,21 @@ case 5: } break; } } -// line 467 "Parser.rl" +// line 471 "Parser.rl" if (cs >= JSON_value_first_final && result != null) { return new ParserResult(result, p); } else { return null; } } -// line 698 "Parser.java" +// line 702 "Parser.java" private static byte[] init__JSON_integer_actions_0() { return new byte [] { 0, 1, 0 }; @@ -791,26 +795,26 @@ static final int JSON_integer_error = 0; static final int JSON_integer_en_main = 1; -// line 486 "Parser.rl" +// line 490 "Parser.rl" ParserResult parseInteger(int p, int pe) { int cs = EVIL; -// line 804 "Parser.java" +// line 808 "Parser.java" { cs = JSON_integer_start; } -// line 492 "Parser.rl" +// line 496 "Parser.rl" int memo = p; -// line 812 "Parser.java" +// line 816 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -887,17 +891,17 @@ while ( _nacts-- > 0 ) { switch ( _JSON_integer_actions[_acts++] ) { case 0: -// line 480 "Parser.rl" +// line 484 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 899 "Parser.java" +// line 903 "Parser.java" } } } case 2: @@ -913,11 +917,11 @@ case 5: } break; } } -// line 494 "Parser.rl" +// line 498 "Parser.rl" if (cs < JSON_integer_first_final) { return null; } @@ -928,11 +932,11 @@ RubyInteger number = RubyNumeric.str2inum(getRuntime(), expr, 10, true); return new ParserResult(number, p + 1); } -// line 934 "Parser.java" +// line 938 "Parser.java" private static byte[] init__JSON_float_actions_0() { return new byte [] { 0, 1, 0 }; @@ -1030,26 +1034,26 @@ static final int JSON_float_error = 0; static final int JSON_float_en_main = 1; -// line 522 "Parser.rl" +// line 526 "Parser.rl" ParserResult parseFloat(int p, int pe) { int cs = EVIL; -// line 1043 "Parser.java" +// line 1047 "Parser.java" { cs = JSON_float_start; } -// line 528 "Parser.rl" +// line 532 "Parser.rl" int memo = p; -// line 1051 "Parser.java" +// line 1055 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -1126,17 +1130,17 @@ while ( _nacts-- > 0 ) { switch ( _JSON_float_actions[_acts++] ) { case 0: -// line 513 "Parser.rl" +// line 517 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1138 "Parser.java" +// line 1142 "Parser.java" } } } case 2: @@ -1152,11 +1156,11 @@ case 5: } break; } } -// line 530 "Parser.rl" +// line 534 "Parser.rl" if (cs < JSON_float_first_final) { return null; } @@ -1167,11 +1171,11 @@ RubyFloat number = RubyNumeric.str2fnum(getRuntime(), expr, true); return new ParserResult(number, p + 1); } -// line 1173 "Parser.java" +// line 1177 "Parser.java" private static byte[] init__JSON_string_actions_0() { return new byte [] { 0, 2, 0, 1 }; @@ -1269,27 +1273,27 @@ static final int JSON_string_error = 0; static final int JSON_string_en_main = 1; -// line 574 "Parser.rl" +// line 578 "Parser.rl" ParserResult parseString(int p, int pe) { int cs = EVIL; IRubyObject result = null; -// line 1283 "Parser.java" +// line 1287 "Parser.java" { cs = JSON_string_start; } -// line 581 "Parser.rl" +// line 585 "Parser.rl" int memo = p; -// line 1291 "Parser.java" +// line 1295 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -1366,11 +1370,11 @@ while ( _nacts-- > 0 ) { switch ( _JSON_string_actions[_acts++] ) { case 0: -// line 549 "Parser.rl" +// line 553 "Parser.rl" { int offset = byteList.begin(); ByteList decoded = decoder.decode(byteList, memo + 1 - offset, p - offset); result = getRuntime().newString(decoded); @@ -1381,17 +1385,17 @@ {p = (( p + 1))-1;} } } break; case 1: -// line 562 "Parser.rl" +// line 566 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1393 "Parser.java" +// line 1397 "Parser.java" } } } case 2: @@ -1407,11 +1411,11 @@ case 5: } break; } } -// line 583 "Parser.rl" +// line 587 "Parser.rl" if (parser.createAdditions) { RubyHash match_string = parser.match_string; if (match_string != null) { final IRubyObject[] memoArray = { result, null }; @@ -1442,11 +1446,11 @@ return null; } } -// line 1448 "Parser.java" +// line 1452 "Parser.java" private static byte[] init__JSON_array_actions_0() { return new byte [] { 0, 1, 0, 1, 1 }; @@ -1555,11 +1559,11 @@ static final int JSON_array_error = 0; static final int JSON_array_en_main = 1; -// line 653 "Parser.rl" +// line 657 "Parser.rl" ParserResult parseArray(int p, int pe) { int cs = EVIL; @@ -1573,18 +1577,18 @@ RubyArray result = (RubyArray)parser.arrayClass.newInstance(context, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); -// line 1579 "Parser.java" +// line 1583 "Parser.java" { cs = JSON_array_start; } -// line 670 "Parser.rl" +// line 674 "Parser.rl" -// line 1586 "Parser.java" +// line 1590 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -1661,11 +1665,11 @@ while ( _nacts-- > 0 ) { switch ( _JSON_array_actions[_acts++] ) { case 0: -// line 622 "Parser.rl" +// line 626 "Parser.rl" { ParserResult res = parseValue(p, pe); if (res == null) { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} @@ -1678,17 +1682,17 @@ {p = (( res.p))-1;} } } break; case 1: -// line 637 "Parser.rl" +// line 641 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1690 "Parser.java" +// line 1694 "Parser.java" } } } case 2: @@ -1704,21 +1708,21 @@ case 5: } break; } } -// line 671 "Parser.rl" +// line 675 "Parser.rl" if (cs >= JSON_array_first_final) { return new ParserResult(result, p + 1); } else { throw unexpectedToken(p, pe); } } -// line 1720 "Parser.java" +// line 1724 "Parser.java" private static byte[] init__JSON_object_actions_0() { return new byte [] { 0, 1, 0, 1, 1, 1, 2 }; @@ -1837,11 +1841,11 @@ static final int JSON_object_error = 0; static final int JSON_object_en_main = 1; -// line 730 "Parser.rl" +// line 734 "Parser.rl" ParserResult parseObject(int p, int pe) { int cs = EVIL; IRubyObject lastName = null; @@ -1856,18 +1860,18 @@ RubyHash result = (RubyHash)parser.objectClass.newInstance(context, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); -// line 1862 "Parser.java" +// line 1866 "Parser.java" { cs = JSON_object_start; } -// line 748 "Parser.rl" +// line 752 "Parser.rl" -// line 1869 "Parser.java" +// line 1873 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -1944,11 +1948,11 @@ while ( _nacts-- > 0 ) { switch ( _JSON_object_actions[_acts++] ) { case 0: -// line 685 "Parser.rl" +// line 689 "Parser.rl" { ParserResult res = parseValue(p, pe); if (res == null) { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} @@ -1961,11 +1965,11 @@ {p = (( res.p))-1;} } } break; case 1: -// line 700 "Parser.rl" +// line 704 "Parser.rl" { ParserResult res = parseString(p, pe); if (res == null) { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} @@ -1981,17 +1985,17 @@ {p = (( res.p))-1;} } } break; case 2: -// line 718 "Parser.rl" +// line 722 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1993 "Parser.java" +// line 1997 "Parser.java" } } } case 2: @@ -2007,11 +2011,11 @@ case 5: } break; } } -// line 749 "Parser.rl" +// line 753 "Parser.rl" if (cs < JSON_object_first_final) { return null; } @@ -2033,11 +2037,11 @@ } return new ParserResult(returnedResult, p + 1); } -// line 2039 "Parser.java" +// line 2043 "Parser.java" private static byte[] init__JSON_actions_0() { return new byte [] { 0, 1, 0, 1, 1 }; @@ -2137,29 +2141,29 @@ static final int JSON_error = 0; static final int JSON_en_main = 1; -// line 807 "Parser.rl" +// line 811 "Parser.rl" public IRubyObject parseStrict() { int cs = EVIL; int p, pe; IRubyObject result = null; -// line 2152 "Parser.java" +// line 2156 "Parser.java" { cs = JSON_start; } -// line 815 "Parser.rl" +// line 819 "Parser.rl" p = byteList.begin(); pe = p + byteList.length(); -// line 2161 "Parser.java" +// line 2165 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -2236,11 +2240,11 @@ while ( _nacts-- > 0 ) { switch ( _JSON_actions[_acts++] ) { case 0: -// line 779 "Parser.rl" +// line 783 "Parser.rl" { currentNesting = 1; ParserResult res = parseObject(p, pe); if (res == null) { p--; @@ -2250,11 +2254,11 @@ {p = (( res.p))-1;} } } break; case 1: -// line 791 "Parser.rl" +// line 795 "Parser.rl" { currentNesting = 1; ParserResult res = parseArray(p, pe); if (res == null) { p--; @@ -2263,11 +2267,11 @@ result = res.result; {p = (( res.p))-1;} } } break; -// line 2269 "Parser.java" +// line 2273 "Parser.java" } } } case 2: @@ -2283,21 +2287,21 @@ case 5: } break; } } -// line 818 "Parser.rl" +// line 822 "Parser.rl" if (cs >= JSON_first_final && p == pe) { return result; } else { throw unexpectedToken(p, pe); } } -// line 2299 "Parser.java" +// line 2303 "Parser.java" private static byte[] init__JSON_quirks_mode_actions_0() { return new byte [] { 0, 1, 0 }; @@ -2396,29 +2400,29 @@ static final int JSON_quirks_mode_error = 0; static final int JSON_quirks_mode_en_main = 1; -// line 846 "Parser.rl" +// line 850 "Parser.rl" public IRubyObject parseQuirksMode() { int cs = EVIL; int p, pe; IRubyObject result = null; -// line 2411 "Parser.java" +// line 2415 "Parser.java" { cs = JSON_quirks_mode_start; } -// line 854 "Parser.rl" +// line 858 "Parser.rl" p = byteList.begin(); pe = p + byteList.length(); -// line 2420 "Parser.java" +// line 2424 "Parser.java" { int _klen; int _trans = 0; int _acts; int _nacts; @@ -2495,11 +2499,11 @@ while ( _nacts-- > 0 ) { switch ( _JSON_quirks_mode_actions[_acts++] ) { case 0: -// line 832 "Parser.rl" +// line 836 "Parser.rl" { ParserResult res = parseValue(p, pe); if (res == null) { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} @@ -2507,11 +2511,11 @@ result = res.result; {p = (( res.p))-1;} } } break; -// line 2513 "Parser.java" +// line 2517 "Parser.java" } } } case 2: @@ -2527,10 +2531,10 @@ case 5: } break; } } -// line 857 "Parser.rl" +// line 861 "Parser.rl" if (cs >= JSON_quirks_mode_first_final && p == pe) { return result; } else { throw unexpectedToken(p, pe);