json 1.8.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +5 -3
  4. data/CHANGES +5 -5
  5. data/Gemfile +3 -1
  6. data/README.md +131 -84
  7. data/Rakefile +17 -10
  8. data/VERSION +1 -1
  9. data/ext/json/ext/generator/generator.c +1 -52
  10. data/ext/json/ext/generator/generator.h +0 -5
  11. data/ext/json/ext/parser/extconf.rb +3 -0
  12. data/ext/json/ext/parser/parser.c +304 -458
  13. data/ext/json/ext/parser/parser.h +0 -1
  14. data/ext/json/ext/parser/parser.rl +35 -152
  15. data/ext/json/extconf.rb +0 -1
  16. data/java/src/json/ext/Generator.java +2 -5
  17. data/java/src/json/ext/GeneratorState.java +2 -54
  18. data/java/src/json/ext/OptionsReader.java +1 -1
  19. data/java/src/json/ext/Parser.java +109 -409
  20. data/java/src/json/ext/Parser.rl +24 -117
  21. data/java/src/json/ext/RuntimeInfo.java +0 -4
  22. data/json.gemspec +0 -0
  23. data/json_pure.gemspec +7 -7
  24. data/lib/json.rb +1 -0
  25. data/lib/json/add/bigdecimal.rb +1 -0
  26. data/lib/json/add/complex.rb +2 -1
  27. data/lib/json/add/core.rb +1 -0
  28. data/lib/json/add/date.rb +1 -1
  29. data/lib/json/add/date_time.rb +1 -1
  30. data/lib/json/add/exception.rb +1 -1
  31. data/lib/json/add/ostruct.rb +1 -1
  32. data/lib/json/add/range.rb +1 -1
  33. data/lib/json/add/rational.rb +1 -0
  34. data/lib/json/add/regexp.rb +1 -1
  35. data/lib/json/add/struct.rb +1 -1
  36. data/lib/json/add/symbol.rb +1 -1
  37. data/lib/json/add/time.rb +1 -1
  38. data/lib/json/common.rb +24 -52
  39. data/lib/json/ext.rb +0 -6
  40. data/lib/json/generic_object.rb +5 -4
  41. data/lib/json/pure.rb +2 -8
  42. data/lib/json/pure/generator.rb +51 -123
  43. data/lib/json/pure/parser.rb +28 -80
  44. data/lib/json/version.rb +2 -1
  45. data/references/rfc7159.txt +899 -0
  46. data/tests/fixtures/obsolete_fail1.json +1 -0
  47. data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
  48. data/tests/json_common_interface_test.rb +126 -0
  49. data/tests/json_encoding_test.rb +105 -0
  50. data/tests/json_ext_parser_test.rb +15 -0
  51. data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
  52. data/tests/{test_json_generate.rb → json_generator_test.rb} +65 -37
  53. data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
  54. data/tests/json_parser_test.rb +448 -0
  55. data/tests/json_string_matching_test.rb +38 -0
  56. data/tests/test_helper.rb +23 -0
  57. data/tools/fuzz.rb +1 -9
  58. metadata +19 -32
  59. data/TODO +0 -1
  60. data/tests/fixtures/fail1.json +0 -1
  61. data/tests/setup_variant.rb +0 -11
  62. data/tests/test_json.rb +0 -519
  63. data/tests/test_json_encoding.rb +0 -65
  64. data/tests/test_json_string_matching.rb +0 -39
  65. data/tests/test_json_unicode.rb +0 -72
@@ -52,10 +52,9 @@ public class Parser extends RubyObject {
52
52
  private int maxNesting;
53
53
  private boolean allowNaN;
54
54
  private boolean symbolizeNames;
55
- private boolean quirksMode;
56
55
  private RubyClass objectClass;
57
56
  private RubyClass arrayClass;
58
- private RubyHash match_string;
57
+ private RubyHash matchString;
59
58
 
60
59
  private static final int DEFAULT_MAX_NESTING = 100;
61
60
 
@@ -123,10 +122,6 @@ public class Parser extends RubyObject {
123
122
  * <dd>If set to <code>true</code>, returns symbols for the names (keys) in
124
123
  * a JSON object. Otherwise strings are returned, which is also the default.
125
124
  *
126
- * <dt><code>:quirks_mode?</code>
127
- * <dd>If set to <code>true</code>, if the parse is in quirks_mode, false
128
- * otherwise.
129
- *
130
125
  * <dt><code>:create_additions</code>
131
126
  * <dd>If set to <code>false</code>, the Parser doesn't create additions
132
127
  * even if a matching class and <code>create_id</code> was found. This option
@@ -138,9 +133,6 @@ public class Parser extends RubyObject {
138
133
  * <dt><code>:array_class</code>
139
134
  * <dd>Defaults to Array.
140
135
  *
141
- * <dt><code>:quirks_mode</code>
142
- * <dd>Enables quirks_mode for parser, that is for example parsing single
143
- * JSON values instead of documents is possible.
144
136
  * </dl>
145
137
  */
146
138
  @JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
@@ -163,15 +155,20 @@ public class Parser extends RubyObject {
163
155
  this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
164
156
  this.allowNaN = opts.getBool("allow_nan", false);
165
157
  this.symbolizeNames = opts.getBool("symbolize_names", false);
166
- this.quirksMode = opts.getBool("quirks_mode", false);
167
158
  this.createId = opts.getString("create_id", getCreateId(context));
168
159
  this.createAdditions = opts.getBool("create_additions", false);
169
160
  this.objectClass = opts.getClass("object_class", runtime.getHash());
170
161
  this.arrayClass = opts.getClass("array_class", runtime.getArray());
171
- this.match_string = opts.getHash("match_string");
162
+ this.matchString = opts.getHash("match_string");
172
163
 
164
+ if(symbolizeNames && createAdditions) {
165
+ throw runtime.newArgumentError(
166
+ "options :symbolize_names and :create_additions cannot be " +
167
+ " used in conjunction"
168
+ );
169
+ }
173
170
  this.vSource = args[0].convertToString();
174
- if (!quirksMode) this.vSource = convertEncoding(context, vSource);
171
+ this.vSource = convertEncoding(context, vSource);
175
172
 
176
173
  return this;
177
174
  }
@@ -182,33 +179,13 @@ public class Parser extends RubyObject {
182
179
  * Returns the source string if no conversion is needed.
183
180
  */
184
181
  private RubyString convertEncoding(ThreadContext context, RubyString source) {
185
- ByteList bl = source.getByteList();
186
- int len = bl.length();
187
- if (len < 2) {
188
- throw Utils.newException(context, Utils.M_PARSER_ERROR,
189
- "A JSON text must at least contain two octets!");
190
- }
191
-
192
- if (info.encodingsSupported()) {
193
- RubyEncoding encoding = (RubyEncoding)source.encoding(context);
194
- if (encoding != info.ascii8bit.get()) {
195
- return (RubyString)source.encode(context, info.utf8.get());
196
- }
197
-
198
- String sniffedEncoding = sniffByteList(bl);
199
- if (sniffedEncoding == null) return source; // assume UTF-8
200
- return reinterpretEncoding(context, source, sniffedEncoding);
201
- }
202
-
203
- String sniffedEncoding = sniffByteList(bl);
204
- if (sniffedEncoding == null) return source; // assume UTF-8
205
- Ruby runtime = context.getRuntime();
206
- return (RubyString)info.jsonModule.get().
207
- callMethod(context, "iconv",
208
- new IRubyObject[] {
209
- runtime.newString("utf-8"),
210
- runtime.newString(sniffedEncoding),
211
- source});
182
+ RubyEncoding encoding = (RubyEncoding)source.encoding(context);
183
+ if (encoding == info.ascii8bit.get()) {
184
+ source.force_encoding(context, info.utf8.get());
185
+ } else {
186
+ source = (RubyString) source.encode(context, info.utf8.get());
187
+ }
188
+ return source;
212
189
  }
213
190
 
214
191
  /**
@@ -261,17 +238,6 @@ public class Parser extends RubyObject {
261
238
  return checkAndGetSource().dup();
262
239
  }
263
240
 
264
- /**
265
- * <code>Parser#quirks_mode?()</code>
266
- *
267
- * <p>If set to <code>true</code>, if the parse is in quirks_mode, false
268
- * otherwise.
269
- */
270
- @JRubyMethod(name = "quirks_mode?")
271
- public IRubyObject quirks_mode_p(ThreadContext context) {
272
- return context.getRuntime().newBoolean(quirksMode);
273
- }
274
-
275
241
  public RubyString checkAndGetSource() {
276
242
  if (vSource != null) {
277
243
  return vSource;
@@ -338,11 +304,11 @@ public class Parser extends RubyObject {
338
304
  }
339
305
 
340
306
 
341
- // line 365 "Parser.rl"
307
+ // line 330 "Parser.rl"
342
308
 
343
309
 
344
310
 
345
- // line 347 "Parser.java"
311
+ // line 312 "Parser.java"
346
312
  private static byte[] init__JSON_value_actions_0()
347
313
  {
348
314
  return new byte [] {
@@ -456,7 +422,7 @@ static final int JSON_value_error = 0;
456
422
  static final int JSON_value_en_main = 1;
457
423
 
458
424
 
459
- // line 471 "Parser.rl"
425
+ // line 436 "Parser.rl"
460
426
 
461
427
 
462
428
  void parseValue(ParserResult res, int p, int pe) {
@@ -464,14 +430,14 @@ static final int JSON_value_en_main = 1;
464
430
  IRubyObject result = null;
465
431
 
466
432
 
467
- // line 469 "Parser.java"
433
+ // line 434 "Parser.java"
468
434
  {
469
435
  cs = JSON_value_start;
470
436
  }
471
437
 
472
- // line 478 "Parser.rl"
438
+ // line 443 "Parser.rl"
473
439
 
474
- // line 476 "Parser.java"
440
+ // line 441 "Parser.java"
475
441
  {
476
442
  int _klen;
477
443
  int _trans = 0;
@@ -497,13 +463,13 @@ case 1:
497
463
  while ( _nacts-- > 0 ) {
498
464
  switch ( _JSON_value_actions[_acts++] ) {
499
465
  case 9:
500
- // line 456 "Parser.rl"
466
+ // line 421 "Parser.rl"
501
467
  {
502
468
  p--;
503
469
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
504
470
  }
505
471
  break;
506
- // line 508 "Parser.java"
472
+ // line 473 "Parser.java"
507
473
  }
508
474
  }
509
475
 
@@ -566,25 +532,25 @@ case 1:
566
532
  switch ( _JSON_value_actions[_acts++] )
567
533
  {
568
534
  case 0:
569
- // line 373 "Parser.rl"
535
+ // line 338 "Parser.rl"
570
536
  {
571
537
  result = getRuntime().getNil();
572
538
  }
573
539
  break;
574
540
  case 1:
575
- // line 376 "Parser.rl"
541
+ // line 341 "Parser.rl"
576
542
  {
577
543
  result = getRuntime().getFalse();
578
544
  }
579
545
  break;
580
546
  case 2:
581
- // line 379 "Parser.rl"
547
+ // line 344 "Parser.rl"
582
548
  {
583
549
  result = getRuntime().getTrue();
584
550
  }
585
551
  break;
586
552
  case 3:
587
- // line 382 "Parser.rl"
553
+ // line 347 "Parser.rl"
588
554
  {
589
555
  if (parser.allowNaN) {
590
556
  result = getConstant(CONST_NAN);
@@ -594,7 +560,7 @@ case 1:
594
560
  }
595
561
  break;
596
562
  case 4:
597
- // line 389 "Parser.rl"
563
+ // line 354 "Parser.rl"
598
564
  {
599
565
  if (parser.allowNaN) {
600
566
  result = getConstant(CONST_INFINITY);
@@ -604,9 +570,9 @@ case 1:
604
570
  }
605
571
  break;
606
572
  case 5:
607
- // line 396 "Parser.rl"
573
+ // line 361 "Parser.rl"
608
574
  {
609
- if (pe > p + 9 - (parser.quirksMode ? 1 : 0) &&
575
+ if (pe > p + 8 &&
610
576
  absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
611
577
 
612
578
  if (parser.allowNaN) {
@@ -633,7 +599,7 @@ case 1:
633
599
  }
634
600
  break;
635
601
  case 6:
636
- // line 422 "Parser.rl"
602
+ // line 387 "Parser.rl"
637
603
  {
638
604
  parseString(res, p, pe);
639
605
  if (res.result == null) {
@@ -646,7 +612,7 @@ case 1:
646
612
  }
647
613
  break;
648
614
  case 7:
649
- // line 432 "Parser.rl"
615
+ // line 397 "Parser.rl"
650
616
  {
651
617
  currentNesting++;
652
618
  parseArray(res, p, pe);
@@ -661,7 +627,7 @@ case 1:
661
627
  }
662
628
  break;
663
629
  case 8:
664
- // line 444 "Parser.rl"
630
+ // line 409 "Parser.rl"
665
631
  {
666
632
  currentNesting++;
667
633
  parseObject(res, p, pe);
@@ -675,7 +641,7 @@ case 1:
675
641
  }
676
642
  }
677
643
  break;
678
- // line 680 "Parser.java"
644
+ // line 645 "Parser.java"
679
645
  }
680
646
  }
681
647
  }
@@ -695,7 +661,7 @@ case 5:
695
661
  break; }
696
662
  }
697
663
 
698
- // line 479 "Parser.rl"
664
+ // line 444 "Parser.rl"
699
665
 
700
666
  if (cs >= JSON_value_first_final && result != null) {
701
667
  res.update(result, p);
@@ -705,7 +671,7 @@ case 5:
705
671
  }
706
672
 
707
673
 
708
- // line 710 "Parser.java"
674
+ // line 675 "Parser.java"
709
675
  private static byte[] init__JSON_integer_actions_0()
710
676
  {
711
677
  return new byte [] {
@@ -804,7 +770,7 @@ static final int JSON_integer_error = 0;
804
770
  static final int JSON_integer_en_main = 1;
805
771
 
806
772
 
807
- // line 498 "Parser.rl"
773
+ // line 463 "Parser.rl"
808
774
 
809
775
 
810
776
  void parseInteger(ParserResult res, int p, int pe) {
@@ -822,15 +788,15 @@ static final int JSON_integer_en_main = 1;
822
788
  int cs = EVIL;
823
789
 
824
790
 
825
- // line 827 "Parser.java"
791
+ // line 792 "Parser.java"
826
792
  {
827
793
  cs = JSON_integer_start;
828
794
  }
829
795
 
830
- // line 515 "Parser.rl"
796
+ // line 480 "Parser.rl"
831
797
  int memo = p;
832
798
 
833
- // line 835 "Parser.java"
799
+ // line 800 "Parser.java"
834
800
  {
835
801
  int _klen;
836
802
  int _trans = 0;
@@ -911,13 +877,13 @@ case 1:
911
877
  switch ( _JSON_integer_actions[_acts++] )
912
878
  {
913
879
  case 0:
914
- // line 492 "Parser.rl"
880
+ // line 457 "Parser.rl"
915
881
  {
916
882
  p--;
917
883
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
918
884
  }
919
885
  break;
920
- // line 922 "Parser.java"
886
+ // line 887 "Parser.java"
921
887
  }
922
888
  }
923
889
  }
@@ -937,7 +903,7 @@ case 5:
937
903
  break; }
938
904
  }
939
905
 
940
- // line 517 "Parser.rl"
906
+ // line 482 "Parser.rl"
941
907
 
942
908
  if (cs < JSON_integer_first_final) {
943
909
  return -1;
@@ -959,7 +925,7 @@ case 5:
959
925
  }
960
926
 
961
927
 
962
- // line 964 "Parser.java"
928
+ // line 929 "Parser.java"
963
929
  private static byte[] init__JSON_float_actions_0()
964
930
  {
965
931
  return new byte [] {
@@ -1061,7 +1027,7 @@ static final int JSON_float_error = 0;
1061
1027
  static final int JSON_float_en_main = 1;
1062
1028
 
1063
1029
 
1064
- // line 552 "Parser.rl"
1030
+ // line 517 "Parser.rl"
1065
1031
 
1066
1032
 
1067
1033
  void parseFloat(ParserResult res, int p, int pe) {
@@ -1079,15 +1045,15 @@ static final int JSON_float_en_main = 1;
1079
1045
  int cs = EVIL;
1080
1046
 
1081
1047
 
1082
- // line 1084 "Parser.java"
1048
+ // line 1049 "Parser.java"
1083
1049
  {
1084
1050
  cs = JSON_float_start;
1085
1051
  }
1086
1052
 
1087
- // line 569 "Parser.rl"
1053
+ // line 534 "Parser.rl"
1088
1054
  int memo = p;
1089
1055
 
1090
- // line 1092 "Parser.java"
1056
+ // line 1057 "Parser.java"
1091
1057
  {
1092
1058
  int _klen;
1093
1059
  int _trans = 0;
@@ -1168,13 +1134,13 @@ case 1:
1168
1134
  switch ( _JSON_float_actions[_acts++] )
1169
1135
  {
1170
1136
  case 0:
1171
- // line 543 "Parser.rl"
1137
+ // line 508 "Parser.rl"
1172
1138
  {
1173
1139
  p--;
1174
1140
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1175
1141
  }
1176
1142
  break;
1177
- // line 1179 "Parser.java"
1143
+ // line 1144 "Parser.java"
1178
1144
  }
1179
1145
  }
1180
1146
  }
@@ -1194,7 +1160,7 @@ case 5:
1194
1160
  break; }
1195
1161
  }
1196
1162
 
1197
- // line 571 "Parser.rl"
1163
+ // line 536 "Parser.rl"
1198
1164
 
1199
1165
  if (cs < JSON_float_first_final) {
1200
1166
  return -1;
@@ -1210,7 +1176,7 @@ case 5:
1210
1176
  }
1211
1177
 
1212
1178
 
1213
- // line 1215 "Parser.java"
1179
+ // line 1180 "Parser.java"
1214
1180
  private static byte[] init__JSON_string_actions_0()
1215
1181
  {
1216
1182
  return new byte [] {
@@ -1312,7 +1278,7 @@ static final int JSON_string_error = 0;
1312
1278
  static final int JSON_string_en_main = 1;
1313
1279
 
1314
1280
 
1315
- // line 616 "Parser.rl"
1281
+ // line 581 "Parser.rl"
1316
1282
 
1317
1283
 
1318
1284
  void parseString(ParserResult res, int p, int pe) {
@@ -1320,15 +1286,15 @@ static final int JSON_string_en_main = 1;
1320
1286
  IRubyObject result = null;
1321
1287
 
1322
1288
 
1323
- // line 1325 "Parser.java"
1289
+ // line 1290 "Parser.java"
1324
1290
  {
1325
1291
  cs = JSON_string_start;
1326
1292
  }
1327
1293
 
1328
- // line 623 "Parser.rl"
1294
+ // line 588 "Parser.rl"
1329
1295
  int memo = p;
1330
1296
 
1331
- // line 1333 "Parser.java"
1297
+ // line 1298 "Parser.java"
1332
1298
  {
1333
1299
  int _klen;
1334
1300
  int _trans = 0;
@@ -1409,7 +1375,7 @@ case 1:
1409
1375
  switch ( _JSON_string_actions[_acts++] )
1410
1376
  {
1411
1377
  case 0:
1412
- // line 591 "Parser.rl"
1378
+ // line 556 "Parser.rl"
1413
1379
  {
1414
1380
  int offset = byteList.begin();
1415
1381
  ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
@@ -1424,13 +1390,13 @@ case 1:
1424
1390
  }
1425
1391
  break;
1426
1392
  case 1:
1427
- // line 604 "Parser.rl"
1393
+ // line 569 "Parser.rl"
1428
1394
  {
1429
1395
  p--;
1430
1396
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1431
1397
  }
1432
1398
  break;
1433
- // line 1435 "Parser.java"
1399
+ // line 1400 "Parser.java"
1434
1400
  }
1435
1401
  }
1436
1402
  }
@@ -1450,14 +1416,14 @@ case 5:
1450
1416
  break; }
1451
1417
  }
1452
1418
 
1453
- // line 625 "Parser.rl"
1419
+ // line 590 "Parser.rl"
1454
1420
 
1455
1421
  if (parser.createAdditions) {
1456
- RubyHash match_string = parser.match_string;
1457
- if (match_string != null) {
1422
+ RubyHash matchString = parser.matchString;
1423
+ if (matchString != null) {
1458
1424
  final IRubyObject[] memoArray = { result, null };
1459
1425
  try {
1460
- match_string.visitAll(new RubyHash.Visitor() {
1426
+ matchString.visitAll(new RubyHash.Visitor() {
1461
1427
  @Override
1462
1428
  public void visit(IRubyObject pattern, IRubyObject klass) {
1463
1429
  if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
@@ -1478,7 +1444,7 @@ case 5:
1478
1444
  }
1479
1445
 
1480
1446
  if (cs >= JSON_string_first_final && result != null) {
1481
- if (info.encodingsSupported() && result instanceof RubyString) {
1447
+ if (result instanceof RubyString) {
1482
1448
  ((RubyString)result).force_encoding(context, info.utf8.get());
1483
1449
  }
1484
1450
  res.update(result, p + 1);
@@ -1488,7 +1454,7 @@ case 5:
1488
1454
  }
1489
1455
 
1490
1456
 
1491
- // line 1493 "Parser.java"
1457
+ // line 1458 "Parser.java"
1492
1458
  private static byte[] init__JSON_array_actions_0()
1493
1459
  {
1494
1460
  return new byte [] {
@@ -1601,7 +1567,7 @@ static final int JSON_array_error = 0;
1601
1567
  static final int JSON_array_en_main = 1;
1602
1568
 
1603
1569
 
1604
- // line 698 "Parser.rl"
1570
+ // line 663 "Parser.rl"
1605
1571
 
1606
1572
 
1607
1573
  void parseArray(ParserResult res, int p, int pe) {
@@ -1621,14 +1587,14 @@ static final int JSON_array_en_main = 1;
1621
1587
  }
1622
1588
 
1623
1589
 
1624
- // line 1626 "Parser.java"
1590
+ // line 1591 "Parser.java"
1625
1591
  {
1626
1592
  cs = JSON_array_start;
1627
1593
  }
1628
1594
 
1629
- // line 717 "Parser.rl"
1595
+ // line 682 "Parser.rl"
1630
1596
 
1631
- // line 1633 "Parser.java"
1597
+ // line 1598 "Parser.java"
1632
1598
  {
1633
1599
  int _klen;
1634
1600
  int _trans = 0;
@@ -1709,7 +1675,7 @@ case 1:
1709
1675
  switch ( _JSON_array_actions[_acts++] )
1710
1676
  {
1711
1677
  case 0:
1712
- // line 667 "Parser.rl"
1678
+ // line 632 "Parser.rl"
1713
1679
  {
1714
1680
  parseValue(res, p, pe);
1715
1681
  if (res.result == null) {
@@ -1726,13 +1692,13 @@ case 1:
1726
1692
  }
1727
1693
  break;
1728
1694
  case 1:
1729
- // line 682 "Parser.rl"
1695
+ // line 647 "Parser.rl"
1730
1696
  {
1731
1697
  p--;
1732
1698
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1733
1699
  }
1734
1700
  break;
1735
- // line 1737 "Parser.java"
1701
+ // line 1702 "Parser.java"
1736
1702
  }
1737
1703
  }
1738
1704
  }
@@ -1752,7 +1718,7 @@ case 5:
1752
1718
  break; }
1753
1719
  }
1754
1720
 
1755
- // line 718 "Parser.rl"
1721
+ // line 683 "Parser.rl"
1756
1722
 
1757
1723
  if (cs >= JSON_array_first_final) {
1758
1724
  res.update(result, p + 1);
@@ -1762,7 +1728,7 @@ case 5:
1762
1728
  }
1763
1729
 
1764
1730
 
1765
- // line 1767 "Parser.java"
1731
+ // line 1732 "Parser.java"
1766
1732
  private static byte[] init__JSON_object_actions_0()
1767
1733
  {
1768
1734
  return new byte [] {
@@ -1885,7 +1851,7 @@ static final int JSON_object_error = 0;
1885
1851
  static final int JSON_object_en_main = 1;
1886
1852
 
1887
1853
 
1888
- // line 777 "Parser.rl"
1854
+ // line 742 "Parser.rl"
1889
1855
 
1890
1856
 
1891
1857
  void parseObject(ParserResult res, int p, int pe) {
@@ -1910,14 +1876,14 @@ static final int JSON_object_en_main = 1;
1910
1876
  }
1911
1877
 
1912
1878
 
1913
- // line 1915 "Parser.java"
1879
+ // line 1880 "Parser.java"
1914
1880
  {
1915
1881
  cs = JSON_object_start;
1916
1882
  }
1917
1883
 
1918
- // line 801 "Parser.rl"
1884
+ // line 766 "Parser.rl"
1919
1885
 
1920
- // line 1922 "Parser.java"
1886
+ // line 1887 "Parser.java"
1921
1887
  {
1922
1888
  int _klen;
1923
1889
  int _trans = 0;
@@ -1998,7 +1964,7 @@ case 1:
1998
1964
  switch ( _JSON_object_actions[_acts++] )
1999
1965
  {
2000
1966
  case 0:
2001
- // line 732 "Parser.rl"
1967
+ // line 697 "Parser.rl"
2002
1968
  {
2003
1969
  parseValue(res, p, pe);
2004
1970
  if (res.result == null) {
@@ -2015,7 +1981,7 @@ case 1:
2015
1981
  }
2016
1982
  break;
2017
1983
  case 1:
2018
- // line 747 "Parser.rl"
1984
+ // line 712 "Parser.rl"
2019
1985
  {
2020
1986
  parseString(res, p, pe);
2021
1987
  if (res.result == null) {
@@ -2035,13 +2001,13 @@ case 1:
2035
2001
  }
2036
2002
  break;
2037
2003
  case 2:
2038
- // line 765 "Parser.rl"
2004
+ // line 730 "Parser.rl"
2039
2005
  {
2040
2006
  p--;
2041
2007
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
2042
2008
  }
2043
2009
  break;
2044
- // line 2046 "Parser.java"
2010
+ // line 2011 "Parser.java"
2045
2011
  }
2046
2012
  }
2047
2013
  }
@@ -2061,7 +2027,7 @@ case 5:
2061
2027
  break; }
2062
2028
  }
2063
2029
 
2064
- // line 802 "Parser.rl"
2030
+ // line 767 "Parser.rl"
2065
2031
 
2066
2032
  if (cs < JSON_object_first_final) {
2067
2033
  res.update(null, p + 1);
@@ -2094,11 +2060,11 @@ case 5:
2094
2060
  }
2095
2061
 
2096
2062
 
2097
- // line 2099 "Parser.java"
2063
+ // line 2064 "Parser.java"
2098
2064
  private static byte[] init__JSON_actions_0()
2099
2065
  {
2100
2066
  return new byte [] {
2101
- 0, 1, 0, 1, 1
2067
+ 0, 1, 0
2102
2068
  };
2103
2069
  }
2104
2070
 
@@ -2108,7 +2074,7 @@ private static final byte _JSON_actions[] = init__JSON_actions_0();
2108
2074
  private static byte[] init__JSON_key_offsets_0()
2109
2075
  {
2110
2076
  return new byte [] {
2111
- 0, 0, 7, 9, 10, 12, 13, 15, 16, 18, 19
2077
+ 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28
2112
2078
  };
2113
2079
  }
2114
2080
 
@@ -2118,9 +2084,9 @@ private static final byte _JSON_key_offsets[] = init__JSON_key_offsets_0();
2118
2084
  private static char[] init__JSON_trans_keys_0()
2119
2085
  {
2120
2086
  return new char [] {
2121
- 13, 32, 47, 91, 123, 9, 10, 42, 47, 42, 42, 47,
2122
- 10, 42, 47, 42, 42, 47, 10, 13, 32, 47, 9, 10,
2123
- 0
2087
+ 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123,
2088
+ 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47,
2089
+ 42, 42, 47, 10, 13, 32, 47, 9, 10, 0
2124
2090
  };
2125
2091
  }
2126
2092
 
@@ -2130,7 +2096,7 @@ private static final char _JSON_trans_keys[] = init__JSON_trans_keys_0();
2130
2096
  private static byte[] init__JSON_single_lengths_0()
2131
2097
  {
2132
2098
  return new byte [] {
2133
- 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, 3
2099
+ 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3
2134
2100
  };
2135
2101
  }
2136
2102
 
@@ -2140,7 +2106,7 @@ private static final byte _JSON_single_lengths[] = init__JSON_single_lengths_0()
2140
2106
  private static byte[] init__JSON_range_lengths_0()
2141
2107
  {
2142
2108
  return new byte [] {
2143
- 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
2109
+ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1
2144
2110
  };
2145
2111
  }
2146
2112
 
@@ -2150,7 +2116,7 @@ private static final byte _JSON_range_lengths[] = init__JSON_range_lengths_0();
2150
2116
  private static byte[] init__JSON_index_offsets_0()
2151
2117
  {
2152
2118
  return new byte [] {
2153
- 0, 0, 7, 10, 12, 15, 17, 20, 22, 25, 27
2119
+ 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35
2154
2120
  };
2155
2121
  }
2156
2122
 
@@ -2160,9 +2126,10 @@ private static final byte _JSON_index_offsets[] = init__JSON_index_offsets_0();
2160
2126
  private static byte[] init__JSON_indicies_0()
2161
2127
  {
2162
2128
  return new byte [] {
2163
- 0, 0, 2, 3, 4, 0, 1, 5, 6, 1, 7, 5,
2164
- 7, 0, 5, 0, 6, 8, 9, 1, 10, 8, 10, 11,
2165
- 8, 11, 9, 11, 11, 12, 11, 1, 0
2129
+ 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2,
2130
+ 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7,
2131
+ 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7,
2132
+ 7, 11, 7, 1, 0
2166
2133
  };
2167
2134
  }
2168
2135
 
@@ -2172,8 +2139,7 @@ private static final byte _JSON_indicies[] = init__JSON_indicies_0();
2172
2139
  private static byte[] init__JSON_trans_targs_0()
2173
2140
  {
2174
2141
  return new byte [] {
2175
- 1, 0, 2, 10, 10, 3, 5, 4, 7, 9, 8, 10,
2176
- 6
2142
+ 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2
2177
2143
  };
2178
2144
  }
2179
2145
 
@@ -2183,8 +2149,7 @@ private static final byte _JSON_trans_targs[] = init__JSON_trans_targs_0();
2183
2149
  private static byte[] init__JSON_trans_actions_0()
2184
2150
  {
2185
2151
  return new byte [] {
2186
- 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0,
2187
- 0
2152
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
2188
2153
  };
2189
2154
  }
2190
2155
 
@@ -2198,26 +2163,26 @@ static final int JSON_error = 0;
2198
2163
  static final int JSON_en_main = 1;
2199
2164
 
2200
2165
 
2201
- // line 867 "Parser.rl"
2166
+ // line 818 "Parser.rl"
2202
2167
 
2203
2168
 
2204
- public IRubyObject parseStrict() {
2169
+ public IRubyObject parseImplemetation() {
2205
2170
  int cs = EVIL;
2206
2171
  int p, pe;
2207
2172
  IRubyObject result = null;
2208
2173
  ParserResult res = new ParserResult();
2209
2174
 
2210
2175
 
2211
- // line 2213 "Parser.java"
2176
+ // line 2177 "Parser.java"
2212
2177
  {
2213
2178
  cs = JSON_start;
2214
2179
  }
2215
2180
 
2216
- // line 876 "Parser.rl"
2181
+ // line 827 "Parser.rl"
2217
2182
  p = byteList.begin();
2218
2183
  pe = p + byteList.length();
2219
2184
 
2220
- // line 2222 "Parser.java"
2185
+ // line 2186 "Parser.java"
2221
2186
  {
2222
2187
  int _klen;
2223
2188
  int _trans = 0;
@@ -2298,267 +2263,7 @@ case 1:
2298
2263
  switch ( _JSON_actions[_acts++] )
2299
2264
  {
2300
2265
  case 0:
2301
- // line 839 "Parser.rl"
2302
- {
2303
- currentNesting = 1;
2304
- parseObject(res, p, pe);
2305
- if (res.result == null) {
2306
- p--;
2307
- { p += 1; _goto_targ = 5; if (true) continue _goto;}
2308
- } else {
2309
- result = res.result;
2310
- {p = (( res.p))-1;}
2311
- }
2312
- }
2313
- break;
2314
- case 1:
2315
- // line 851 "Parser.rl"
2316
- {
2317
- currentNesting = 1;
2318
- parseArray(res, p, pe);
2319
- if (res.result == null) {
2320
- p--;
2321
- { p += 1; _goto_targ = 5; if (true) continue _goto;}
2322
- } else {
2323
- result = res.result;
2324
- {p = (( res.p))-1;}
2325
- }
2326
- }
2327
- break;
2328
- // line 2330 "Parser.java"
2329
- }
2330
- }
2331
- }
2332
-
2333
- case 2:
2334
- if ( cs == 0 ) {
2335
- _goto_targ = 5;
2336
- continue _goto;
2337
- }
2338
- if ( ++p != pe ) {
2339
- _goto_targ = 1;
2340
- continue _goto;
2341
- }
2342
- case 4:
2343
- case 5:
2344
- }
2345
- break; }
2346
- }
2347
-
2348
- // line 879 "Parser.rl"
2349
-
2350
- if (cs >= JSON_first_final && p == pe) {
2351
- return result;
2352
- } else {
2353
- throw unexpectedToken(p, pe);
2354
- }
2355
- }
2356
-
2357
-
2358
- // line 2360 "Parser.java"
2359
- private static byte[] init__JSON_quirks_mode_actions_0()
2360
- {
2361
- return new byte [] {
2362
- 0, 1, 0
2363
- };
2364
- }
2365
-
2366
- private static final byte _JSON_quirks_mode_actions[] = init__JSON_quirks_mode_actions_0();
2367
-
2368
-
2369
- private static byte[] init__JSON_quirks_mode_key_offsets_0()
2370
- {
2371
- return new byte [] {
2372
- 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28
2373
- };
2374
- }
2375
-
2376
- private static final byte _JSON_quirks_mode_key_offsets[] = init__JSON_quirks_mode_key_offsets_0();
2377
-
2378
-
2379
- private static char[] init__JSON_quirks_mode_trans_keys_0()
2380
- {
2381
- return new char [] {
2382
- 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123,
2383
- 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47,
2384
- 42, 42, 47, 10, 13, 32, 47, 9, 10, 0
2385
- };
2386
- }
2387
-
2388
- private static final char _JSON_quirks_mode_trans_keys[] = init__JSON_quirks_mode_trans_keys_0();
2389
-
2390
-
2391
- private static byte[] init__JSON_quirks_mode_single_lengths_0()
2392
- {
2393
- return new byte [] {
2394
- 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3
2395
- };
2396
- }
2397
-
2398
- private static final byte _JSON_quirks_mode_single_lengths[] = init__JSON_quirks_mode_single_lengths_0();
2399
-
2400
-
2401
- private static byte[] init__JSON_quirks_mode_range_lengths_0()
2402
- {
2403
- return new byte [] {
2404
- 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1
2405
- };
2406
- }
2407
-
2408
- private static final byte _JSON_quirks_mode_range_lengths[] = init__JSON_quirks_mode_range_lengths_0();
2409
-
2410
-
2411
- private static byte[] init__JSON_quirks_mode_index_offsets_0()
2412
- {
2413
- return new byte [] {
2414
- 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35
2415
- };
2416
- }
2417
-
2418
- private static final byte _JSON_quirks_mode_index_offsets[] = init__JSON_quirks_mode_index_offsets_0();
2419
-
2420
-
2421
- private static byte[] init__JSON_quirks_mode_indicies_0()
2422
- {
2423
- return new byte [] {
2424
- 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2,
2425
- 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7,
2426
- 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7,
2427
- 7, 11, 7, 1, 0
2428
- };
2429
- }
2430
-
2431
- private static final byte _JSON_quirks_mode_indicies[] = init__JSON_quirks_mode_indicies_0();
2432
-
2433
-
2434
- private static byte[] init__JSON_quirks_mode_trans_targs_0()
2435
- {
2436
- return new byte [] {
2437
- 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2
2438
- };
2439
- }
2440
-
2441
- private static final byte _JSON_quirks_mode_trans_targs[] = init__JSON_quirks_mode_trans_targs_0();
2442
-
2443
-
2444
- private static byte[] init__JSON_quirks_mode_trans_actions_0()
2445
- {
2446
- return new byte [] {
2447
- 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
2448
- };
2449
- }
2450
-
2451
- private static final byte _JSON_quirks_mode_trans_actions[] = init__JSON_quirks_mode_trans_actions_0();
2452
-
2453
-
2454
- static final int JSON_quirks_mode_start = 1;
2455
- static final int JSON_quirks_mode_first_final = 10;
2456
- static final int JSON_quirks_mode_error = 0;
2457
-
2458
- static final int JSON_quirks_mode_en_main = 1;
2459
-
2460
-
2461
- // line 907 "Parser.rl"
2462
-
2463
-
2464
- public IRubyObject parseQuirksMode() {
2465
- int cs = EVIL;
2466
- int p, pe;
2467
- IRubyObject result = null;
2468
- ParserResult res = new ParserResult();
2469
-
2470
-
2471
- // line 2473 "Parser.java"
2472
- {
2473
- cs = JSON_quirks_mode_start;
2474
- }
2475
-
2476
- // line 916 "Parser.rl"
2477
- p = byteList.begin();
2478
- pe = p + byteList.length();
2479
-
2480
- // line 2482 "Parser.java"
2481
- {
2482
- int _klen;
2483
- int _trans = 0;
2484
- int _acts;
2485
- int _nacts;
2486
- int _keys;
2487
- int _goto_targ = 0;
2488
-
2489
- _goto: while (true) {
2490
- switch ( _goto_targ ) {
2491
- case 0:
2492
- if ( p == pe ) {
2493
- _goto_targ = 4;
2494
- continue _goto;
2495
- }
2496
- if ( cs == 0 ) {
2497
- _goto_targ = 5;
2498
- continue _goto;
2499
- }
2500
- case 1:
2501
- _match: do {
2502
- _keys = _JSON_quirks_mode_key_offsets[cs];
2503
- _trans = _JSON_quirks_mode_index_offsets[cs];
2504
- _klen = _JSON_quirks_mode_single_lengths[cs];
2505
- if ( _klen > 0 ) {
2506
- int _lower = _keys;
2507
- int _mid;
2508
- int _upper = _keys + _klen - 1;
2509
- while (true) {
2510
- if ( _upper < _lower )
2511
- break;
2512
-
2513
- _mid = _lower + ((_upper-_lower) >> 1);
2514
- if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] )
2515
- _upper = _mid - 1;
2516
- else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid] )
2517
- _lower = _mid + 1;
2518
- else {
2519
- _trans += (_mid - _keys);
2520
- break _match;
2521
- }
2522
- }
2523
- _keys += _klen;
2524
- _trans += _klen;
2525
- }
2526
-
2527
- _klen = _JSON_quirks_mode_range_lengths[cs];
2528
- if ( _klen > 0 ) {
2529
- int _lower = _keys;
2530
- int _mid;
2531
- int _upper = _keys + (_klen<<1) - 2;
2532
- while (true) {
2533
- if ( _upper < _lower )
2534
- break;
2535
-
2536
- _mid = _lower + (((_upper-_lower) >> 1) & ~1);
2537
- if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] )
2538
- _upper = _mid - 2;
2539
- else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid+1] )
2540
- _lower = _mid + 2;
2541
- else {
2542
- _trans += ((_mid - _keys)>>1);
2543
- break _match;
2544
- }
2545
- }
2546
- _trans += _klen;
2547
- }
2548
- } while (false);
2549
-
2550
- _trans = _JSON_quirks_mode_indicies[_trans];
2551
- cs = _JSON_quirks_mode_trans_targs[_trans];
2552
-
2553
- if ( _JSON_quirks_mode_trans_actions[_trans] != 0 ) {
2554
- _acts = _JSON_quirks_mode_trans_actions[_trans];
2555
- _nacts = (int) _JSON_quirks_mode_actions[_acts++];
2556
- while ( _nacts-- > 0 )
2557
- {
2558
- switch ( _JSON_quirks_mode_actions[_acts++] )
2559
- {
2560
- case 0:
2561
- // line 893 "Parser.rl"
2266
+ // line 804 "Parser.rl"
2562
2267
  {
2563
2268
  parseValue(res, p, pe);
2564
2269
  if (res.result == null) {
@@ -2570,7 +2275,7 @@ case 1:
2570
2275
  }
2571
2276
  }
2572
2277
  break;
2573
- // line 2575 "Parser.java"
2278
+ // line 2279 "Parser.java"
2574
2279
  }
2575
2280
  }
2576
2281
  }
@@ -2590,9 +2295,9 @@ case 5:
2590
2295
  break; }
2591
2296
  }
2592
2297
 
2593
- // line 919 "Parser.rl"
2298
+ // line 830 "Parser.rl"
2594
2299
 
2595
- if (cs >= JSON_quirks_mode_first_final && p == pe) {
2300
+ if (cs >= JSON_first_final && p == pe) {
2596
2301
  return result;
2597
2302
  } else {
2598
2303
  throw unexpectedToken(p, pe);
@@ -2600,12 +2305,7 @@ case 5:
2600
2305
  }
2601
2306
 
2602
2307
  public IRubyObject parse() {
2603
- if (parser.quirksMode) {
2604
- return parseQuirksMode();
2605
- } else {
2606
- return parseStrict();
2607
- }
2608
-
2308
+ return parseImplemetation();
2609
2309
  }
2610
2310
 
2611
2311
  /**