json 2.0.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +11 -4
- data/CHANGES.md +44 -0
- data/Gemfile +1 -3
- data/README.md +54 -21
- data/Rakefile +19 -93
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +172 -46
- data/ext/json/ext/generator/generator.h +0 -1
- data/ext/json/ext/parser/parser.c +138 -85
- data/ext/json/ext/parser/parser.h +1 -0
- data/ext/json/ext/parser/parser.rl +62 -9
- 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 +4 -5
- data/json.gemspec +0 -0
- data/json_pure.gemspec +9 -14
- data/lib/json.rb +378 -29
- 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 +326 -91
- data/lib/json/pure/generator.rb +3 -2
- data/lib/json/pure/parser.rb +15 -3
- 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 -0
- data/tests/json_fixtures_test.rb +6 -1
- data/tests/json_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +18 -12
- data/tests/test_helper.rb +0 -4
- metadata +24 -16
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* This file is automatically generated from parser.rl by using ragel */
|
|
2
2
|
#line 1 "parser.rl"
|
|
3
3
|
#include "../fbuffer/fbuffer.h"
|
|
4
4
|
#include "parser.h"
|
|
@@ -27,7 +27,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
|
27
27
|
|
|
28
28
|
/* unicode */
|
|
29
29
|
|
|
30
|
-
static const char digit_values[256] = {
|
|
30
|
+
static const signed char digit_values[256] = {
|
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
32
32
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
33
33
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
|
@@ -46,7 +46,7 @@ static const char digit_values[256] = {
|
|
|
46
46
|
|
|
47
47
|
static UTF32 unescape_unicode(const unsigned char *p)
|
|
48
48
|
{
|
|
49
|
-
char b;
|
|
49
|
+
signed char b;
|
|
50
50
|
UTF32 result = 0;
|
|
51
51
|
b = digit_values[p[0]];
|
|
52
52
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
@@ -91,18 +91,20 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
|
91
91
|
|
|
92
92
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
|
93
93
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
|
94
|
+
static VALUE cBigDecimal = Qundef;
|
|
94
95
|
|
|
95
96
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
|
96
97
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
|
97
|
-
i_object_class, i_array_class,
|
|
98
|
-
i_match_string, i_aset, i_aref,
|
|
98
|
+
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
|
99
|
+
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
|
100
|
+
i_leftshift, i_new, i_BigDecimal;
|
|
99
101
|
|
|
100
102
|
|
|
101
|
-
#line
|
|
103
|
+
#line 126 "parser.rl"
|
|
102
104
|
|
|
103
105
|
|
|
104
106
|
|
|
105
|
-
#line
|
|
107
|
+
#line 108 "parser.c"
|
|
106
108
|
enum {JSON_object_start = 1};
|
|
107
109
|
enum {JSON_object_first_final = 27};
|
|
108
110
|
enum {JSON_object_error = 0};
|
|
@@ -110,7 +112,7 @@ enum {JSON_object_error = 0};
|
|
|
110
112
|
enum {JSON_object_en_main = 1};
|
|
111
113
|
|
|
112
114
|
|
|
113
|
-
#line
|
|
115
|
+
#line 168 "parser.rl"
|
|
114
116
|
|
|
115
117
|
|
|
116
118
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -126,14 +128,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
|
126
128
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
|
127
129
|
|
|
128
130
|
|
|
129
|
-
#line
|
|
131
|
+
#line 132 "parser.c"
|
|
130
132
|
{
|
|
131
133
|
cs = JSON_object_start;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
#line
|
|
136
|
+
#line 183 "parser.rl"
|
|
135
137
|
|
|
136
|
-
#line
|
|
138
|
+
#line 139 "parser.c"
|
|
137
139
|
{
|
|
138
140
|
if ( p == pe )
|
|
139
141
|
goto _test_eof;
|
|
@@ -161,7 +163,7 @@ case 2:
|
|
|
161
163
|
goto st2;
|
|
162
164
|
goto st0;
|
|
163
165
|
tr2:
|
|
164
|
-
#line
|
|
166
|
+
#line 150 "parser.rl"
|
|
165
167
|
{
|
|
166
168
|
char *np;
|
|
167
169
|
json->parsing_name = 1;
|
|
@@ -174,7 +176,7 @@ st3:
|
|
|
174
176
|
if ( ++p == pe )
|
|
175
177
|
goto _test_eof3;
|
|
176
178
|
case 3:
|
|
177
|
-
#line
|
|
179
|
+
#line 180 "parser.c"
|
|
178
180
|
switch( (*p) ) {
|
|
179
181
|
case 13: goto st3;
|
|
180
182
|
case 32: goto st3;
|
|
@@ -241,7 +243,7 @@ case 8:
|
|
|
241
243
|
goto st8;
|
|
242
244
|
goto st0;
|
|
243
245
|
tr11:
|
|
244
|
-
#line
|
|
246
|
+
#line 134 "parser.rl"
|
|
245
247
|
{
|
|
246
248
|
VALUE v = Qnil;
|
|
247
249
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
|
@@ -249,6 +251,7 @@ tr11:
|
|
|
249
251
|
p--; {p++; cs = 9; goto _out;}
|
|
250
252
|
} else {
|
|
251
253
|
if (NIL_P(json->object_class)) {
|
|
254
|
+
OBJ_FREEZE(last_name);
|
|
252
255
|
rb_hash_aset(*result, last_name, v);
|
|
253
256
|
} else {
|
|
254
257
|
rb_funcall(*result, i_aset, 2, last_name, v);
|
|
@@ -261,7 +264,7 @@ st9:
|
|
|
261
264
|
if ( ++p == pe )
|
|
262
265
|
goto _test_eof9;
|
|
263
266
|
case 9:
|
|
264
|
-
#line
|
|
267
|
+
#line 268 "parser.c"
|
|
265
268
|
switch( (*p) ) {
|
|
266
269
|
case 13: goto st9;
|
|
267
270
|
case 32: goto st9;
|
|
@@ -350,14 +353,14 @@ case 18:
|
|
|
350
353
|
goto st9;
|
|
351
354
|
goto st18;
|
|
352
355
|
tr4:
|
|
353
|
-
#line
|
|
356
|
+
#line 158 "parser.rl"
|
|
354
357
|
{ p--; {p++; cs = 27; goto _out;} }
|
|
355
358
|
goto st27;
|
|
356
359
|
st27:
|
|
357
360
|
if ( ++p == pe )
|
|
358
361
|
goto _test_eof27;
|
|
359
362
|
case 27:
|
|
360
|
-
#line
|
|
363
|
+
#line 364 "parser.c"
|
|
361
364
|
goto st0;
|
|
362
365
|
st19:
|
|
363
366
|
if ( ++p == pe )
|
|
@@ -455,7 +458,7 @@ case 26:
|
|
|
455
458
|
_out: {}
|
|
456
459
|
}
|
|
457
460
|
|
|
458
|
-
#line
|
|
461
|
+
#line 184 "parser.rl"
|
|
459
462
|
|
|
460
463
|
if (cs >= JSON_object_first_final) {
|
|
461
464
|
if (json->create_additions) {
|
|
@@ -480,7 +483,7 @@ case 26:
|
|
|
480
483
|
|
|
481
484
|
|
|
482
485
|
|
|
483
|
-
#line
|
|
486
|
+
#line 487 "parser.c"
|
|
484
487
|
enum {JSON_value_start = 1};
|
|
485
488
|
enum {JSON_value_first_final = 29};
|
|
486
489
|
enum {JSON_value_error = 0};
|
|
@@ -488,7 +491,7 @@ enum {JSON_value_error = 0};
|
|
|
488
491
|
enum {JSON_value_en_main = 1};
|
|
489
492
|
|
|
490
493
|
|
|
491
|
-
#line
|
|
494
|
+
#line 284 "parser.rl"
|
|
492
495
|
|
|
493
496
|
|
|
494
497
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -496,14 +499,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
|
496
499
|
int cs = EVIL;
|
|
497
500
|
|
|
498
501
|
|
|
499
|
-
#line
|
|
502
|
+
#line 503 "parser.c"
|
|
500
503
|
{
|
|
501
504
|
cs = JSON_value_start;
|
|
502
505
|
}
|
|
503
506
|
|
|
504
|
-
#line
|
|
507
|
+
#line 291 "parser.rl"
|
|
505
508
|
|
|
506
|
-
#line
|
|
509
|
+
#line 510 "parser.c"
|
|
507
510
|
{
|
|
508
511
|
if ( p == pe )
|
|
509
512
|
goto _test_eof;
|
|
@@ -537,14 +540,14 @@ st0:
|
|
|
537
540
|
cs = 0;
|
|
538
541
|
goto _out;
|
|
539
542
|
tr2:
|
|
540
|
-
#line
|
|
543
|
+
#line 236 "parser.rl"
|
|
541
544
|
{
|
|
542
545
|
char *np = JSON_parse_string(json, p, pe, result);
|
|
543
546
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
|
544
547
|
}
|
|
545
548
|
goto st29;
|
|
546
549
|
tr3:
|
|
547
|
-
#line
|
|
550
|
+
#line 241 "parser.rl"
|
|
548
551
|
{
|
|
549
552
|
char *np;
|
|
550
553
|
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
|
@@ -564,7 +567,7 @@ tr3:
|
|
|
564
567
|
}
|
|
565
568
|
goto st29;
|
|
566
569
|
tr7:
|
|
567
|
-
#line
|
|
570
|
+
#line 259 "parser.rl"
|
|
568
571
|
{
|
|
569
572
|
char *np;
|
|
570
573
|
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
|
@@ -572,7 +575,7 @@ tr7:
|
|
|
572
575
|
}
|
|
573
576
|
goto st29;
|
|
574
577
|
tr11:
|
|
575
|
-
#line
|
|
578
|
+
#line 265 "parser.rl"
|
|
576
579
|
{
|
|
577
580
|
char *np;
|
|
578
581
|
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
|
@@ -580,7 +583,7 @@ tr11:
|
|
|
580
583
|
}
|
|
581
584
|
goto st29;
|
|
582
585
|
tr25:
|
|
583
|
-
#line
|
|
586
|
+
#line 229 "parser.rl"
|
|
584
587
|
{
|
|
585
588
|
if (json->allow_nan) {
|
|
586
589
|
*result = CInfinity;
|
|
@@ -590,7 +593,7 @@ tr25:
|
|
|
590
593
|
}
|
|
591
594
|
goto st29;
|
|
592
595
|
tr27:
|
|
593
|
-
#line
|
|
596
|
+
#line 222 "parser.rl"
|
|
594
597
|
{
|
|
595
598
|
if (json->allow_nan) {
|
|
596
599
|
*result = CNaN;
|
|
@@ -600,19 +603,19 @@ tr27:
|
|
|
600
603
|
}
|
|
601
604
|
goto st29;
|
|
602
605
|
tr31:
|
|
603
|
-
#line
|
|
606
|
+
#line 216 "parser.rl"
|
|
604
607
|
{
|
|
605
608
|
*result = Qfalse;
|
|
606
609
|
}
|
|
607
610
|
goto st29;
|
|
608
611
|
tr34:
|
|
609
|
-
#line
|
|
612
|
+
#line 213 "parser.rl"
|
|
610
613
|
{
|
|
611
614
|
*result = Qnil;
|
|
612
615
|
}
|
|
613
616
|
goto st29;
|
|
614
617
|
tr37:
|
|
615
|
-
#line
|
|
618
|
+
#line 219 "parser.rl"
|
|
616
619
|
{
|
|
617
620
|
*result = Qtrue;
|
|
618
621
|
}
|
|
@@ -621,9 +624,9 @@ st29:
|
|
|
621
624
|
if ( ++p == pe )
|
|
622
625
|
goto _test_eof29;
|
|
623
626
|
case 29:
|
|
624
|
-
#line
|
|
627
|
+
#line 271 "parser.rl"
|
|
625
628
|
{ p--; {p++; cs = 29; goto _out;} }
|
|
626
|
-
#line
|
|
629
|
+
#line 630 "parser.c"
|
|
627
630
|
switch( (*p) ) {
|
|
628
631
|
case 13: goto st29;
|
|
629
632
|
case 32: goto st29;
|
|
@@ -864,7 +867,7 @@ case 28:
|
|
|
864
867
|
_out: {}
|
|
865
868
|
}
|
|
866
869
|
|
|
867
|
-
#line
|
|
870
|
+
#line 292 "parser.rl"
|
|
868
871
|
|
|
869
872
|
if (cs >= JSON_value_first_final) {
|
|
870
873
|
return p;
|
|
@@ -874,7 +877,7 @@ case 28:
|
|
|
874
877
|
}
|
|
875
878
|
|
|
876
879
|
|
|
877
|
-
#line
|
|
880
|
+
#line 881 "parser.c"
|
|
878
881
|
enum {JSON_integer_start = 1};
|
|
879
882
|
enum {JSON_integer_first_final = 3};
|
|
880
883
|
enum {JSON_integer_error = 0};
|
|
@@ -882,7 +885,7 @@ enum {JSON_integer_error = 0};
|
|
|
882
885
|
enum {JSON_integer_en_main = 1};
|
|
883
886
|
|
|
884
887
|
|
|
885
|
-
#line
|
|
888
|
+
#line 308 "parser.rl"
|
|
886
889
|
|
|
887
890
|
|
|
888
891
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
@@ -890,15 +893,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
|
890
893
|
int cs = EVIL;
|
|
891
894
|
|
|
892
895
|
|
|
893
|
-
#line
|
|
896
|
+
#line 897 "parser.c"
|
|
894
897
|
{
|
|
895
898
|
cs = JSON_integer_start;
|
|
896
899
|
}
|
|
897
900
|
|
|
898
|
-
#line
|
|
901
|
+
#line 315 "parser.rl"
|
|
899
902
|
json->memo = p;
|
|
900
903
|
|
|
901
|
-
#line
|
|
904
|
+
#line 905 "parser.c"
|
|
902
905
|
{
|
|
903
906
|
if ( p == pe )
|
|
904
907
|
goto _test_eof;
|
|
@@ -932,14 +935,14 @@ case 3:
|
|
|
932
935
|
goto st0;
|
|
933
936
|
goto tr4;
|
|
934
937
|
tr4:
|
|
935
|
-
#line
|
|
938
|
+
#line 305 "parser.rl"
|
|
936
939
|
{ p--; {p++; cs = 4; goto _out;} }
|
|
937
940
|
goto st4;
|
|
938
941
|
st4:
|
|
939
942
|
if ( ++p == pe )
|
|
940
943
|
goto _test_eof4;
|
|
941
944
|
case 4:
|
|
942
|
-
#line
|
|
945
|
+
#line 946 "parser.c"
|
|
943
946
|
goto st0;
|
|
944
947
|
st5:
|
|
945
948
|
if ( ++p == pe )
|
|
@@ -958,7 +961,7 @@ case 5:
|
|
|
958
961
|
_out: {}
|
|
959
962
|
}
|
|
960
963
|
|
|
961
|
-
#line
|
|
964
|
+
#line 317 "parser.rl"
|
|
962
965
|
|
|
963
966
|
if (cs >= JSON_integer_first_final) {
|
|
964
967
|
long len = p - json->memo;
|
|
@@ -973,7 +976,7 @@ case 5:
|
|
|
973
976
|
}
|
|
974
977
|
|
|
975
978
|
|
|
976
|
-
#line
|
|
979
|
+
#line 980 "parser.c"
|
|
977
980
|
enum {JSON_float_start = 1};
|
|
978
981
|
enum {JSON_float_first_final = 8};
|
|
979
982
|
enum {JSON_float_error = 0};
|
|
@@ -981,23 +984,36 @@ enum {JSON_float_error = 0};
|
|
|
981
984
|
enum {JSON_float_en_main = 1};
|
|
982
985
|
|
|
983
986
|
|
|
984
|
-
#line
|
|
987
|
+
#line 342 "parser.rl"
|
|
985
988
|
|
|
986
989
|
|
|
990
|
+
static int is_bigdecimal_class(VALUE obj)
|
|
991
|
+
{
|
|
992
|
+
if (cBigDecimal == Qundef) {
|
|
993
|
+
if (rb_const_defined(rb_cObject, i_BigDecimal)) {
|
|
994
|
+
cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
return 0;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return obj == cBigDecimal;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
987
1003
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
988
1004
|
{
|
|
989
1005
|
int cs = EVIL;
|
|
990
1006
|
|
|
991
1007
|
|
|
992
|
-
#line
|
|
1008
|
+
#line 1009 "parser.c"
|
|
993
1009
|
{
|
|
994
1010
|
cs = JSON_float_start;
|
|
995
1011
|
}
|
|
996
1012
|
|
|
997
|
-
#line
|
|
1013
|
+
#line 362 "parser.rl"
|
|
998
1014
|
json->memo = p;
|
|
999
1015
|
|
|
1000
|
-
#line
|
|
1016
|
+
#line 1017 "parser.c"
|
|
1001
1017
|
{
|
|
1002
1018
|
if ( p == pe )
|
|
1003
1019
|
goto _test_eof;
|
|
@@ -1055,14 +1071,14 @@ case 8:
|
|
|
1055
1071
|
goto st0;
|
|
1056
1072
|
goto tr9;
|
|
1057
1073
|
tr9:
|
|
1058
|
-
#line
|
|
1074
|
+
#line 336 "parser.rl"
|
|
1059
1075
|
{ p--; {p++; cs = 9; goto _out;} }
|
|
1060
1076
|
goto st9;
|
|
1061
1077
|
st9:
|
|
1062
1078
|
if ( ++p == pe )
|
|
1063
1079
|
goto _test_eof9;
|
|
1064
1080
|
case 9:
|
|
1065
|
-
#line
|
|
1081
|
+
#line 1082 "parser.c"
|
|
1066
1082
|
goto st0;
|
|
1067
1083
|
st5:
|
|
1068
1084
|
if ( ++p == pe )
|
|
@@ -1123,14 +1139,24 @@ case 7:
|
|
|
1123
1139
|
_out: {}
|
|
1124
1140
|
}
|
|
1125
1141
|
|
|
1126
|
-
#line
|
|
1142
|
+
#line 364 "parser.rl"
|
|
1127
1143
|
|
|
1128
1144
|
if (cs >= JSON_float_first_final) {
|
|
1129
1145
|
long len = p - json->memo;
|
|
1130
1146
|
fbuffer_clear(json->fbuffer);
|
|
1131
1147
|
fbuffer_append(json->fbuffer, json->memo, len);
|
|
1132
1148
|
fbuffer_append_char(json->fbuffer, '\0');
|
|
1133
|
-
|
|
1149
|
+
if (NIL_P(json->decimal_class)) {
|
|
1150
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
|
1151
|
+
} else {
|
|
1152
|
+
VALUE text;
|
|
1153
|
+
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
|
1154
|
+
if (is_bigdecimal_class(json->decimal_class)) {
|
|
1155
|
+
*result = rb_funcall(Qnil, i_BigDecimal, 1, text);
|
|
1156
|
+
} else {
|
|
1157
|
+
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1134
1160
|
return p + 1;
|
|
1135
1161
|
} else {
|
|
1136
1162
|
return NULL;
|
|
@@ -1139,7 +1165,7 @@ case 7:
|
|
|
1139
1165
|
|
|
1140
1166
|
|
|
1141
1167
|
|
|
1142
|
-
#line
|
|
1168
|
+
#line 1169 "parser.c"
|
|
1143
1169
|
enum {JSON_array_start = 1};
|
|
1144
1170
|
enum {JSON_array_first_final = 17};
|
|
1145
1171
|
enum {JSON_array_error = 0};
|
|
@@ -1147,7 +1173,7 @@ enum {JSON_array_error = 0};
|
|
|
1147
1173
|
enum {JSON_array_en_main = 1};
|
|
1148
1174
|
|
|
1149
1175
|
|
|
1150
|
-
#line
|
|
1176
|
+
#line 417 "parser.rl"
|
|
1151
1177
|
|
|
1152
1178
|
|
|
1153
1179
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -1161,14 +1187,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
|
1161
1187
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
|
1162
1188
|
|
|
1163
1189
|
|
|
1164
|
-
#line
|
|
1190
|
+
#line 1191 "parser.c"
|
|
1165
1191
|
{
|
|
1166
1192
|
cs = JSON_array_start;
|
|
1167
1193
|
}
|
|
1168
1194
|
|
|
1169
|
-
#line
|
|
1195
|
+
#line 430 "parser.rl"
|
|
1170
1196
|
|
|
1171
|
-
#line
|
|
1197
|
+
#line 1198 "parser.c"
|
|
1172
1198
|
{
|
|
1173
1199
|
if ( p == pe )
|
|
1174
1200
|
goto _test_eof;
|
|
@@ -1207,7 +1233,7 @@ case 2:
|
|
|
1207
1233
|
goto st2;
|
|
1208
1234
|
goto st0;
|
|
1209
1235
|
tr2:
|
|
1210
|
-
#line
|
|
1236
|
+
#line 394 "parser.rl"
|
|
1211
1237
|
{
|
|
1212
1238
|
VALUE v = Qnil;
|
|
1213
1239
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
|
@@ -1227,7 +1253,7 @@ st3:
|
|
|
1227
1253
|
if ( ++p == pe )
|
|
1228
1254
|
goto _test_eof3;
|
|
1229
1255
|
case 3:
|
|
1230
|
-
#line
|
|
1256
|
+
#line 1257 "parser.c"
|
|
1231
1257
|
switch( (*p) ) {
|
|
1232
1258
|
case 13: goto st3;
|
|
1233
1259
|
case 32: goto st3;
|
|
@@ -1327,14 +1353,14 @@ case 12:
|
|
|
1327
1353
|
goto st3;
|
|
1328
1354
|
goto st12;
|
|
1329
1355
|
tr4:
|
|
1330
|
-
#line
|
|
1356
|
+
#line 409 "parser.rl"
|
|
1331
1357
|
{ p--; {p++; cs = 17; goto _out;} }
|
|
1332
1358
|
goto st17;
|
|
1333
1359
|
st17:
|
|
1334
1360
|
if ( ++p == pe )
|
|
1335
1361
|
goto _test_eof17;
|
|
1336
1362
|
case 17:
|
|
1337
|
-
#line
|
|
1363
|
+
#line 1364 "parser.c"
|
|
1338
1364
|
goto st0;
|
|
1339
1365
|
st13:
|
|
1340
1366
|
if ( ++p == pe )
|
|
@@ -1390,7 +1416,7 @@ case 16:
|
|
|
1390
1416
|
_out: {}
|
|
1391
1417
|
}
|
|
1392
1418
|
|
|
1393
|
-
#line
|
|
1419
|
+
#line 431 "parser.rl"
|
|
1394
1420
|
|
|
1395
1421
|
if(cs >= JSON_array_first_final) {
|
|
1396
1422
|
return p + 1;
|
|
@@ -1435,13 +1461,21 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
|
1435
1461
|
break;
|
|
1436
1462
|
case 'u':
|
|
1437
1463
|
if (pe > stringEnd - 4) {
|
|
1438
|
-
|
|
1464
|
+
rb_enc_raise(
|
|
1465
|
+
EXC_ENCODING eParserError,
|
|
1466
|
+
"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
|
|
1467
|
+
);
|
|
1439
1468
|
} else {
|
|
1440
1469
|
UTF32 ch = unescape_unicode((unsigned char *) ++pe);
|
|
1441
1470
|
pe += 3;
|
|
1442
1471
|
if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
|
|
1443
1472
|
pe++;
|
|
1444
|
-
if (pe > stringEnd - 6)
|
|
1473
|
+
if (pe > stringEnd - 6) {
|
|
1474
|
+
rb_enc_raise(
|
|
1475
|
+
EXC_ENCODING eParserError,
|
|
1476
|
+
"%u: incomplete surrogate pair at '%s'", __LINE__, p
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1445
1479
|
if (pe[0] == '\\' && pe[1] == 'u') {
|
|
1446
1480
|
UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
|
|
1447
1481
|
ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
|
|
@@ -1471,7 +1505,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
|
1471
1505
|
}
|
|
1472
1506
|
|
|
1473
1507
|
|
|
1474
|
-
#line
|
|
1508
|
+
#line 1509 "parser.c"
|
|
1475
1509
|
enum {JSON_string_start = 1};
|
|
1476
1510
|
enum {JSON_string_first_final = 8};
|
|
1477
1511
|
enum {JSON_string_error = 0};
|
|
@@ -1479,7 +1513,7 @@ enum {JSON_string_error = 0};
|
|
|
1479
1513
|
enum {JSON_string_en_main = 1};
|
|
1480
1514
|
|
|
1481
1515
|
|
|
1482
|
-
#line
|
|
1516
|
+
#line 538 "parser.rl"
|
|
1483
1517
|
|
|
1484
1518
|
|
|
1485
1519
|
static int
|
|
@@ -1501,15 +1535,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
|
1501
1535
|
|
|
1502
1536
|
*result = rb_str_buf_new(0);
|
|
1503
1537
|
|
|
1504
|
-
#line
|
|
1538
|
+
#line 1539 "parser.c"
|
|
1505
1539
|
{
|
|
1506
1540
|
cs = JSON_string_start;
|
|
1507
1541
|
}
|
|
1508
1542
|
|
|
1509
|
-
#line
|
|
1543
|
+
#line 559 "parser.rl"
|
|
1510
1544
|
json->memo = p;
|
|
1511
1545
|
|
|
1512
|
-
#line
|
|
1546
|
+
#line 1547 "parser.c"
|
|
1513
1547
|
{
|
|
1514
1548
|
if ( p == pe )
|
|
1515
1549
|
goto _test_eof;
|
|
@@ -1530,11 +1564,11 @@ case 2:
|
|
|
1530
1564
|
case 34: goto tr2;
|
|
1531
1565
|
case 92: goto st3;
|
|
1532
1566
|
}
|
|
1533
|
-
if ( 0 <= (*p) && (*p) <= 31 )
|
|
1567
|
+
if ( 0 <= (signed char)(*p) && (*p) <= 31 )
|
|
1534
1568
|
goto st0;
|
|
1535
1569
|
goto st2;
|
|
1536
1570
|
tr2:
|
|
1537
|
-
#line
|
|
1571
|
+
#line 524 "parser.rl"
|
|
1538
1572
|
{
|
|
1539
1573
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
|
1540
1574
|
if (NIL_P(*result)) {
|
|
@@ -1545,14 +1579,14 @@ tr2:
|
|
|
1545
1579
|
{p = (( p + 1))-1;}
|
|
1546
1580
|
}
|
|
1547
1581
|
}
|
|
1548
|
-
#line
|
|
1582
|
+
#line 535 "parser.rl"
|
|
1549
1583
|
{ p--; {p++; cs = 8; goto _out;} }
|
|
1550
1584
|
goto st8;
|
|
1551
1585
|
st8:
|
|
1552
1586
|
if ( ++p == pe )
|
|
1553
1587
|
goto _test_eof8;
|
|
1554
1588
|
case 8:
|
|
1555
|
-
#line
|
|
1589
|
+
#line 1590 "parser.c"
|
|
1556
1590
|
goto st0;
|
|
1557
1591
|
st3:
|
|
1558
1592
|
if ( ++p == pe )
|
|
@@ -1560,7 +1594,7 @@ st3:
|
|
|
1560
1594
|
case 3:
|
|
1561
1595
|
if ( (*p) == 117 )
|
|
1562
1596
|
goto st4;
|
|
1563
|
-
if ( 0 <= (*p) && (*p) <= 31 )
|
|
1597
|
+
if ( 0 <= (signed char)(*p) && (*p) <= 31 )
|
|
1564
1598
|
goto st0;
|
|
1565
1599
|
goto st2;
|
|
1566
1600
|
st4:
|
|
@@ -1628,7 +1662,7 @@ case 7:
|
|
|
1628
1662
|
_out: {}
|
|
1629
1663
|
}
|
|
1630
1664
|
|
|
1631
|
-
#line
|
|
1665
|
+
#line 561 "parser.rl"
|
|
1632
1666
|
|
|
1633
1667
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
|
1634
1668
|
VALUE klass;
|
|
@@ -1643,7 +1677,7 @@ case 7:
|
|
|
1643
1677
|
|
|
1644
1678
|
if (json->symbolize_names && json->parsing_name) {
|
|
1645
1679
|
*result = rb_str_intern(*result);
|
|
1646
|
-
} else {
|
|
1680
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
|
1647
1681
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
|
1648
1682
|
}
|
|
1649
1683
|
if (cs >= JSON_string_first_final) {
|
|
@@ -1781,6 +1815,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1781
1815
|
} else {
|
|
1782
1816
|
json->array_class = Qnil;
|
|
1783
1817
|
}
|
|
1818
|
+
tmp = ID2SYM(i_decimal_class);
|
|
1819
|
+
if (option_given_p(opts, tmp)) {
|
|
1820
|
+
json->decimal_class = rb_hash_aref(opts, tmp);
|
|
1821
|
+
} else {
|
|
1822
|
+
json->decimal_class = Qnil;
|
|
1823
|
+
}
|
|
1784
1824
|
tmp = ID2SYM(i_match_string);
|
|
1785
1825
|
if (option_given_p(opts, tmp)) {
|
|
1786
1826
|
VALUE match_string = rb_hash_aref(opts, tmp);
|
|
@@ -1794,10 +1834,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1794
1834
|
} else {
|
|
1795
1835
|
json->max_nesting = 100;
|
|
1796
1836
|
json->allow_nan = 0;
|
|
1797
|
-
json->create_additions =
|
|
1837
|
+
json->create_additions = 0;
|
|
1798
1838
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
|
1799
1839
|
json->object_class = Qnil;
|
|
1800
1840
|
json->array_class = Qnil;
|
|
1841
|
+
json->decimal_class = Qnil;
|
|
1801
1842
|
}
|
|
1802
1843
|
source = convert_encoding(StringValue(source));
|
|
1803
1844
|
StringValue(source);
|
|
@@ -1808,7 +1849,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1808
1849
|
}
|
|
1809
1850
|
|
|
1810
1851
|
|
|
1811
|
-
#line
|
|
1852
|
+
#line 1853 "parser.c"
|
|
1812
1853
|
enum {JSON_start = 1};
|
|
1813
1854
|
enum {JSON_first_final = 10};
|
|
1814
1855
|
enum {JSON_error = 0};
|
|
@@ -1816,7 +1857,7 @@ enum {JSON_error = 0};
|
|
|
1816
1857
|
enum {JSON_en_main = 1};
|
|
1817
1858
|
|
|
1818
1859
|
|
|
1819
|
-
#line
|
|
1860
|
+
#line 761 "parser.rl"
|
|
1820
1861
|
|
|
1821
1862
|
|
|
1822
1863
|
/*
|
|
@@ -1833,16 +1874,16 @@ static VALUE cParser_parse(VALUE self)
|
|
|
1833
1874
|
GET_PARSER;
|
|
1834
1875
|
|
|
1835
1876
|
|
|
1836
|
-
#line
|
|
1877
|
+
#line 1878 "parser.c"
|
|
1837
1878
|
{
|
|
1838
1879
|
cs = JSON_start;
|
|
1839
1880
|
}
|
|
1840
1881
|
|
|
1841
|
-
#line
|
|
1882
|
+
#line 777 "parser.rl"
|
|
1842
1883
|
p = json->source;
|
|
1843
1884
|
pe = p + json->len;
|
|
1844
1885
|
|
|
1845
|
-
#line
|
|
1886
|
+
#line 1887 "parser.c"
|
|
1846
1887
|
{
|
|
1847
1888
|
if ( p == pe )
|
|
1848
1889
|
goto _test_eof;
|
|
@@ -1876,7 +1917,7 @@ st0:
|
|
|
1876
1917
|
cs = 0;
|
|
1877
1918
|
goto _out;
|
|
1878
1919
|
tr2:
|
|
1879
|
-
#line
|
|
1920
|
+
#line 753 "parser.rl"
|
|
1880
1921
|
{
|
|
1881
1922
|
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
|
1882
1923
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
|
@@ -1886,7 +1927,7 @@ st10:
|
|
|
1886
1927
|
if ( ++p == pe )
|
|
1887
1928
|
goto _test_eof10;
|
|
1888
1929
|
case 10:
|
|
1889
|
-
#line
|
|
1930
|
+
#line 1931 "parser.c"
|
|
1890
1931
|
switch( (*p) ) {
|
|
1891
1932
|
case 13: goto st10;
|
|
1892
1933
|
case 32: goto st10;
|
|
@@ -1975,7 +2016,7 @@ case 9:
|
|
|
1975
2016
|
_out: {}
|
|
1976
2017
|
}
|
|
1977
2018
|
|
|
1978
|
-
#line
|
|
2019
|
+
#line 780 "parser.rl"
|
|
1979
2020
|
|
|
1980
2021
|
if (cs >= JSON_first_final && p == pe) {
|
|
1981
2022
|
return result;
|
|
@@ -1992,6 +2033,7 @@ static void JSON_mark(void *ptr)
|
|
|
1992
2033
|
rb_gc_mark_maybe(json->create_id);
|
|
1993
2034
|
rb_gc_mark_maybe(json->object_class);
|
|
1994
2035
|
rb_gc_mark_maybe(json->array_class);
|
|
2036
|
+
rb_gc_mark_maybe(json->decimal_class);
|
|
1995
2037
|
rb_gc_mark_maybe(json->match_string);
|
|
1996
2038
|
}
|
|
1997
2039
|
|
|
@@ -2041,20 +2083,28 @@ static VALUE cParser_source(VALUE self)
|
|
|
2041
2083
|
|
|
2042
2084
|
void Init_parser(void)
|
|
2043
2085
|
{
|
|
2086
|
+
#undef rb_intern
|
|
2044
2087
|
rb_require("json/common");
|
|
2045
2088
|
mJSON = rb_define_module("JSON");
|
|
2046
2089
|
mExt = rb_define_module_under(mJSON, "Ext");
|
|
2047
2090
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
|
2048
2091
|
eParserError = rb_path2class("JSON::ParserError");
|
|
2049
2092
|
eNestingError = rb_path2class("JSON::NestingError");
|
|
2093
|
+
rb_gc_register_mark_object(eParserError);
|
|
2094
|
+
rb_gc_register_mark_object(eNestingError);
|
|
2050
2095
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
|
2051
2096
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
|
2052
2097
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
|
2053
2098
|
rb_define_method(cParser, "source", cParser_source, 0);
|
|
2054
2099
|
|
|
2055
2100
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
|
2101
|
+
rb_gc_register_mark_object(CNaN);
|
|
2102
|
+
|
|
2056
2103
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
|
2104
|
+
rb_gc_register_mark_object(CInfinity);
|
|
2105
|
+
|
|
2057
2106
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
|
2107
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
|
2058
2108
|
|
|
2059
2109
|
i_json_creatable_p = rb_intern("json_creatable?");
|
|
2060
2110
|
i_json_create = rb_intern("json_create");
|
|
@@ -2066,6 +2116,7 @@ void Init_parser(void)
|
|
|
2066
2116
|
i_symbolize_names = rb_intern("symbolize_names");
|
|
2067
2117
|
i_object_class = rb_intern("object_class");
|
|
2068
2118
|
i_array_class = rb_intern("array_class");
|
|
2119
|
+
i_decimal_class = rb_intern("decimal_class");
|
|
2069
2120
|
i_match = rb_intern("match");
|
|
2070
2121
|
i_match_string = rb_intern("match_string");
|
|
2071
2122
|
i_key_p = rb_intern("key?");
|
|
@@ -2073,6 +2124,8 @@ void Init_parser(void)
|
|
|
2073
2124
|
i_aset = rb_intern("[]=");
|
|
2074
2125
|
i_aref = rb_intern("[]");
|
|
2075
2126
|
i_leftshift = rb_intern("<<");
|
|
2127
|
+
i_new = rb_intern("new");
|
|
2128
|
+
i_BigDecimal = rb_intern("BigDecimal");
|
|
2076
2129
|
}
|
|
2077
2130
|
|
|
2078
2131
|
/*
|