java/src/json/ext/Parser.java in json_pure-1.8.1 vs java/src/json/ext/Parser.java in json_pure-1.8.2
- old
+ new
@@ -128,11 +128,11 @@
* <dd>If set to <code>true</code>, if the parse is in quirks_mode, false
* otherwise.
*
* <dt><code>:create_additions</code>
* <dd>If set to <code>false</code>, the Parser doesn't create additions
- * even if a matchin class and <code>create_id</code> was found. This option
+ * even if a matching class and <code>create_id</code> was found. This option
* defaults to <code>true</code>.
*
* <dt><code>:object_class</code>
* <dd>Defaults to Hash.
*
@@ -246,11 +246,11 @@
* <p>Parses the current JSON text <code>source</code> and returns the
* complete data structure as a result.
*/
@JRubyMethod
public IRubyObject parse(ThreadContext context) {
- return new ParserSession(this, context).parse();
+ return new ParserSession(this, context, info).parse();
}
/**
* <code>Parser#source()</code>
*
@@ -302,10 +302,11 @@
// Ragel uses lots of fall-through
@SuppressWarnings("fallthrough")
private static class ParserSession {
private final Parser parser;
private final ThreadContext context;
+ private final RuntimeInfo info;
private final ByteList byteList;
private final ByteList view;
private final byte[] data;
private final StringDecoder decoder;
private int currentNesting = 0;
@@ -313,13 +314,14 @@
// initialization value for all state variables.
// no idea about the origins of this value, ask Flori ;)
private static final int EVIL = 0x666;
- private ParserSession(Parser parser, ThreadContext context) {
+ private ParserSession(Parser parser, ThreadContext context, RuntimeInfo info) {
this.parser = parser;
this.context = context;
+ this.info = info;
this.byteList = parser.checkAndGetSource().getByteList();
this.data = byteList.unsafeBytes();
this.view = new ByteList(data, false);
this.decoder = new StringDecoder(context);
this.dc = new DoubleConverter();
@@ -335,15 +337,15 @@
private Ruby getRuntime() {
return context.getRuntime();
}
-// line 363 "Parser.rl"
+// line 365 "Parser.rl"
-// line 345 "Parser.java"
+// line 347 "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
@@ -453,26 +455,26 @@
static final int JSON_value_error = 0;
static final int JSON_value_en_main = 1;
-// line 469 "Parser.rl"
+// line 471 "Parser.rl"
void parseValue(ParserResult res, int p, int pe) {
int cs = EVIL;
IRubyObject result = null;
-// line 467 "Parser.java"
+// line 469 "Parser.java"
{
cs = JSON_value_start;
}
-// line 476 "Parser.rl"
+// line 478 "Parser.rl"
-// line 474 "Parser.java"
+// line 476 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -494,17 +496,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 454 "Parser.rl"
+// line 456 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 506 "Parser.java"
+// line 508 "Parser.java"
}
}
_match: do {
_keys = _JSON_value_key_offsets[cs];
@@ -563,49 +565,49 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_value_actions[_acts++] )
{
case 0:
-// line 371 "Parser.rl"
+// line 373 "Parser.rl"
{
result = getRuntime().getNil();
}
break;
case 1:
-// line 374 "Parser.rl"
+// line 376 "Parser.rl"
{
result = getRuntime().getFalse();
}
break;
case 2:
-// line 377 "Parser.rl"
+// line 379 "Parser.rl"
{
result = getRuntime().getTrue();
}
break;
case 3:
-// line 380 "Parser.rl"
+// line 382 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_NAN);
} else {
throw unexpectedToken(p - 2, pe);
}
}
break;
case 4:
-// line 387 "Parser.rl"
+// line 389 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_INFINITY);
} else {
throw unexpectedToken(p - 7, pe);
}
}
break;
case 5:
-// line 394 "Parser.rl"
+// line 396 "Parser.rl"
{
if (pe > p + 9 - (parser.quirksMode ? 1 : 0) &&
absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
if (parser.allowNaN) {
@@ -630,11 +632,11 @@
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
case 6:
-// line 420 "Parser.rl"
+// line 422 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
@@ -643,11 +645,11 @@
{p = (( res.p))-1;}
}
}
break;
case 7:
-// line 430 "Parser.rl"
+// line 432 "Parser.rl"
{
currentNesting++;
parseArray(res, p, pe);
currentNesting--;
if (res.result == null) {
@@ -658,11 +660,11 @@
{p = (( res.p))-1;}
}
}
break;
case 8:
-// line 442 "Parser.rl"
+// line 444 "Parser.rl"
{
currentNesting++;
parseObject(res, p, pe);
currentNesting--;
if (res.result == null) {
@@ -672,11 +674,11 @@
result = res.result;
{p = (( res.p))-1;}
}
}
break;
-// line 678 "Parser.java"
+// line 680 "Parser.java"
}
}
}
case 2:
@@ -692,21 +694,21 @@
case 5:
}
break; }
}
-// line 477 "Parser.rl"
+// line 479 "Parser.rl"
if (cs >= JSON_value_first_final && result != null) {
res.update(result, p);
} else {
res.update(null, p);
}
}
-// line 708 "Parser.java"
+// line 710 "Parser.java"
private static byte[] init__JSON_integer_actions_0()
{
return new byte [] {
0, 1, 0
};
@@ -801,11 +803,11 @@
static final int JSON_integer_error = 0;
static final int JSON_integer_en_main = 1;
-// line 496 "Parser.rl"
+// line 498 "Parser.rl"
void parseInteger(ParserResult res, int p, int pe) {
int new_p = parseIntegerInternal(p, pe);
if (new_p == -1) {
@@ -819,19 +821,19 @@
int parseIntegerInternal(int p, int pe) {
int cs = EVIL;
-// line 825 "Parser.java"
+// line 827 "Parser.java"
{
cs = JSON_integer_start;
}
-// line 513 "Parser.rl"
+// line 515 "Parser.rl"
int memo = p;
-// line 833 "Parser.java"
+// line 835 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -908,17 +910,17 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_integer_actions[_acts++] )
{
case 0:
-// line 490 "Parser.rl"
+// line 492 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 920 "Parser.java"
+// line 922 "Parser.java"
}
}
}
case 2:
@@ -934,11 +936,11 @@
case 5:
}
break; }
}
-// line 515 "Parser.rl"
+// line 517 "Parser.rl"
if (cs < JSON_integer_first_final) {
return -1;
}
@@ -956,11 +958,11 @@
ConvertBytes.byteListToInum19(runtime, num, 10, true) :
ConvertBytes.byteListToInum(runtime, num, 10, true);
}
-// line 962 "Parser.java"
+// line 964 "Parser.java"
private static byte[] init__JSON_float_actions_0()
{
return new byte [] {
0, 1, 0
};
@@ -1058,11 +1060,11 @@
static final int JSON_float_error = 0;
static final int JSON_float_en_main = 1;
-// line 550 "Parser.rl"
+// line 552 "Parser.rl"
void parseFloat(ParserResult res, int p, int pe) {
int new_p = parseFloatInternal(p, pe);
if (new_p == -1) {
@@ -1076,19 +1078,19 @@
int parseFloatInternal(int p, int pe) {
int cs = EVIL;
-// line 1082 "Parser.java"
+// line 1084 "Parser.java"
{
cs = JSON_float_start;
}
-// line 567 "Parser.rl"
+// line 569 "Parser.rl"
int memo = p;
-// line 1090 "Parser.java"
+// line 1092 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -1165,17 +1167,17 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_float_actions[_acts++] )
{
case 0:
-// line 541 "Parser.rl"
+// line 543 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1177 "Parser.java"
+// line 1179 "Parser.java"
}
}
}
case 2:
@@ -1191,11 +1193,11 @@
case 5:
}
break; }
}
-// line 569 "Parser.rl"
+// line 571 "Parser.rl"
if (cs < JSON_float_first_final) {
return -1;
}
@@ -1207,11 +1209,11 @@
ByteList num = absSubSequence(p, new_p);
return RubyFloat.newFloat(runtime, dc.parse(num, true, runtime.is1_9()));
}
-// line 1213 "Parser.java"
+// line 1215 "Parser.java"
private static byte[] init__JSON_string_actions_0()
{
return new byte [] {
0, 2, 0, 1
};
@@ -1309,27 +1311,27 @@
static final int JSON_string_error = 0;
static final int JSON_string_en_main = 1;
-// line 614 "Parser.rl"
+// line 616 "Parser.rl"
void parseString(ParserResult res, int p, int pe) {
int cs = EVIL;
IRubyObject result = null;
-// line 1323 "Parser.java"
+// line 1325 "Parser.java"
{
cs = JSON_string_start;
}
-// line 621 "Parser.rl"
+// line 623 "Parser.rl"
int memo = p;
-// line 1331 "Parser.java"
+// line 1333 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -1406,11 +1408,11 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_string_actions[_acts++] )
{
case 0:
-// line 589 "Parser.rl"
+// line 591 "Parser.rl"
{
int offset = byteList.begin();
ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
p - offset);
result = getRuntime().newString(decoded);
@@ -1421,17 +1423,17 @@
{p = (( p + 1))-1;}
}
}
break;
case 1:
-// line 602 "Parser.rl"
+// line 604 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1433 "Parser.java"
+// line 1435 "Parser.java"
}
}
}
case 2:
@@ -1447,11 +1449,11 @@
case 5:
}
break; }
}
-// line 623 "Parser.rl"
+// line 625 "Parser.rl"
if (parser.createAdditions) {
RubyHash match_string = parser.match_string;
if (match_string != null) {
final IRubyObject[] memoArray = { result, null };
@@ -1474,23 +1476,22 @@
}
}
}
}
- if (cs >= JSON_string_first_final && result != null) {
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
+ if (cs >= JSON_string_first_final && result != null) {
if (info.encodingsSupported() && result instanceof RubyString) {
((RubyString)result).force_encoding(context, info.utf8.get());
}
res.update(result, p + 1);
} else {
res.update(null, p + 1);
}
}
-// line 1492 "Parser.java"
+// line 1493 "Parser.java"
private static byte[] init__JSON_array_actions_0()
{
return new byte [] {
0, 1, 0, 1, 1
};
@@ -1599,11 +1600,11 @@
static final int JSON_array_error = 0;
static final int JSON_array_en_main = 1;
-// line 697 "Parser.rl"
+// line 698 "Parser.rl"
void parseArray(ParserResult res, int p, int pe) {
int cs = EVIL;
@@ -1619,18 +1620,18 @@
result = parser.arrayClass.newInstance(context,
IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}
-// line 1625 "Parser.java"
+// line 1626 "Parser.java"
{
cs = JSON_array_start;
}
-// line 716 "Parser.rl"
+// line 717 "Parser.rl"
-// line 1632 "Parser.java"
+// line 1633 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -1707,11 +1708,11 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_array_actions[_acts++] )
{
case 0:
-// line 666 "Parser.rl"
+// line 667 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
@@ -1724,17 +1725,17 @@
{p = (( res.p))-1;}
}
}
break;
case 1:
-// line 681 "Parser.rl"
+// line 682 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1736 "Parser.java"
+// line 1737 "Parser.java"
}
}
}
case 2:
@@ -1750,21 +1751,21 @@
case 5:
}
break; }
}
-// line 717 "Parser.rl"
+// line 718 "Parser.rl"
if (cs >= JSON_array_first_final) {
res.update(result, p + 1);
} else {
throw unexpectedToken(p, pe);
}
}
-// line 1766 "Parser.java"
+// line 1767 "Parser.java"
private static byte[] init__JSON_object_actions_0()
{
return new byte [] {
0, 1, 0, 1, 1, 1, 2
};
@@ -1883,11 +1884,11 @@
static final int JSON_object_error = 0;
static final int JSON_object_en_main = 1;
-// line 776 "Parser.rl"
+// line 777 "Parser.rl"
void parseObject(ParserResult res, int p, int pe) {
int cs = EVIL;
IRubyObject lastName = null;
@@ -1908,18 +1909,18 @@
result = parser.objectClass.newInstance(context,
IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}
-// line 1914 "Parser.java"
+// line 1915 "Parser.java"
{
cs = JSON_object_start;
}
-// line 800 "Parser.rl"
+// line 801 "Parser.rl"
-// line 1921 "Parser.java"
+// line 1922 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -1996,11 +1997,11 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_object_actions[_acts++] )
{
case 0:
-// line 731 "Parser.rl"
+// line 732 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
@@ -2013,11 +2014,11 @@
{p = (( res.p))-1;}
}
}
break;
case 1:
-// line 746 "Parser.rl"
+// line 747 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
@@ -2033,17 +2034,17 @@
{p = (( res.p))-1;}
}
}
break;
case 2:
-// line 764 "Parser.rl"
+// line 765 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 2045 "Parser.java"
+// line 2046 "Parser.java"
}
}
}
case 2:
@@ -2059,11 +2060,11 @@
case 5:
}
break; }
}
-// line 801 "Parser.rl"
+// line 802 "Parser.rl"
if (cs < JSON_object_first_final) {
res.update(null, p + 1);
return;
}
@@ -2092,11 +2093,11 @@
}
res.update(returnedResult, p + 1);
}
-// line 2098 "Parser.java"
+// line 2099 "Parser.java"
private static byte[] init__JSON_actions_0()
{
return new byte [] {
0, 1, 0, 1, 1
};
@@ -2196,30 +2197,30 @@
static final int JSON_error = 0;
static final int JSON_en_main = 1;
-// line 866 "Parser.rl"
+// line 867 "Parser.rl"
public IRubyObject parseStrict() {
int cs = EVIL;
int p, pe;
IRubyObject result = null;
ParserResult res = new ParserResult();
-// line 2212 "Parser.java"
+// line 2213 "Parser.java"
{
cs = JSON_start;
}
-// line 875 "Parser.rl"
+// line 876 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2221 "Parser.java"
+// line 2222 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -2296,11 +2297,11 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_actions[_acts++] )
{
case 0:
-// line 838 "Parser.rl"
+// line 839 "Parser.rl"
{
currentNesting = 1;
parseObject(res, p, pe);
if (res.result == null) {
p--;
@@ -2310,11 +2311,11 @@
{p = (( res.p))-1;}
}
}
break;
case 1:
-// line 850 "Parser.rl"
+// line 851 "Parser.rl"
{
currentNesting = 1;
parseArray(res, p, pe);
if (res.result == null) {
p--;
@@ -2323,11 +2324,11 @@
result = res.result;
{p = (( res.p))-1;}
}
}
break;
-// line 2329 "Parser.java"
+// line 2330 "Parser.java"
}
}
}
case 2:
@@ -2343,21 +2344,21 @@
case 5:
}
break; }
}
-// line 878 "Parser.rl"
+// line 879 "Parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
throw unexpectedToken(p, pe);
}
}
-// line 2359 "Parser.java"
+// line 2360 "Parser.java"
private static byte[] init__JSON_quirks_mode_actions_0()
{
return new byte [] {
0, 1, 0
};
@@ -2456,30 +2457,30 @@
static final int JSON_quirks_mode_error = 0;
static final int JSON_quirks_mode_en_main = 1;
-// line 906 "Parser.rl"
+// line 907 "Parser.rl"
public IRubyObject parseQuirksMode() {
int cs = EVIL;
int p, pe;
IRubyObject result = null;
ParserResult res = new ParserResult();
-// line 2472 "Parser.java"
+// line 2473 "Parser.java"
{
cs = JSON_quirks_mode_start;
}
-// line 915 "Parser.rl"
+// line 916 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2481 "Parser.java"
+// line 2482 "Parser.java"
{
int _klen;
int _trans = 0;
int _acts;
int _nacts;
@@ -2556,11 +2557,11 @@
while ( _nacts-- > 0 )
{
switch ( _JSON_quirks_mode_actions[_acts++] )
{
case 0:
-// line 892 "Parser.rl"
+// line 893 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
@@ -2568,11 +2569,11 @@
result = res.result;
{p = (( res.p))-1;}
}
}
break;
-// line 2574 "Parser.java"
+// line 2575 "Parser.java"
}
}
}
case 2:
@@ -2588,10 +2589,10 @@
case 5:
}
break; }
}
-// line 918 "Parser.rl"
+// line 919 "Parser.rl"
if (cs >= JSON_quirks_mode_first_final && p == pe) {
return result;
} else {
throw unexpectedToken(p, pe);