json 2.0.4 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +9 -4
- data/CHANGES.md +6 -0
- data/Gemfile +1 -3
- data/LICENSE +56 -0
- data/README.md +38 -21
- data/Rakefile +12 -7
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +96 -40
- data/ext/json/ext/parser/parser.c +124 -80
- data/ext/json/ext/parser/parser.h +1 -0
- data/ext/json/ext/parser/parser.rl +51 -7
- data/java/src/json/ext/Generator.java +33 -10
- data/java/src/json/ext/Parser.java +95 -80
- data/java/src/json/ext/Parser.rl +25 -10
- data/json-java.gemspec +1 -2
- data/json.gemspec +0 -0
- data/json_pure.gemspec +5 -5
- data/lib/json/add/bigdecimal.rb +2 -2
- data/lib/json/add/complex.rb +2 -2
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/rational.rb +2 -2
- data/lib/json/add/regexp.rb +2 -2
- data/lib/json/add/set.rb +29 -0
- data/lib/json/common.rb +2 -2
- data/lib/json/pure/generator.rb +2 -1
- data/lib/json/pure/parser.rb +13 -1
- data/lib/json/version.rb +1 -1
- data/tests/json_addition_test.rb +10 -0
- data/tests/json_common_interface_test.rb +4 -4
- data/tests/json_encoding_test.rb +2 -2
- data/tests/json_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +18 -12
- data/tests/test_helper.rb +0 -4
- metadata +5 -7
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
@@ -25,7 +25,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
25
25
|
|
26
26
|
/* unicode */
|
27
27
|
|
28
|
-
static const char digit_values[256] = {
|
28
|
+
static const signed char digit_values[256] = {
|
29
29
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
30
30
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
@@ -44,7 +44,7 @@ static const char digit_values[256] = {
|
|
44
44
|
|
45
45
|
static UTF32 unescape_unicode(const unsigned char *p)
|
46
46
|
{
|
47
|
-
char b;
|
47
|
+
signed char b;
|
48
48
|
UTF32 result = 0;
|
49
49
|
b = digit_values[p[0]];
|
50
50
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
@@ -89,11 +89,13 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
89
89
|
|
90
90
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
91
91
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
92
|
+
static VALUE cBigDecimal = Qundef;
|
92
93
|
|
93
94
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
94
95
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
95
|
-
i_object_class, i_array_class,
|
96
|
-
i_match_string, i_aset, i_aref,
|
96
|
+
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
97
|
+
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
98
|
+
i_leftshift, i_new, i_BigDecimal;
|
97
99
|
|
98
100
|
%%{
|
99
101
|
machine JSON_common;
|
@@ -338,6 +340,19 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
338
340
|
) (^[0-9Ee.\-]? @exit );
|
339
341
|
}%%
|
340
342
|
|
343
|
+
static int is_bigdecimal_class(VALUE obj)
|
344
|
+
{
|
345
|
+
if (cBigDecimal == Qundef) {
|
346
|
+
if (rb_const_defined(rb_cObject, i_BigDecimal)) {
|
347
|
+
cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
|
348
|
+
}
|
349
|
+
else {
|
350
|
+
return 0;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
return obj == cBigDecimal;
|
354
|
+
}
|
355
|
+
|
341
356
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
342
357
|
{
|
343
358
|
int cs = EVIL;
|
@@ -351,7 +366,17 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
351
366
|
fbuffer_clear(json->fbuffer);
|
352
367
|
fbuffer_append(json->fbuffer, json->memo, len);
|
353
368
|
fbuffer_append_char(json->fbuffer, '\0');
|
354
|
-
|
369
|
+
if (NIL_P(json->decimal_class)) {
|
370
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
371
|
+
} else {
|
372
|
+
VALUE text;
|
373
|
+
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
374
|
+
if (is_bigdecimal_class(json->decimal_class)) {
|
375
|
+
*result = rb_funcall(Qnil, i_BigDecimal, 1, text);
|
376
|
+
} else {
|
377
|
+
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
378
|
+
}
|
379
|
+
}
|
355
380
|
return p + 1;
|
356
381
|
} else {
|
357
382
|
return NULL;
|
@@ -546,7 +571,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
546
571
|
|
547
572
|
if (json->symbolize_names && json->parsing_name) {
|
548
573
|
*result = rb_str_intern(*result);
|
549
|
-
} else {
|
574
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
550
575
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
551
576
|
}
|
552
577
|
if (cs >= JSON_string_first_final) {
|
@@ -684,6 +709,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
684
709
|
} else {
|
685
710
|
json->array_class = Qnil;
|
686
711
|
}
|
712
|
+
tmp = ID2SYM(i_decimal_class);
|
713
|
+
if (option_given_p(opts, tmp)) {
|
714
|
+
json->decimal_class = rb_hash_aref(opts, tmp);
|
715
|
+
} else {
|
716
|
+
json->decimal_class = Qnil;
|
717
|
+
}
|
687
718
|
tmp = ID2SYM(i_match_string);
|
688
719
|
if (option_given_p(opts, tmp)) {
|
689
720
|
VALUE match_string = rb_hash_aref(opts, tmp);
|
@@ -697,10 +728,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
697
728
|
} else {
|
698
729
|
json->max_nesting = 100;
|
699
730
|
json->allow_nan = 0;
|
700
|
-
json->create_additions =
|
731
|
+
json->create_additions = 0;
|
701
732
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
702
733
|
json->object_class = Qnil;
|
703
734
|
json->array_class = Qnil;
|
735
|
+
json->decimal_class = Qnil;
|
704
736
|
}
|
705
737
|
source = convert_encoding(StringValue(source));
|
706
738
|
StringValue(source);
|
@@ -760,6 +792,7 @@ static void JSON_mark(void *ptr)
|
|
760
792
|
rb_gc_mark_maybe(json->create_id);
|
761
793
|
rb_gc_mark_maybe(json->object_class);
|
762
794
|
rb_gc_mark_maybe(json->array_class);
|
795
|
+
rb_gc_mark_maybe(json->decimal_class);
|
763
796
|
rb_gc_mark_maybe(json->match_string);
|
764
797
|
}
|
765
798
|
|
@@ -809,20 +842,28 @@ static VALUE cParser_source(VALUE self)
|
|
809
842
|
|
810
843
|
void Init_parser(void)
|
811
844
|
{
|
845
|
+
#undef rb_intern
|
812
846
|
rb_require("json/common");
|
813
847
|
mJSON = rb_define_module("JSON");
|
814
848
|
mExt = rb_define_module_under(mJSON, "Ext");
|
815
849
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
816
850
|
eParserError = rb_path2class("JSON::ParserError");
|
817
851
|
eNestingError = rb_path2class("JSON::NestingError");
|
852
|
+
rb_gc_register_mark_object(eParserError);
|
853
|
+
rb_gc_register_mark_object(eNestingError);
|
818
854
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
819
855
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
820
856
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
821
857
|
rb_define_method(cParser, "source", cParser_source, 0);
|
822
858
|
|
823
859
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
860
|
+
rb_gc_register_mark_object(CNaN);
|
861
|
+
|
824
862
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
863
|
+
rb_gc_register_mark_object(CInfinity);
|
864
|
+
|
825
865
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
866
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
826
867
|
|
827
868
|
i_json_creatable_p = rb_intern("json_creatable?");
|
828
869
|
i_json_create = rb_intern("json_create");
|
@@ -834,6 +875,7 @@ void Init_parser(void)
|
|
834
875
|
i_symbolize_names = rb_intern("symbolize_names");
|
835
876
|
i_object_class = rb_intern("object_class");
|
836
877
|
i_array_class = rb_intern("array_class");
|
878
|
+
i_decimal_class = rb_intern("decimal_class");
|
837
879
|
i_match = rb_intern("match");
|
838
880
|
i_match_string = rb_intern("match_string");
|
839
881
|
i_key_p = rb_intern("key?");
|
@@ -841,6 +883,8 @@ void Init_parser(void)
|
|
841
883
|
i_aset = rb_intern("[]=");
|
842
884
|
i_aref = rb_intern("[]");
|
843
885
|
i_leftshift = rb_intern("<<");
|
886
|
+
i_new = rb_intern("new");
|
887
|
+
i_BigDecimal = rb_intern("BigDecimal");
|
844
888
|
}
|
845
889
|
|
846
890
|
/*
|
@@ -7,6 +7,7 @@ package json.ext;
|
|
7
7
|
|
8
8
|
import org.jruby.Ruby;
|
9
9
|
import org.jruby.RubyArray;
|
10
|
+
import org.jruby.RubyBasicObject;
|
10
11
|
import org.jruby.RubyBignum;
|
11
12
|
import org.jruby.RubyBoolean;
|
12
13
|
import org.jruby.RubyClass;
|
@@ -15,6 +16,7 @@ import org.jruby.RubyFloat;
|
|
15
16
|
import org.jruby.RubyHash;
|
16
17
|
import org.jruby.RubyNumeric;
|
17
18
|
import org.jruby.RubyString;
|
19
|
+
import org.jruby.runtime.ClassIndex;
|
18
20
|
import org.jruby.runtime.ThreadContext;
|
19
21
|
import org.jruby.runtime.builtin.IRubyObject;
|
20
22
|
import org.jruby.util.ByteList;
|
@@ -57,6 +59,19 @@ public final class Generator {
|
|
57
59
|
return handler.generateNew(session, object);
|
58
60
|
}
|
59
61
|
|
62
|
+
// NOTE: drop this once Ruby 1.9.3 support is gone!
|
63
|
+
private static final int FIXNUM = 1;
|
64
|
+
private static final int BIGNUM = 2;
|
65
|
+
private static final int ARRAY = 3;
|
66
|
+
private static final int STRING = 4;
|
67
|
+
private static final int NIL = 5;
|
68
|
+
private static final int TRUE = 6;
|
69
|
+
private static final int FALSE = 7;
|
70
|
+
private static final int HASH = 10;
|
71
|
+
private static final int FLOAT = 11;
|
72
|
+
// hard-coded due JRuby 1.7 compatibility
|
73
|
+
// https://github.com/jruby/jruby/blob/1.7.27/core/src/main/java/org/jruby/runtime/ClassIndex.java
|
74
|
+
|
60
75
|
/**
|
61
76
|
* Returns the best serialization handler for the given object.
|
62
77
|
*/
|
@@ -65,16 +80,24 @@ public final class Generator {
|
|
65
80
|
@SuppressWarnings("unchecked")
|
66
81
|
private static <T extends IRubyObject>
|
67
82
|
Handler<? super T> getHandlerFor(Ruby runtime, T object) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
switch (((RubyBasicObject) object).getNativeTypeIndex()) {
|
84
|
+
// can not use getNativeClassIndex due 1.7 compatibility
|
85
|
+
case NIL : return (Handler) NIL_HANDLER;
|
86
|
+
case TRUE : return (Handler) TRUE_HANDLER;
|
87
|
+
case FALSE : return (Handler) FALSE_HANDLER;
|
88
|
+
case FLOAT : return (Handler) FLOAT_HANDLER;
|
89
|
+
case FIXNUM : return (Handler) FIXNUM_HANDLER;
|
90
|
+
case BIGNUM : return (Handler) BIGNUM_HANDLER;
|
91
|
+
case STRING :
|
92
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getString()) break;
|
93
|
+
return (Handler) STRING_HANDLER;
|
94
|
+
case ARRAY :
|
95
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getArray()) break;
|
96
|
+
return (Handler) ARRAY_HANDLER;
|
97
|
+
case HASH :
|
98
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getHash()) break;
|
99
|
+
return (Handler) HASH_HANDLER;
|
100
|
+
}
|
78
101
|
return GENERIC_HANDLER;
|
79
102
|
}
|
80
103
|
|
@@ -54,7 +54,8 @@ public class Parser extends RubyObject {
|
|
54
54
|
private boolean symbolizeNames;
|
55
55
|
private RubyClass objectClass;
|
56
56
|
private RubyClass arrayClass;
|
57
|
-
private
|
57
|
+
private RubyClass decimalClass;
|
58
|
+
private RubyHash match_string;
|
58
59
|
|
59
60
|
private static final int DEFAULT_MAX_NESTING = 100;
|
60
61
|
|
@@ -133,6 +134,10 @@ public class Parser extends RubyObject {
|
|
133
134
|
* <dt><code>:array_class</code>
|
134
135
|
* <dd>Defaults to Array.
|
135
136
|
*
|
137
|
+
* <dt><code>:decimal_class</code>
|
138
|
+
* <dd>Specifies which class to use instead of the default (Float) when
|
139
|
+
* parsing decimal numbers. This class must accept a single string argument
|
140
|
+
* in its constructor.
|
136
141
|
* </dl>
|
137
142
|
*/
|
138
143
|
@JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
|
@@ -159,7 +164,8 @@ public class Parser extends RubyObject {
|
|
159
164
|
this.createAdditions = opts.getBool("create_additions", false);
|
160
165
|
this.objectClass = opts.getClass("object_class", runtime.getHash());
|
161
166
|
this.arrayClass = opts.getClass("array_class", runtime.getArray());
|
162
|
-
this.
|
167
|
+
this.decimalClass = opts.getClass("decimal_class", null);
|
168
|
+
this.match_string = opts.getHash("match_string");
|
163
169
|
|
164
170
|
if(symbolizeNames && createAdditions) {
|
165
171
|
throw runtime.newArgumentError(
|
@@ -307,11 +313,11 @@ public class Parser extends RubyObject {
|
|
307
313
|
}
|
308
314
|
|
309
315
|
|
310
|
-
// line
|
316
|
+
// line 339 "Parser.rl"
|
311
317
|
|
312
318
|
|
313
319
|
|
314
|
-
// line
|
320
|
+
// line 321 "Parser.java"
|
315
321
|
private static byte[] init__JSON_value_actions_0()
|
316
322
|
{
|
317
323
|
return new byte [] {
|
@@ -425,7 +431,7 @@ static final int JSON_value_error = 0;
|
|
425
431
|
static final int JSON_value_en_main = 1;
|
426
432
|
|
427
433
|
|
428
|
-
// line
|
434
|
+
// line 445 "Parser.rl"
|
429
435
|
|
430
436
|
|
431
437
|
void parseValue(ParserResult res, int p, int pe) {
|
@@ -433,14 +439,14 @@ static final int JSON_value_en_main = 1;
|
|
433
439
|
IRubyObject result = null;
|
434
440
|
|
435
441
|
|
436
|
-
// line
|
442
|
+
// line 443 "Parser.java"
|
437
443
|
{
|
438
444
|
cs = JSON_value_start;
|
439
445
|
}
|
440
446
|
|
441
|
-
// line
|
447
|
+
// line 452 "Parser.rl"
|
442
448
|
|
443
|
-
// line
|
449
|
+
// line 450 "Parser.java"
|
444
450
|
{
|
445
451
|
int _klen;
|
446
452
|
int _trans = 0;
|
@@ -466,13 +472,13 @@ case 1:
|
|
466
472
|
while ( _nacts-- > 0 ) {
|
467
473
|
switch ( _JSON_value_actions[_acts++] ) {
|
468
474
|
case 9:
|
469
|
-
// line
|
475
|
+
// line 430 "Parser.rl"
|
470
476
|
{
|
471
477
|
p--;
|
472
478
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
473
479
|
}
|
474
480
|
break;
|
475
|
-
// line
|
481
|
+
// line 482 "Parser.java"
|
476
482
|
}
|
477
483
|
}
|
478
484
|
|
@@ -535,25 +541,25 @@ case 1:
|
|
535
541
|
switch ( _JSON_value_actions[_acts++] )
|
536
542
|
{
|
537
543
|
case 0:
|
538
|
-
// line
|
544
|
+
// line 347 "Parser.rl"
|
539
545
|
{
|
540
546
|
result = getRuntime().getNil();
|
541
547
|
}
|
542
548
|
break;
|
543
549
|
case 1:
|
544
|
-
// line
|
550
|
+
// line 350 "Parser.rl"
|
545
551
|
{
|
546
552
|
result = getRuntime().getFalse();
|
547
553
|
}
|
548
554
|
break;
|
549
555
|
case 2:
|
550
|
-
// line
|
556
|
+
// line 353 "Parser.rl"
|
551
557
|
{
|
552
558
|
result = getRuntime().getTrue();
|
553
559
|
}
|
554
560
|
break;
|
555
561
|
case 3:
|
556
|
-
// line
|
562
|
+
// line 356 "Parser.rl"
|
557
563
|
{
|
558
564
|
if (parser.allowNaN) {
|
559
565
|
result = getConstant(CONST_NAN);
|
@@ -563,7 +569,7 @@ case 1:
|
|
563
569
|
}
|
564
570
|
break;
|
565
571
|
case 4:
|
566
|
-
// line
|
572
|
+
// line 363 "Parser.rl"
|
567
573
|
{
|
568
574
|
if (parser.allowNaN) {
|
569
575
|
result = getConstant(CONST_INFINITY);
|
@@ -573,7 +579,7 @@ case 1:
|
|
573
579
|
}
|
574
580
|
break;
|
575
581
|
case 5:
|
576
|
-
// line
|
582
|
+
// line 370 "Parser.rl"
|
577
583
|
{
|
578
584
|
if (pe > p + 8 &&
|
579
585
|
absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
|
@@ -602,7 +608,7 @@ case 1:
|
|
602
608
|
}
|
603
609
|
break;
|
604
610
|
case 6:
|
605
|
-
// line
|
611
|
+
// line 396 "Parser.rl"
|
606
612
|
{
|
607
613
|
parseString(res, p, pe);
|
608
614
|
if (res.result == null) {
|
@@ -615,7 +621,7 @@ case 1:
|
|
615
621
|
}
|
616
622
|
break;
|
617
623
|
case 7:
|
618
|
-
// line
|
624
|
+
// line 406 "Parser.rl"
|
619
625
|
{
|
620
626
|
currentNesting++;
|
621
627
|
parseArray(res, p, pe);
|
@@ -630,7 +636,7 @@ case 1:
|
|
630
636
|
}
|
631
637
|
break;
|
632
638
|
case 8:
|
633
|
-
// line
|
639
|
+
// line 418 "Parser.rl"
|
634
640
|
{
|
635
641
|
currentNesting++;
|
636
642
|
parseObject(res, p, pe);
|
@@ -644,7 +650,7 @@ case 1:
|
|
644
650
|
}
|
645
651
|
}
|
646
652
|
break;
|
647
|
-
// line
|
653
|
+
// line 654 "Parser.java"
|
648
654
|
}
|
649
655
|
}
|
650
656
|
}
|
@@ -664,7 +670,7 @@ case 5:
|
|
664
670
|
break; }
|
665
671
|
}
|
666
672
|
|
667
|
-
// line
|
673
|
+
// line 453 "Parser.rl"
|
668
674
|
|
669
675
|
if (cs >= JSON_value_first_final && result != null) {
|
670
676
|
res.update(result, p);
|
@@ -674,7 +680,7 @@ case 5:
|
|
674
680
|
}
|
675
681
|
|
676
682
|
|
677
|
-
// line
|
683
|
+
// line 684 "Parser.java"
|
678
684
|
private static byte[] init__JSON_integer_actions_0()
|
679
685
|
{
|
680
686
|
return new byte [] {
|
@@ -773,7 +779,7 @@ static final int JSON_integer_error = 0;
|
|
773
779
|
static final int JSON_integer_en_main = 1;
|
774
780
|
|
775
781
|
|
776
|
-
// line
|
782
|
+
// line 472 "Parser.rl"
|
777
783
|
|
778
784
|
|
779
785
|
void parseInteger(ParserResult res, int p, int pe) {
|
@@ -791,15 +797,15 @@ static final int JSON_integer_en_main = 1;
|
|
791
797
|
int cs = EVIL;
|
792
798
|
|
793
799
|
|
794
|
-
// line
|
800
|
+
// line 801 "Parser.java"
|
795
801
|
{
|
796
802
|
cs = JSON_integer_start;
|
797
803
|
}
|
798
804
|
|
799
|
-
// line
|
805
|
+
// line 489 "Parser.rl"
|
800
806
|
int memo = p;
|
801
807
|
|
802
|
-
// line
|
808
|
+
// line 809 "Parser.java"
|
803
809
|
{
|
804
810
|
int _klen;
|
805
811
|
int _trans = 0;
|
@@ -880,13 +886,13 @@ case 1:
|
|
880
886
|
switch ( _JSON_integer_actions[_acts++] )
|
881
887
|
{
|
882
888
|
case 0:
|
883
|
-
// line
|
889
|
+
// line 466 "Parser.rl"
|
884
890
|
{
|
885
891
|
p--;
|
886
892
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
887
893
|
}
|
888
894
|
break;
|
889
|
-
// line
|
895
|
+
// line 896 "Parser.java"
|
890
896
|
}
|
891
897
|
}
|
892
898
|
}
|
@@ -906,7 +912,7 @@ case 5:
|
|
906
912
|
break; }
|
907
913
|
}
|
908
914
|
|
909
|
-
// line
|
915
|
+
// line 491 "Parser.rl"
|
910
916
|
|
911
917
|
if (cs < JSON_integer_first_final) {
|
912
918
|
return -1;
|
@@ -914,13 +920,13 @@ case 5:
|
|
914
920
|
|
915
921
|
return p;
|
916
922
|
}
|
917
|
-
|
923
|
+
|
918
924
|
RubyInteger createInteger(int p, int new_p) {
|
919
925
|
Ruby runtime = getRuntime();
|
920
926
|
ByteList num = absSubSequence(p, new_p);
|
921
927
|
return bytesToInum(runtime, num);
|
922
928
|
}
|
923
|
-
|
929
|
+
|
924
930
|
RubyInteger bytesToInum(Ruby runtime, ByteList num) {
|
925
931
|
return runtime.is1_9() ?
|
926
932
|
ConvertBytes.byteListToInum19(runtime, num, 10, true) :
|
@@ -928,7 +934,7 @@ case 5:
|
|
928
934
|
}
|
929
935
|
|
930
936
|
|
931
|
-
// line
|
937
|
+
// line 938 "Parser.java"
|
932
938
|
private static byte[] init__JSON_float_actions_0()
|
933
939
|
{
|
934
940
|
return new byte [] {
|
@@ -1030,7 +1036,7 @@ static final int JSON_float_error = 0;
|
|
1030
1036
|
static final int JSON_float_en_main = 1;
|
1031
1037
|
|
1032
1038
|
|
1033
|
-
// line
|
1039
|
+
// line 526 "Parser.rl"
|
1034
1040
|
|
1035
1041
|
|
1036
1042
|
void parseFloat(ParserResult res, int p, int pe) {
|
@@ -1039,7 +1045,9 @@ static final int JSON_float_en_main = 1;
|
|
1039
1045
|
res.update(null, p);
|
1040
1046
|
return;
|
1041
1047
|
}
|
1042
|
-
|
1048
|
+
IRubyObject number = parser.decimalClass == null ?
|
1049
|
+
createFloat(p, new_p) : createCustomDecimal(p, new_p);
|
1050
|
+
|
1043
1051
|
res.update(number, new_p + 1);
|
1044
1052
|
return;
|
1045
1053
|
}
|
@@ -1048,15 +1056,15 @@ static final int JSON_float_en_main = 1;
|
|
1048
1056
|
int cs = EVIL;
|
1049
1057
|
|
1050
1058
|
|
1051
|
-
// line
|
1059
|
+
// line 1060 "Parser.java"
|
1052
1060
|
{
|
1053
1061
|
cs = JSON_float_start;
|
1054
1062
|
}
|
1055
1063
|
|
1056
|
-
// line
|
1064
|
+
// line 545 "Parser.rl"
|
1057
1065
|
int memo = p;
|
1058
1066
|
|
1059
|
-
// line
|
1067
|
+
// line 1068 "Parser.java"
|
1060
1068
|
{
|
1061
1069
|
int _klen;
|
1062
1070
|
int _trans = 0;
|
@@ -1137,13 +1145,13 @@ case 1:
|
|
1137
1145
|
switch ( _JSON_float_actions[_acts++] )
|
1138
1146
|
{
|
1139
1147
|
case 0:
|
1140
|
-
// line
|
1148
|
+
// line 517 "Parser.rl"
|
1141
1149
|
{
|
1142
1150
|
p--;
|
1143
1151
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
1144
1152
|
}
|
1145
1153
|
break;
|
1146
|
-
// line
|
1154
|
+
// line 1155 "Parser.java"
|
1147
1155
|
}
|
1148
1156
|
}
|
1149
1157
|
}
|
@@ -1163,23 +1171,30 @@ case 5:
|
|
1163
1171
|
break; }
|
1164
1172
|
}
|
1165
1173
|
|
1166
|
-
// line
|
1174
|
+
// line 547 "Parser.rl"
|
1167
1175
|
|
1168
1176
|
if (cs < JSON_float_first_final) {
|
1169
1177
|
return -1;
|
1170
1178
|
}
|
1171
|
-
|
1179
|
+
|
1172
1180
|
return p;
|
1173
1181
|
}
|
1174
|
-
|
1182
|
+
|
1175
1183
|
RubyFloat createFloat(int p, int new_p) {
|
1176
1184
|
Ruby runtime = getRuntime();
|
1177
1185
|
ByteList num = absSubSequence(p, new_p);
|
1178
1186
|
return RubyFloat.newFloat(runtime, dc.parse(num, true, runtime.is1_9()));
|
1179
1187
|
}
|
1180
1188
|
|
1189
|
+
IRubyObject createCustomDecimal(int p, int new_p) {
|
1190
|
+
Ruby runtime = getRuntime();
|
1191
|
+
ByteList num = absSubSequence(p, new_p);
|
1192
|
+
IRubyObject numString = runtime.newString(num.toString());
|
1193
|
+
return parser.decimalClass.callMethod(context, "new", numString);
|
1194
|
+
}
|
1195
|
+
|
1181
1196
|
|
1182
|
-
// line
|
1197
|
+
// line 1198 "Parser.java"
|
1183
1198
|
private static byte[] init__JSON_string_actions_0()
|
1184
1199
|
{
|
1185
1200
|
return new byte [] {
|
@@ -1281,7 +1296,7 @@ static final int JSON_string_error = 0;
|
|
1281
1296
|
static final int JSON_string_en_main = 1;
|
1282
1297
|
|
1283
1298
|
|
1284
|
-
// line
|
1299
|
+
// line 599 "Parser.rl"
|
1285
1300
|
|
1286
1301
|
|
1287
1302
|
void parseString(ParserResult res, int p, int pe) {
|
@@ -1289,15 +1304,15 @@ static final int JSON_string_en_main = 1;
|
|
1289
1304
|
IRubyObject result = null;
|
1290
1305
|
|
1291
1306
|
|
1292
|
-
// line
|
1307
|
+
// line 1308 "Parser.java"
|
1293
1308
|
{
|
1294
1309
|
cs = JSON_string_start;
|
1295
1310
|
}
|
1296
1311
|
|
1297
|
-
// line
|
1312
|
+
// line 606 "Parser.rl"
|
1298
1313
|
int memo = p;
|
1299
1314
|
|
1300
|
-
// line
|
1315
|
+
// line 1316 "Parser.java"
|
1301
1316
|
{
|
1302
1317
|
int _klen;
|
1303
1318
|
int _trans = 0;
|
@@ -1378,7 +1393,7 @@ case 1:
|
|
1378
1393
|
switch ( _JSON_string_actions[_acts++] )
|
1379
1394
|
{
|
1380
1395
|
case 0:
|
1381
|
-
// line
|
1396
|
+
// line 574 "Parser.rl"
|
1382
1397
|
{
|
1383
1398
|
int offset = byteList.begin();
|
1384
1399
|
ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
|
@@ -1393,13 +1408,13 @@ case 1:
|
|
1393
1408
|
}
|
1394
1409
|
break;
|
1395
1410
|
case 1:
|
1396
|
-
// line
|
1411
|
+
// line 587 "Parser.rl"
|
1397
1412
|
{
|
1398
1413
|
p--;
|
1399
1414
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
1400
1415
|
}
|
1401
1416
|
break;
|
1402
|
-
// line
|
1417
|
+
// line 1418 "Parser.java"
|
1403
1418
|
}
|
1404
1419
|
}
|
1405
1420
|
}
|
@@ -1419,10 +1434,10 @@ case 5:
|
|
1419
1434
|
break; }
|
1420
1435
|
}
|
1421
1436
|
|
1422
|
-
// line
|
1437
|
+
// line 608 "Parser.rl"
|
1423
1438
|
|
1424
1439
|
if (parser.createAdditions) {
|
1425
|
-
RubyHash matchString = parser.
|
1440
|
+
RubyHash matchString = parser.match_string;
|
1426
1441
|
if (matchString != null) {
|
1427
1442
|
final IRubyObject[] memoArray = { result, null };
|
1428
1443
|
try {
|
@@ -1446,7 +1461,7 @@ case 5:
|
|
1446
1461
|
}
|
1447
1462
|
}
|
1448
1463
|
|
1449
|
-
if (cs >= JSON_string_first_final && result != null) {
|
1464
|
+
if (cs >= JSON_string_first_final && result != null) {
|
1450
1465
|
if (result instanceof RubyString) {
|
1451
1466
|
((RubyString)result).force_encoding(context, info.utf8.get());
|
1452
1467
|
}
|
@@ -1457,7 +1472,7 @@ case 5:
|
|
1457
1472
|
}
|
1458
1473
|
|
1459
1474
|
|
1460
|
-
// line
|
1475
|
+
// line 1476 "Parser.java"
|
1461
1476
|
private static byte[] init__JSON_array_actions_0()
|
1462
1477
|
{
|
1463
1478
|
return new byte [] {
|
@@ -1570,7 +1585,7 @@ static final int JSON_array_error = 0;
|
|
1570
1585
|
static final int JSON_array_en_main = 1;
|
1571
1586
|
|
1572
1587
|
|
1573
|
-
// line
|
1588
|
+
// line 681 "Parser.rl"
|
1574
1589
|
|
1575
1590
|
|
1576
1591
|
void parseArray(ParserResult res, int p, int pe) {
|
@@ -1590,14 +1605,14 @@ static final int JSON_array_en_main = 1;
|
|
1590
1605
|
}
|
1591
1606
|
|
1592
1607
|
|
1593
|
-
// line
|
1608
|
+
// line 1609 "Parser.java"
|
1594
1609
|
{
|
1595
1610
|
cs = JSON_array_start;
|
1596
1611
|
}
|
1597
1612
|
|
1598
|
-
// line
|
1613
|
+
// line 700 "Parser.rl"
|
1599
1614
|
|
1600
|
-
// line
|
1615
|
+
// line 1616 "Parser.java"
|
1601
1616
|
{
|
1602
1617
|
int _klen;
|
1603
1618
|
int _trans = 0;
|
@@ -1678,7 +1693,7 @@ case 1:
|
|
1678
1693
|
switch ( _JSON_array_actions[_acts++] )
|
1679
1694
|
{
|
1680
1695
|
case 0:
|
1681
|
-
// line
|
1696
|
+
// line 650 "Parser.rl"
|
1682
1697
|
{
|
1683
1698
|
parseValue(res, p, pe);
|
1684
1699
|
if (res.result == null) {
|
@@ -1695,13 +1710,13 @@ case 1:
|
|
1695
1710
|
}
|
1696
1711
|
break;
|
1697
1712
|
case 1:
|
1698
|
-
// line
|
1713
|
+
// line 665 "Parser.rl"
|
1699
1714
|
{
|
1700
1715
|
p--;
|
1701
1716
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
1702
1717
|
}
|
1703
1718
|
break;
|
1704
|
-
// line
|
1719
|
+
// line 1720 "Parser.java"
|
1705
1720
|
}
|
1706
1721
|
}
|
1707
1722
|
}
|
@@ -1721,7 +1736,7 @@ case 5:
|
|
1721
1736
|
break; }
|
1722
1737
|
}
|
1723
1738
|
|
1724
|
-
// line
|
1739
|
+
// line 701 "Parser.rl"
|
1725
1740
|
|
1726
1741
|
if (cs >= JSON_array_first_final) {
|
1727
1742
|
res.update(result, p + 1);
|
@@ -1731,7 +1746,7 @@ case 5:
|
|
1731
1746
|
}
|
1732
1747
|
|
1733
1748
|
|
1734
|
-
// line
|
1749
|
+
// line 1750 "Parser.java"
|
1735
1750
|
private static byte[] init__JSON_object_actions_0()
|
1736
1751
|
{
|
1737
1752
|
return new byte [] {
|
@@ -1854,7 +1869,7 @@ static final int JSON_object_error = 0;
|
|
1854
1869
|
static final int JSON_object_en_main = 1;
|
1855
1870
|
|
1856
1871
|
|
1857
|
-
// line
|
1872
|
+
// line 760 "Parser.rl"
|
1858
1873
|
|
1859
1874
|
|
1860
1875
|
void parseObject(ParserResult res, int p, int pe) {
|
@@ -1879,14 +1894,14 @@ static final int JSON_object_en_main = 1;
|
|
1879
1894
|
}
|
1880
1895
|
|
1881
1896
|
|
1882
|
-
// line
|
1897
|
+
// line 1898 "Parser.java"
|
1883
1898
|
{
|
1884
1899
|
cs = JSON_object_start;
|
1885
1900
|
}
|
1886
1901
|
|
1887
|
-
// line
|
1902
|
+
// line 784 "Parser.rl"
|
1888
1903
|
|
1889
|
-
// line
|
1904
|
+
// line 1905 "Parser.java"
|
1890
1905
|
{
|
1891
1906
|
int _klen;
|
1892
1907
|
int _trans = 0;
|
@@ -1967,7 +1982,7 @@ case 1:
|
|
1967
1982
|
switch ( _JSON_object_actions[_acts++] )
|
1968
1983
|
{
|
1969
1984
|
case 0:
|
1970
|
-
// line
|
1985
|
+
// line 715 "Parser.rl"
|
1971
1986
|
{
|
1972
1987
|
parseValue(res, p, pe);
|
1973
1988
|
if (res.result == null) {
|
@@ -1984,7 +1999,7 @@ case 1:
|
|
1984
1999
|
}
|
1985
2000
|
break;
|
1986
2001
|
case 1:
|
1987
|
-
// line
|
2002
|
+
// line 730 "Parser.rl"
|
1988
2003
|
{
|
1989
2004
|
parseString(res, p, pe);
|
1990
2005
|
if (res.result == null) {
|
@@ -2004,13 +2019,13 @@ case 1:
|
|
2004
2019
|
}
|
2005
2020
|
break;
|
2006
2021
|
case 2:
|
2007
|
-
// line
|
2022
|
+
// line 748 "Parser.rl"
|
2008
2023
|
{
|
2009
2024
|
p--;
|
2010
2025
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
2011
2026
|
}
|
2012
2027
|
break;
|
2013
|
-
// line
|
2028
|
+
// line 2029 "Parser.java"
|
2014
2029
|
}
|
2015
2030
|
}
|
2016
2031
|
}
|
@@ -2030,7 +2045,7 @@ case 5:
|
|
2030
2045
|
break; }
|
2031
2046
|
}
|
2032
2047
|
|
2033
|
-
// line
|
2048
|
+
// line 785 "Parser.rl"
|
2034
2049
|
|
2035
2050
|
if (cs < JSON_object_first_final) {
|
2036
2051
|
res.update(null, p + 1);
|
@@ -2063,7 +2078,7 @@ case 5:
|
|
2063
2078
|
}
|
2064
2079
|
|
2065
2080
|
|
2066
|
-
// line
|
2081
|
+
// line 2082 "Parser.java"
|
2067
2082
|
private static byte[] init__JSON_actions_0()
|
2068
2083
|
{
|
2069
2084
|
return new byte [] {
|
@@ -2166,7 +2181,7 @@ static final int JSON_error = 0;
|
|
2166
2181
|
static final int JSON_en_main = 1;
|
2167
2182
|
|
2168
2183
|
|
2169
|
-
// line
|
2184
|
+
// line 836 "Parser.rl"
|
2170
2185
|
|
2171
2186
|
|
2172
2187
|
public IRubyObject parseImplemetation() {
|
@@ -2176,16 +2191,16 @@ static final int JSON_en_main = 1;
|
|
2176
2191
|
ParserResult res = new ParserResult();
|
2177
2192
|
|
2178
2193
|
|
2179
|
-
// line
|
2194
|
+
// line 2195 "Parser.java"
|
2180
2195
|
{
|
2181
2196
|
cs = JSON_start;
|
2182
2197
|
}
|
2183
2198
|
|
2184
|
-
// line
|
2199
|
+
// line 845 "Parser.rl"
|
2185
2200
|
p = byteList.begin();
|
2186
2201
|
pe = p + byteList.length();
|
2187
2202
|
|
2188
|
-
// line
|
2203
|
+
// line 2204 "Parser.java"
|
2189
2204
|
{
|
2190
2205
|
int _klen;
|
2191
2206
|
int _trans = 0;
|
@@ -2266,7 +2281,7 @@ case 1:
|
|
2266
2281
|
switch ( _JSON_actions[_acts++] )
|
2267
2282
|
{
|
2268
2283
|
case 0:
|
2269
|
-
// line
|
2284
|
+
// line 822 "Parser.rl"
|
2270
2285
|
{
|
2271
2286
|
parseValue(res, p, pe);
|
2272
2287
|
if (res.result == null) {
|
@@ -2278,7 +2293,7 @@ case 1:
|
|
2278
2293
|
}
|
2279
2294
|
}
|
2280
2295
|
break;
|
2281
|
-
// line
|
2296
|
+
// line 2297 "Parser.java"
|
2282
2297
|
}
|
2283
2298
|
}
|
2284
2299
|
}
|
@@ -2298,7 +2313,7 @@ case 5:
|
|
2298
2313
|
break; }
|
2299
2314
|
}
|
2300
2315
|
|
2301
|
-
// line
|
2316
|
+
// line 848 "Parser.rl"
|
2302
2317
|
|
2303
2318
|
if (cs >= JSON_first_final && p == pe) {
|
2304
2319
|
return result;
|