json 2.1.0 → 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 +3 -0
- data/Gemfile +0 -2
- data/LICENSE +56 -0
- data/README.md +38 -21
- data/Rakefile +10 -5
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +96 -40
- data/ext/json/ext/parser/parser.c +106 -79
- data/ext/json/ext/parser/parser.rl +33 -6
- data/java/src/json/ext/Generator.java +33 -10
- data/java/src/json/ext/Parser.java +3 -3
- data/java/src/json/ext/Parser.rl +1 -1
- 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 +9 -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_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +15 -14
- 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
@@ -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,19 +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
98
|
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
98
99
|
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
99
|
-
i_leftshift, i_new;
|
100
|
+
i_leftshift, i_new, i_BigDecimal;
|
100
101
|
|
101
102
|
|
102
|
-
#line
|
103
|
+
#line 126 "parser.rl"
|
103
104
|
|
104
105
|
|
105
106
|
|
106
|
-
#line
|
107
|
+
#line 108 "parser.c"
|
107
108
|
enum {JSON_object_start = 1};
|
108
109
|
enum {JSON_object_first_final = 27};
|
109
110
|
enum {JSON_object_error = 0};
|
@@ -111,7 +112,7 @@ enum {JSON_object_error = 0};
|
|
111
112
|
enum {JSON_object_en_main = 1};
|
112
113
|
|
113
114
|
|
114
|
-
#line
|
115
|
+
#line 167 "parser.rl"
|
115
116
|
|
116
117
|
|
117
118
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
@@ -127,14 +128,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
127
128
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
128
129
|
|
129
130
|
|
130
|
-
#line
|
131
|
+
#line 132 "parser.c"
|
131
132
|
{
|
132
133
|
cs = JSON_object_start;
|
133
134
|
}
|
134
135
|
|
135
|
-
#line
|
136
|
+
#line 182 "parser.rl"
|
136
137
|
|
137
|
-
#line
|
138
|
+
#line 139 "parser.c"
|
138
139
|
{
|
139
140
|
if ( p == pe )
|
140
141
|
goto _test_eof;
|
@@ -162,7 +163,7 @@ case 2:
|
|
162
163
|
goto st2;
|
163
164
|
goto st0;
|
164
165
|
tr2:
|
165
|
-
#line
|
166
|
+
#line 149 "parser.rl"
|
166
167
|
{
|
167
168
|
char *np;
|
168
169
|
json->parsing_name = 1;
|
@@ -175,7 +176,7 @@ st3:
|
|
175
176
|
if ( ++p == pe )
|
176
177
|
goto _test_eof3;
|
177
178
|
case 3:
|
178
|
-
#line
|
179
|
+
#line 180 "parser.c"
|
179
180
|
switch( (*p) ) {
|
180
181
|
case 13: goto st3;
|
181
182
|
case 32: goto st3;
|
@@ -242,7 +243,7 @@ case 8:
|
|
242
243
|
goto st8;
|
243
244
|
goto st0;
|
244
245
|
tr11:
|
245
|
-
#line
|
246
|
+
#line 134 "parser.rl"
|
246
247
|
{
|
247
248
|
VALUE v = Qnil;
|
248
249
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
@@ -262,7 +263,7 @@ st9:
|
|
262
263
|
if ( ++p == pe )
|
263
264
|
goto _test_eof9;
|
264
265
|
case 9:
|
265
|
-
#line
|
266
|
+
#line 267 "parser.c"
|
266
267
|
switch( (*p) ) {
|
267
268
|
case 13: goto st9;
|
268
269
|
case 32: goto st9;
|
@@ -351,14 +352,14 @@ case 18:
|
|
351
352
|
goto st9;
|
352
353
|
goto st18;
|
353
354
|
tr4:
|
354
|
-
#line
|
355
|
+
#line 157 "parser.rl"
|
355
356
|
{ p--; {p++; cs = 27; goto _out;} }
|
356
357
|
goto st27;
|
357
358
|
st27:
|
358
359
|
if ( ++p == pe )
|
359
360
|
goto _test_eof27;
|
360
361
|
case 27:
|
361
|
-
#line
|
362
|
+
#line 363 "parser.c"
|
362
363
|
goto st0;
|
363
364
|
st19:
|
364
365
|
if ( ++p == pe )
|
@@ -456,7 +457,7 @@ case 26:
|
|
456
457
|
_out: {}
|
457
458
|
}
|
458
459
|
|
459
|
-
#line
|
460
|
+
#line 183 "parser.rl"
|
460
461
|
|
461
462
|
if (cs >= JSON_object_first_final) {
|
462
463
|
if (json->create_additions) {
|
@@ -481,7 +482,7 @@ case 26:
|
|
481
482
|
|
482
483
|
|
483
484
|
|
484
|
-
#line
|
485
|
+
#line 486 "parser.c"
|
485
486
|
enum {JSON_value_start = 1};
|
486
487
|
enum {JSON_value_first_final = 29};
|
487
488
|
enum {JSON_value_error = 0};
|
@@ -489,7 +490,7 @@ enum {JSON_value_error = 0};
|
|
489
490
|
enum {JSON_value_en_main = 1};
|
490
491
|
|
491
492
|
|
492
|
-
#line
|
493
|
+
#line 283 "parser.rl"
|
493
494
|
|
494
495
|
|
495
496
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
@@ -497,14 +498,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
497
498
|
int cs = EVIL;
|
498
499
|
|
499
500
|
|
500
|
-
#line
|
501
|
+
#line 502 "parser.c"
|
501
502
|
{
|
502
503
|
cs = JSON_value_start;
|
503
504
|
}
|
504
505
|
|
505
|
-
#line
|
506
|
+
#line 290 "parser.rl"
|
506
507
|
|
507
|
-
#line
|
508
|
+
#line 509 "parser.c"
|
508
509
|
{
|
509
510
|
if ( p == pe )
|
510
511
|
goto _test_eof;
|
@@ -538,14 +539,14 @@ st0:
|
|
538
539
|
cs = 0;
|
539
540
|
goto _out;
|
540
541
|
tr2:
|
541
|
-
#line
|
542
|
+
#line 235 "parser.rl"
|
542
543
|
{
|
543
544
|
char *np = JSON_parse_string(json, p, pe, result);
|
544
545
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
545
546
|
}
|
546
547
|
goto st29;
|
547
548
|
tr3:
|
548
|
-
#line
|
549
|
+
#line 240 "parser.rl"
|
549
550
|
{
|
550
551
|
char *np;
|
551
552
|
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
@@ -565,7 +566,7 @@ tr3:
|
|
565
566
|
}
|
566
567
|
goto st29;
|
567
568
|
tr7:
|
568
|
-
#line
|
569
|
+
#line 258 "parser.rl"
|
569
570
|
{
|
570
571
|
char *np;
|
571
572
|
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
@@ -573,7 +574,7 @@ tr7:
|
|
573
574
|
}
|
574
575
|
goto st29;
|
575
576
|
tr11:
|
576
|
-
#line
|
577
|
+
#line 264 "parser.rl"
|
577
578
|
{
|
578
579
|
char *np;
|
579
580
|
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
@@ -581,7 +582,7 @@ tr11:
|
|
581
582
|
}
|
582
583
|
goto st29;
|
583
584
|
tr25:
|
584
|
-
#line
|
585
|
+
#line 228 "parser.rl"
|
585
586
|
{
|
586
587
|
if (json->allow_nan) {
|
587
588
|
*result = CInfinity;
|
@@ -591,7 +592,7 @@ tr25:
|
|
591
592
|
}
|
592
593
|
goto st29;
|
593
594
|
tr27:
|
594
|
-
#line
|
595
|
+
#line 221 "parser.rl"
|
595
596
|
{
|
596
597
|
if (json->allow_nan) {
|
597
598
|
*result = CNaN;
|
@@ -601,19 +602,19 @@ tr27:
|
|
601
602
|
}
|
602
603
|
goto st29;
|
603
604
|
tr31:
|
604
|
-
#line
|
605
|
+
#line 215 "parser.rl"
|
605
606
|
{
|
606
607
|
*result = Qfalse;
|
607
608
|
}
|
608
609
|
goto st29;
|
609
610
|
tr34:
|
610
|
-
#line
|
611
|
+
#line 212 "parser.rl"
|
611
612
|
{
|
612
613
|
*result = Qnil;
|
613
614
|
}
|
614
615
|
goto st29;
|
615
616
|
tr37:
|
616
|
-
#line
|
617
|
+
#line 218 "parser.rl"
|
617
618
|
{
|
618
619
|
*result = Qtrue;
|
619
620
|
}
|
@@ -622,9 +623,9 @@ st29:
|
|
622
623
|
if ( ++p == pe )
|
623
624
|
goto _test_eof29;
|
624
625
|
case 29:
|
625
|
-
#line
|
626
|
+
#line 270 "parser.rl"
|
626
627
|
{ p--; {p++; cs = 29; goto _out;} }
|
627
|
-
#line
|
628
|
+
#line 629 "parser.c"
|
628
629
|
switch( (*p) ) {
|
629
630
|
case 13: goto st29;
|
630
631
|
case 32: goto st29;
|
@@ -865,7 +866,7 @@ case 28:
|
|
865
866
|
_out: {}
|
866
867
|
}
|
867
868
|
|
868
|
-
#line
|
869
|
+
#line 291 "parser.rl"
|
869
870
|
|
870
871
|
if (cs >= JSON_value_first_final) {
|
871
872
|
return p;
|
@@ -875,7 +876,7 @@ case 28:
|
|
875
876
|
}
|
876
877
|
|
877
878
|
|
878
|
-
#line
|
879
|
+
#line 880 "parser.c"
|
879
880
|
enum {JSON_integer_start = 1};
|
880
881
|
enum {JSON_integer_first_final = 3};
|
881
882
|
enum {JSON_integer_error = 0};
|
@@ -883,7 +884,7 @@ enum {JSON_integer_error = 0};
|
|
883
884
|
enum {JSON_integer_en_main = 1};
|
884
885
|
|
885
886
|
|
886
|
-
#line
|
887
|
+
#line 307 "parser.rl"
|
887
888
|
|
888
889
|
|
889
890
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -891,15 +892,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
891
892
|
int cs = EVIL;
|
892
893
|
|
893
894
|
|
894
|
-
#line
|
895
|
+
#line 896 "parser.c"
|
895
896
|
{
|
896
897
|
cs = JSON_integer_start;
|
897
898
|
}
|
898
899
|
|
899
|
-
#line
|
900
|
+
#line 314 "parser.rl"
|
900
901
|
json->memo = p;
|
901
902
|
|
902
|
-
#line
|
903
|
+
#line 904 "parser.c"
|
903
904
|
{
|
904
905
|
if ( p == pe )
|
905
906
|
goto _test_eof;
|
@@ -933,14 +934,14 @@ case 3:
|
|
933
934
|
goto st0;
|
934
935
|
goto tr4;
|
935
936
|
tr4:
|
936
|
-
#line
|
937
|
+
#line 304 "parser.rl"
|
937
938
|
{ p--; {p++; cs = 4; goto _out;} }
|
938
939
|
goto st4;
|
939
940
|
st4:
|
940
941
|
if ( ++p == pe )
|
941
942
|
goto _test_eof4;
|
942
943
|
case 4:
|
943
|
-
#line
|
944
|
+
#line 945 "parser.c"
|
944
945
|
goto st0;
|
945
946
|
st5:
|
946
947
|
if ( ++p == pe )
|
@@ -959,7 +960,7 @@ case 5:
|
|
959
960
|
_out: {}
|
960
961
|
}
|
961
962
|
|
962
|
-
#line
|
963
|
+
#line 316 "parser.rl"
|
963
964
|
|
964
965
|
if (cs >= JSON_integer_first_final) {
|
965
966
|
long len = p - json->memo;
|
@@ -974,7 +975,7 @@ case 5:
|
|
974
975
|
}
|
975
976
|
|
976
977
|
|
977
|
-
#line
|
978
|
+
#line 979 "parser.c"
|
978
979
|
enum {JSON_float_start = 1};
|
979
980
|
enum {JSON_float_first_final = 8};
|
980
981
|
enum {JSON_float_error = 0};
|
@@ -982,23 +983,36 @@ enum {JSON_float_error = 0};
|
|
982
983
|
enum {JSON_float_en_main = 1};
|
983
984
|
|
984
985
|
|
985
|
-
#line
|
986
|
+
#line 341 "parser.rl"
|
986
987
|
|
987
988
|
|
989
|
+
static int is_bigdecimal_class(VALUE obj)
|
990
|
+
{
|
991
|
+
if (cBigDecimal == Qundef) {
|
992
|
+
if (rb_const_defined(rb_cObject, i_BigDecimal)) {
|
993
|
+
cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
|
994
|
+
}
|
995
|
+
else {
|
996
|
+
return 0;
|
997
|
+
}
|
998
|
+
}
|
999
|
+
return obj == cBigDecimal;
|
1000
|
+
}
|
1001
|
+
|
988
1002
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
989
1003
|
{
|
990
1004
|
int cs = EVIL;
|
991
1005
|
|
992
1006
|
|
993
|
-
#line
|
1007
|
+
#line 1008 "parser.c"
|
994
1008
|
{
|
995
1009
|
cs = JSON_float_start;
|
996
1010
|
}
|
997
1011
|
|
998
|
-
#line
|
1012
|
+
#line 361 "parser.rl"
|
999
1013
|
json->memo = p;
|
1000
1014
|
|
1001
|
-
#line
|
1015
|
+
#line 1016 "parser.c"
|
1002
1016
|
{
|
1003
1017
|
if ( p == pe )
|
1004
1018
|
goto _test_eof;
|
@@ -1056,14 +1070,14 @@ case 8:
|
|
1056
1070
|
goto st0;
|
1057
1071
|
goto tr9;
|
1058
1072
|
tr9:
|
1059
|
-
#line
|
1073
|
+
#line 335 "parser.rl"
|
1060
1074
|
{ p--; {p++; cs = 9; goto _out;} }
|
1061
1075
|
goto st9;
|
1062
1076
|
st9:
|
1063
1077
|
if ( ++p == pe )
|
1064
1078
|
goto _test_eof9;
|
1065
1079
|
case 9:
|
1066
|
-
#line
|
1080
|
+
#line 1081 "parser.c"
|
1067
1081
|
goto st0;
|
1068
1082
|
st5:
|
1069
1083
|
if ( ++p == pe )
|
@@ -1124,7 +1138,7 @@ case 7:
|
|
1124
1138
|
_out: {}
|
1125
1139
|
}
|
1126
1140
|
|
1127
|
-
#line
|
1141
|
+
#line 363 "parser.rl"
|
1128
1142
|
|
1129
1143
|
if (cs >= JSON_float_first_final) {
|
1130
1144
|
long len = p - json->memo;
|
@@ -1136,7 +1150,11 @@ case 7:
|
|
1136
1150
|
} else {
|
1137
1151
|
VALUE text;
|
1138
1152
|
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
1139
|
-
|
1153
|
+
if (is_bigdecimal_class(json->decimal_class)) {
|
1154
|
+
*result = rb_funcall(Qnil, i_BigDecimal, 1, text);
|
1155
|
+
} else {
|
1156
|
+
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
1157
|
+
}
|
1140
1158
|
}
|
1141
1159
|
return p + 1;
|
1142
1160
|
} else {
|
@@ -1146,7 +1164,7 @@ case 7:
|
|
1146
1164
|
|
1147
1165
|
|
1148
1166
|
|
1149
|
-
#line
|
1167
|
+
#line 1168 "parser.c"
|
1150
1168
|
enum {JSON_array_start = 1};
|
1151
1169
|
enum {JSON_array_first_final = 17};
|
1152
1170
|
enum {JSON_array_error = 0};
|
@@ -1154,7 +1172,7 @@ enum {JSON_array_error = 0};
|
|
1154
1172
|
enum {JSON_array_en_main = 1};
|
1155
1173
|
|
1156
1174
|
|
1157
|
-
#line
|
1175
|
+
#line 416 "parser.rl"
|
1158
1176
|
|
1159
1177
|
|
1160
1178
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
@@ -1168,14 +1186,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
1168
1186
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1169
1187
|
|
1170
1188
|
|
1171
|
-
#line
|
1189
|
+
#line 1190 "parser.c"
|
1172
1190
|
{
|
1173
1191
|
cs = JSON_array_start;
|
1174
1192
|
}
|
1175
1193
|
|
1176
|
-
#line
|
1194
|
+
#line 429 "parser.rl"
|
1177
1195
|
|
1178
|
-
#line
|
1196
|
+
#line 1197 "parser.c"
|
1179
1197
|
{
|
1180
1198
|
if ( p == pe )
|
1181
1199
|
goto _test_eof;
|
@@ -1214,7 +1232,7 @@ case 2:
|
|
1214
1232
|
goto st2;
|
1215
1233
|
goto st0;
|
1216
1234
|
tr2:
|
1217
|
-
#line
|
1235
|
+
#line 393 "parser.rl"
|
1218
1236
|
{
|
1219
1237
|
VALUE v = Qnil;
|
1220
1238
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
@@ -1234,7 +1252,7 @@ st3:
|
|
1234
1252
|
if ( ++p == pe )
|
1235
1253
|
goto _test_eof3;
|
1236
1254
|
case 3:
|
1237
|
-
#line
|
1255
|
+
#line 1256 "parser.c"
|
1238
1256
|
switch( (*p) ) {
|
1239
1257
|
case 13: goto st3;
|
1240
1258
|
case 32: goto st3;
|
@@ -1334,14 +1352,14 @@ case 12:
|
|
1334
1352
|
goto st3;
|
1335
1353
|
goto st12;
|
1336
1354
|
tr4:
|
1337
|
-
#line
|
1355
|
+
#line 408 "parser.rl"
|
1338
1356
|
{ p--; {p++; cs = 17; goto _out;} }
|
1339
1357
|
goto st17;
|
1340
1358
|
st17:
|
1341
1359
|
if ( ++p == pe )
|
1342
1360
|
goto _test_eof17;
|
1343
1361
|
case 17:
|
1344
|
-
#line
|
1362
|
+
#line 1363 "parser.c"
|
1345
1363
|
goto st0;
|
1346
1364
|
st13:
|
1347
1365
|
if ( ++p == pe )
|
@@ -1397,7 +1415,7 @@ case 16:
|
|
1397
1415
|
_out: {}
|
1398
1416
|
}
|
1399
1417
|
|
1400
|
-
#line
|
1418
|
+
#line 430 "parser.rl"
|
1401
1419
|
|
1402
1420
|
if(cs >= JSON_array_first_final) {
|
1403
1421
|
return p + 1;
|
@@ -1486,7 +1504,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1486
1504
|
}
|
1487
1505
|
|
1488
1506
|
|
1489
|
-
#line
|
1507
|
+
#line 1508 "parser.c"
|
1490
1508
|
enum {JSON_string_start = 1};
|
1491
1509
|
enum {JSON_string_first_final = 8};
|
1492
1510
|
enum {JSON_string_error = 0};
|
@@ -1494,7 +1512,7 @@ enum {JSON_string_error = 0};
|
|
1494
1512
|
enum {JSON_string_en_main = 1};
|
1495
1513
|
|
1496
1514
|
|
1497
|
-
#line
|
1515
|
+
#line 537 "parser.rl"
|
1498
1516
|
|
1499
1517
|
|
1500
1518
|
static int
|
@@ -1516,15 +1534,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1516
1534
|
|
1517
1535
|
*result = rb_str_buf_new(0);
|
1518
1536
|
|
1519
|
-
#line
|
1537
|
+
#line 1538 "parser.c"
|
1520
1538
|
{
|
1521
1539
|
cs = JSON_string_start;
|
1522
1540
|
}
|
1523
1541
|
|
1524
|
-
#line
|
1542
|
+
#line 558 "parser.rl"
|
1525
1543
|
json->memo = p;
|
1526
1544
|
|
1527
|
-
#line
|
1545
|
+
#line 1546 "parser.c"
|
1528
1546
|
{
|
1529
1547
|
if ( p == pe )
|
1530
1548
|
goto _test_eof;
|
@@ -1549,7 +1567,7 @@ case 2:
|
|
1549
1567
|
goto st0;
|
1550
1568
|
goto st2;
|
1551
1569
|
tr2:
|
1552
|
-
#line
|
1570
|
+
#line 523 "parser.rl"
|
1553
1571
|
{
|
1554
1572
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
1555
1573
|
if (NIL_P(*result)) {
|
@@ -1560,14 +1578,14 @@ tr2:
|
|
1560
1578
|
{p = (( p + 1))-1;}
|
1561
1579
|
}
|
1562
1580
|
}
|
1563
|
-
#line
|
1581
|
+
#line 534 "parser.rl"
|
1564
1582
|
{ p--; {p++; cs = 8; goto _out;} }
|
1565
1583
|
goto st8;
|
1566
1584
|
st8:
|
1567
1585
|
if ( ++p == pe )
|
1568
1586
|
goto _test_eof8;
|
1569
1587
|
case 8:
|
1570
|
-
#line
|
1588
|
+
#line 1589 "parser.c"
|
1571
1589
|
goto st0;
|
1572
1590
|
st3:
|
1573
1591
|
if ( ++p == pe )
|
@@ -1643,7 +1661,7 @@ case 7:
|
|
1643
1661
|
_out: {}
|
1644
1662
|
}
|
1645
1663
|
|
1646
|
-
#line
|
1664
|
+
#line 560 "parser.rl"
|
1647
1665
|
|
1648
1666
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1649
1667
|
VALUE klass;
|
@@ -1658,7 +1676,7 @@ case 7:
|
|
1658
1676
|
|
1659
1677
|
if (json->symbolize_names && json->parsing_name) {
|
1660
1678
|
*result = rb_str_intern(*result);
|
1661
|
-
} else {
|
1679
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
1662
1680
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
1663
1681
|
}
|
1664
1682
|
if (cs >= JSON_string_first_final) {
|
@@ -1815,7 +1833,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1815
1833
|
} else {
|
1816
1834
|
json->max_nesting = 100;
|
1817
1835
|
json->allow_nan = 0;
|
1818
|
-
json->create_additions =
|
1836
|
+
json->create_additions = 0;
|
1819
1837
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1820
1838
|
json->object_class = Qnil;
|
1821
1839
|
json->array_class = Qnil;
|
@@ -1830,7 +1848,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1830
1848
|
}
|
1831
1849
|
|
1832
1850
|
|
1833
|
-
#line
|
1851
|
+
#line 1852 "parser.c"
|
1834
1852
|
enum {JSON_start = 1};
|
1835
1853
|
enum {JSON_first_final = 10};
|
1836
1854
|
enum {JSON_error = 0};
|
@@ -1838,7 +1856,7 @@ enum {JSON_error = 0};
|
|
1838
1856
|
enum {JSON_en_main = 1};
|
1839
1857
|
|
1840
1858
|
|
1841
|
-
#line
|
1859
|
+
#line 760 "parser.rl"
|
1842
1860
|
|
1843
1861
|
|
1844
1862
|
/*
|
@@ -1855,16 +1873,16 @@ static VALUE cParser_parse(VALUE self)
|
|
1855
1873
|
GET_PARSER;
|
1856
1874
|
|
1857
1875
|
|
1858
|
-
#line
|
1876
|
+
#line 1877 "parser.c"
|
1859
1877
|
{
|
1860
1878
|
cs = JSON_start;
|
1861
1879
|
}
|
1862
1880
|
|
1863
|
-
#line
|
1881
|
+
#line 776 "parser.rl"
|
1864
1882
|
p = json->source;
|
1865
1883
|
pe = p + json->len;
|
1866
1884
|
|
1867
|
-
#line
|
1885
|
+
#line 1886 "parser.c"
|
1868
1886
|
{
|
1869
1887
|
if ( p == pe )
|
1870
1888
|
goto _test_eof;
|
@@ -1898,7 +1916,7 @@ st0:
|
|
1898
1916
|
cs = 0;
|
1899
1917
|
goto _out;
|
1900
1918
|
tr2:
|
1901
|
-
#line
|
1919
|
+
#line 752 "parser.rl"
|
1902
1920
|
{
|
1903
1921
|
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
1904
1922
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
@@ -1908,7 +1926,7 @@ st10:
|
|
1908
1926
|
if ( ++p == pe )
|
1909
1927
|
goto _test_eof10;
|
1910
1928
|
case 10:
|
1911
|
-
#line
|
1929
|
+
#line 1930 "parser.c"
|
1912
1930
|
switch( (*p) ) {
|
1913
1931
|
case 13: goto st10;
|
1914
1932
|
case 32: goto st10;
|
@@ -1997,7 +2015,7 @@ case 9:
|
|
1997
2015
|
_out: {}
|
1998
2016
|
}
|
1999
2017
|
|
2000
|
-
#line
|
2018
|
+
#line 779 "parser.rl"
|
2001
2019
|
|
2002
2020
|
if (cs >= JSON_first_final && p == pe) {
|
2003
2021
|
return result;
|
@@ -2064,20 +2082,28 @@ static VALUE cParser_source(VALUE self)
|
|
2064
2082
|
|
2065
2083
|
void Init_parser(void)
|
2066
2084
|
{
|
2085
|
+
#undef rb_intern
|
2067
2086
|
rb_require("json/common");
|
2068
2087
|
mJSON = rb_define_module("JSON");
|
2069
2088
|
mExt = rb_define_module_under(mJSON, "Ext");
|
2070
2089
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
2071
2090
|
eParserError = rb_path2class("JSON::ParserError");
|
2072
2091
|
eNestingError = rb_path2class("JSON::NestingError");
|
2092
|
+
rb_gc_register_mark_object(eParserError);
|
2093
|
+
rb_gc_register_mark_object(eNestingError);
|
2073
2094
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
2074
2095
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
2075
2096
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
2076
2097
|
rb_define_method(cParser, "source", cParser_source, 0);
|
2077
2098
|
|
2078
2099
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
2100
|
+
rb_gc_register_mark_object(CNaN);
|
2101
|
+
|
2079
2102
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
2103
|
+
rb_gc_register_mark_object(CInfinity);
|
2104
|
+
|
2080
2105
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
2106
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
2081
2107
|
|
2082
2108
|
i_json_creatable_p = rb_intern("json_creatable?");
|
2083
2109
|
i_json_create = rb_intern("json_create");
|
@@ -2098,6 +2124,7 @@ void Init_parser(void)
|
|
2098
2124
|
i_aref = rb_intern("[]");
|
2099
2125
|
i_leftshift = rb_intern("<<");
|
2100
2126
|
i_new = rb_intern("new");
|
2127
|
+
i_BigDecimal = rb_intern("BigDecimal");
|
2101
2128
|
}
|
2102
2129
|
|
2103
2130
|
/*
|