json-maglev- 1.6.1 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/CHANGES +13 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/benchmarks/data/.keep +0 -0
- data/benchmarks/data-p4-3GHz-ruby18/.keep +0 -0
- data/benchmarks/generator2_benchmark.rb +1 -1
- data/benchmarks/generator_benchmark.rb +1 -1
- data/benchmarks/parser2_benchmark.rb +1 -1
- data/benchmarks/parser_benchmark.rb +1 -1
- data/diagrams/.keep +0 -0
- data/ext/json/ext/fbuffer/fbuffer.h +156 -0
- data/ext/json/ext/generator/generator.c +57 -132
- data/ext/json/ext/generator/generator.h +2 -39
- data/ext/json/ext/parser/parser.c +100 -94
- data/ext/json/ext/parser/parser.h +1 -6
- data/ext/json/ext/parser/parser.rl +18 -9
- data/java/src/json/ext/GeneratorState.java +21 -0
- data/json.gemspec +16 -16
- data/json_pure.gemspec +15 -15
- data/lib/json/add/bigdecimal.rb +21 -0
- data/lib/json/add/ostruct.rb +31 -0
- data/lib/json/add/time.rb +2 -2
- data/lib/json/common.rb +40 -5
- data/lib/json/ext/.keep +0 -0
- data/lib/json/ext.rb +6 -0
- data/lib/json/pure/generator.rb +20 -9
- data/lib/json/pure/parser.rb +7 -2
- data/lib/json/pure.rb +6 -0
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +17 -1
- data/tests/test_json_addition.rb +15 -1
- data/tests/test_json_generate.rb +66 -30
- metadata +128 -119
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
#line 1 "parser.rl"
|
3
|
+
#include "../fbuffer/fbuffer.h"
|
3
4
|
#include "parser.h"
|
4
5
|
|
5
6
|
/* unicode */
|
@@ -83,11 +84,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
|
83
84
|
i_match_string, i_aset, i_leftshift;
|
84
85
|
|
85
86
|
|
86
|
-
#line
|
87
|
+
#line 110 "parser.rl"
|
87
88
|
|
88
89
|
|
89
90
|
|
90
|
-
#line
|
91
|
+
#line 92 "parser.c"
|
91
92
|
static const int JSON_object_start = 1;
|
92
93
|
static const int JSON_object_first_final = 27;
|
93
94
|
static const int JSON_object_error = 0;
|
@@ -95,7 +96,7 @@ static const int JSON_object_error = 0;
|
|
95
96
|
static const int JSON_object_en_main = 1;
|
96
97
|
|
97
98
|
|
98
|
-
#line
|
99
|
+
#line 151 "parser.rl"
|
99
100
|
|
100
101
|
|
101
102
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -111,14 +112,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
111
112
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
112
113
|
|
113
114
|
|
114
|
-
#line
|
115
|
+
#line 116 "parser.c"
|
115
116
|
{
|
116
117
|
cs = JSON_object_start;
|
117
118
|
}
|
118
119
|
|
119
|
-
#line
|
120
|
+
#line 166 "parser.rl"
|
120
121
|
|
121
|
-
#line
|
122
|
+
#line 123 "parser.c"
|
122
123
|
{
|
123
124
|
if ( p == pe )
|
124
125
|
goto _test_eof;
|
@@ -146,7 +147,7 @@ case 2:
|
|
146
147
|
goto st2;
|
147
148
|
goto st0;
|
148
149
|
tr2:
|
149
|
-
#line
|
150
|
+
#line 133 "parser.rl"
|
150
151
|
{
|
151
152
|
char *np;
|
152
153
|
json->parsing_name = 1;
|
@@ -159,7 +160,7 @@ st3:
|
|
159
160
|
if ( ++p == pe )
|
160
161
|
goto _test_eof3;
|
161
162
|
case 3:
|
162
|
-
#line
|
163
|
+
#line 164 "parser.c"
|
163
164
|
switch( (*p) ) {
|
164
165
|
case 13: goto st3;
|
165
166
|
case 32: goto st3;
|
@@ -226,7 +227,7 @@ case 8:
|
|
226
227
|
goto st8;
|
227
228
|
goto st0;
|
228
229
|
tr11:
|
229
|
-
#line
|
230
|
+
#line 118 "parser.rl"
|
230
231
|
{
|
231
232
|
VALUE v = Qnil;
|
232
233
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -246,7 +247,7 @@ st9:
|
|
246
247
|
if ( ++p == pe )
|
247
248
|
goto _test_eof9;
|
248
249
|
case 9:
|
249
|
-
#line
|
250
|
+
#line 251 "parser.c"
|
250
251
|
switch( (*p) ) {
|
251
252
|
case 13: goto st9;
|
252
253
|
case 32: goto st9;
|
@@ -335,14 +336,14 @@ case 18:
|
|
335
336
|
goto st9;
|
336
337
|
goto st18;
|
337
338
|
tr4:
|
338
|
-
#line
|
339
|
+
#line 141 "parser.rl"
|
339
340
|
{ p--; {p++; cs = 27; goto _out;} }
|
340
341
|
goto st27;
|
341
342
|
st27:
|
342
343
|
if ( ++p == pe )
|
343
344
|
goto _test_eof27;
|
344
345
|
case 27:
|
345
|
-
#line
|
346
|
+
#line 347 "parser.c"
|
346
347
|
goto st0;
|
347
348
|
st19:
|
348
349
|
if ( ++p == pe )
|
@@ -440,7 +441,7 @@ case 26:
|
|
440
441
|
_out: {}
|
441
442
|
}
|
442
443
|
|
443
|
-
#line
|
444
|
+
#line 167 "parser.rl"
|
444
445
|
|
445
446
|
if (cs >= JSON_object_first_final) {
|
446
447
|
if (json->create_additions) {
|
@@ -460,7 +461,7 @@ case 26:
|
|
460
461
|
|
461
462
|
|
462
463
|
|
463
|
-
#line
|
464
|
+
#line 465 "parser.c"
|
464
465
|
static const int JSON_value_start = 1;
|
465
466
|
static const int JSON_value_first_final = 21;
|
466
467
|
static const int JSON_value_error = 0;
|
@@ -468,7 +469,7 @@ static const int JSON_value_error = 0;
|
|
468
469
|
static const int JSON_value_en_main = 1;
|
469
470
|
|
470
471
|
|
471
|
-
#line
|
472
|
+
#line 266 "parser.rl"
|
472
473
|
|
473
474
|
|
474
475
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -476,14 +477,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
476
477
|
int cs = EVIL;
|
477
478
|
|
478
479
|
|
479
|
-
#line
|
480
|
+
#line 481 "parser.c"
|
480
481
|
{
|
481
482
|
cs = JSON_value_start;
|
482
483
|
}
|
483
484
|
|
484
|
-
#line
|
485
|
+
#line 273 "parser.rl"
|
485
486
|
|
486
|
-
#line
|
487
|
+
#line 488 "parser.c"
|
487
488
|
{
|
488
489
|
if ( p == pe )
|
489
490
|
goto _test_eof;
|
@@ -508,14 +509,14 @@ st0:
|
|
508
509
|
cs = 0;
|
509
510
|
goto _out;
|
510
511
|
tr0:
|
511
|
-
#line
|
512
|
+
#line 214 "parser.rl"
|
512
513
|
{
|
513
514
|
char *np = JSON_parse_string(json, p, pe, result);
|
514
515
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
515
516
|
}
|
516
517
|
goto st21;
|
517
518
|
tr2:
|
518
|
-
#line
|
519
|
+
#line 219 "parser.rl"
|
519
520
|
{
|
520
521
|
char *np;
|
521
522
|
if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
|
@@ -535,7 +536,7 @@ tr2:
|
|
535
536
|
}
|
536
537
|
goto st21;
|
537
538
|
tr5:
|
538
|
-
#line
|
539
|
+
#line 237 "parser.rl"
|
539
540
|
{
|
540
541
|
char *np;
|
541
542
|
json->current_nesting++;
|
@@ -545,7 +546,7 @@ tr5:
|
|
545
546
|
}
|
546
547
|
goto st21;
|
547
548
|
tr9:
|
548
|
-
#line
|
549
|
+
#line 245 "parser.rl"
|
549
550
|
{
|
550
551
|
char *np;
|
551
552
|
json->current_nesting++;
|
@@ -555,7 +556,7 @@ tr9:
|
|
555
556
|
}
|
556
557
|
goto st21;
|
557
558
|
tr16:
|
558
|
-
#line
|
559
|
+
#line 207 "parser.rl"
|
559
560
|
{
|
560
561
|
if (json->allow_nan) {
|
561
562
|
*result = CInfinity;
|
@@ -565,7 +566,7 @@ tr16:
|
|
565
566
|
}
|
566
567
|
goto st21;
|
567
568
|
tr18:
|
568
|
-
#line
|
569
|
+
#line 200 "parser.rl"
|
569
570
|
{
|
570
571
|
if (json->allow_nan) {
|
571
572
|
*result = CNaN;
|
@@ -575,19 +576,19 @@ tr18:
|
|
575
576
|
}
|
576
577
|
goto st21;
|
577
578
|
tr22:
|
578
|
-
#line
|
579
|
+
#line 194 "parser.rl"
|
579
580
|
{
|
580
581
|
*result = Qfalse;
|
581
582
|
}
|
582
583
|
goto st21;
|
583
584
|
tr25:
|
584
|
-
#line
|
585
|
+
#line 191 "parser.rl"
|
585
586
|
{
|
586
587
|
*result = Qnil;
|
587
588
|
}
|
588
589
|
goto st21;
|
589
590
|
tr28:
|
590
|
-
#line
|
591
|
+
#line 197 "parser.rl"
|
591
592
|
{
|
592
593
|
*result = Qtrue;
|
593
594
|
}
|
@@ -596,9 +597,9 @@ st21:
|
|
596
597
|
if ( ++p == pe )
|
597
598
|
goto _test_eof21;
|
598
599
|
case 21:
|
599
|
-
#line
|
600
|
+
#line 253 "parser.rl"
|
600
601
|
{ p--; {p++; cs = 21; goto _out;} }
|
601
|
-
#line
|
602
|
+
#line 603 "parser.c"
|
602
603
|
goto st0;
|
603
604
|
st2:
|
604
605
|
if ( ++p == pe )
|
@@ -759,7 +760,7 @@ case 20:
|
|
759
760
|
_out: {}
|
760
761
|
}
|
761
762
|
|
762
|
-
#line
|
763
|
+
#line 274 "parser.rl"
|
763
764
|
|
764
765
|
if (cs >= JSON_value_first_final) {
|
765
766
|
return p;
|
@@ -769,7 +770,7 @@ case 20:
|
|
769
770
|
}
|
770
771
|
|
771
772
|
|
772
|
-
#line
|
773
|
+
#line 774 "parser.c"
|
773
774
|
static const int JSON_integer_start = 1;
|
774
775
|
static const int JSON_integer_first_final = 3;
|
775
776
|
static const int JSON_integer_error = 0;
|
@@ -777,7 +778,7 @@ static const int JSON_integer_error = 0;
|
|
777
778
|
static const int JSON_integer_en_main = 1;
|
778
779
|
|
779
780
|
|
780
|
-
#line
|
781
|
+
#line 290 "parser.rl"
|
781
782
|
|
782
783
|
|
783
784
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -785,15 +786,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
785
786
|
int cs = EVIL;
|
786
787
|
|
787
788
|
|
788
|
-
#line
|
789
|
+
#line 790 "parser.c"
|
789
790
|
{
|
790
791
|
cs = JSON_integer_start;
|
791
792
|
}
|
792
793
|
|
793
|
-
#line
|
794
|
+
#line 297 "parser.rl"
|
794
795
|
json->memo = p;
|
795
796
|
|
796
|
-
#line
|
797
|
+
#line 798 "parser.c"
|
797
798
|
{
|
798
799
|
if ( p == pe )
|
799
800
|
goto _test_eof;
|
@@ -827,14 +828,14 @@ case 3:
|
|
827
828
|
goto st0;
|
828
829
|
goto tr4;
|
829
830
|
tr4:
|
830
|
-
#line
|
831
|
+
#line 287 "parser.rl"
|
831
832
|
{ p--; {p++; cs = 4; goto _out;} }
|
832
833
|
goto st4;
|
833
834
|
st4:
|
834
835
|
if ( ++p == pe )
|
835
836
|
goto _test_eof4;
|
836
837
|
case 4:
|
837
|
-
#line
|
838
|
+
#line 839 "parser.c"
|
838
839
|
goto st0;
|
839
840
|
st5:
|
840
841
|
if ( ++p == pe )
|
@@ -853,11 +854,14 @@ case 5:
|
|
853
854
|
_out: {}
|
854
855
|
}
|
855
856
|
|
856
|
-
#line
|
857
|
+
#line 299 "parser.rl"
|
857
858
|
|
858
859
|
if (cs >= JSON_integer_first_final) {
|
859
860
|
long len = p - json->memo;
|
860
|
-
|
861
|
+
fbuffer_clear(json->fbuffer);
|
862
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
863
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
864
|
+
*result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
|
861
865
|
return p + 1;
|
862
866
|
} else {
|
863
867
|
return NULL;
|
@@ -865,7 +869,7 @@ case 5:
|
|
865
869
|
}
|
866
870
|
|
867
871
|
|
868
|
-
#line
|
872
|
+
#line 873 "parser.c"
|
869
873
|
static const int JSON_float_start = 1;
|
870
874
|
static const int JSON_float_first_final = 8;
|
871
875
|
static const int JSON_float_error = 0;
|
@@ -873,7 +877,7 @@ static const int JSON_float_error = 0;
|
|
873
877
|
static const int JSON_float_en_main = 1;
|
874
878
|
|
875
879
|
|
876
|
-
#line
|
880
|
+
#line 324 "parser.rl"
|
877
881
|
|
878
882
|
|
879
883
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -881,15 +885,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
881
885
|
int cs = EVIL;
|
882
886
|
|
883
887
|
|
884
|
-
#line
|
888
|
+
#line 889 "parser.c"
|
885
889
|
{
|
886
890
|
cs = JSON_float_start;
|
887
891
|
}
|
888
892
|
|
889
|
-
#line
|
893
|
+
#line 331 "parser.rl"
|
890
894
|
json->memo = p;
|
891
895
|
|
892
|
-
#line
|
896
|
+
#line 897 "parser.c"
|
893
897
|
{
|
894
898
|
if ( p == pe )
|
895
899
|
goto _test_eof;
|
@@ -947,14 +951,14 @@ case 8:
|
|
947
951
|
goto st0;
|
948
952
|
goto tr9;
|
949
953
|
tr9:
|
950
|
-
#line
|
954
|
+
#line 318 "parser.rl"
|
951
955
|
{ p--; {p++; cs = 9; goto _out;} }
|
952
956
|
goto st9;
|
953
957
|
st9:
|
954
958
|
if ( ++p == pe )
|
955
959
|
goto _test_eof9;
|
956
960
|
case 9:
|
957
|
-
#line
|
961
|
+
#line 962 "parser.c"
|
958
962
|
goto st0;
|
959
963
|
st5:
|
960
964
|
if ( ++p == pe )
|
@@ -1015,11 +1019,14 @@ case 7:
|
|
1015
1019
|
_out: {}
|
1016
1020
|
}
|
1017
1021
|
|
1018
|
-
#line
|
1022
|
+
#line 333 "parser.rl"
|
1019
1023
|
|
1020
1024
|
if (cs >= JSON_float_first_final) {
|
1021
1025
|
long len = p - json->memo;
|
1022
|
-
|
1026
|
+
fbuffer_clear(json->fbuffer);
|
1027
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
1028
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
1029
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
1023
1030
|
return p + 1;
|
1024
1031
|
} else {
|
1025
1032
|
return NULL;
|
@@ -1028,7 +1035,7 @@ case 7:
|
|
1028
1035
|
|
1029
1036
|
|
1030
1037
|
|
1031
|
-
#line
|
1038
|
+
#line 1039 "parser.c"
|
1032
1039
|
static const int JSON_array_start = 1;
|
1033
1040
|
static const int JSON_array_first_final = 17;
|
1034
1041
|
static const int JSON_array_error = 0;
|
@@ -1036,7 +1043,7 @@ static const int JSON_array_error = 0;
|
|
1036
1043
|
static const int JSON_array_en_main = 1;
|
1037
1044
|
|
1038
1045
|
|
1039
|
-
#line
|
1046
|
+
#line 376 "parser.rl"
|
1040
1047
|
|
1041
1048
|
|
1042
1049
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1050,14 +1057,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
1050
1057
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1051
1058
|
|
1052
1059
|
|
1053
|
-
#line
|
1060
|
+
#line 1061 "parser.c"
|
1054
1061
|
{
|
1055
1062
|
cs = JSON_array_start;
|
1056
1063
|
}
|
1057
1064
|
|
1058
|
-
#line
|
1065
|
+
#line 389 "parser.rl"
|
1059
1066
|
|
1060
|
-
#line
|
1067
|
+
#line 1068 "parser.c"
|
1061
1068
|
{
|
1062
1069
|
if ( p == pe )
|
1063
1070
|
goto _test_eof;
|
@@ -1096,7 +1103,7 @@ case 2:
|
|
1096
1103
|
goto st2;
|
1097
1104
|
goto st0;
|
1098
1105
|
tr2:
|
1099
|
-
#line
|
1106
|
+
#line 353 "parser.rl"
|
1100
1107
|
{
|
1101
1108
|
VALUE v = Qnil;
|
1102
1109
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -1116,7 +1123,7 @@ st3:
|
|
1116
1123
|
if ( ++p == pe )
|
1117
1124
|
goto _test_eof3;
|
1118
1125
|
case 3:
|
1119
|
-
#line
|
1126
|
+
#line 1127 "parser.c"
|
1120
1127
|
switch( (*p) ) {
|
1121
1128
|
case 13: goto st3;
|
1122
1129
|
case 32: goto st3;
|
@@ -1216,14 +1223,14 @@ case 12:
|
|
1216
1223
|
goto st3;
|
1217
1224
|
goto st12;
|
1218
1225
|
tr4:
|
1219
|
-
#line
|
1226
|
+
#line 368 "parser.rl"
|
1220
1227
|
{ p--; {p++; cs = 17; goto _out;} }
|
1221
1228
|
goto st17;
|
1222
1229
|
st17:
|
1223
1230
|
if ( ++p == pe )
|
1224
1231
|
goto _test_eof17;
|
1225
1232
|
case 17:
|
1226
|
-
#line
|
1233
|
+
#line 1234 "parser.c"
|
1227
1234
|
goto st0;
|
1228
1235
|
st13:
|
1229
1236
|
if ( ++p == pe )
|
@@ -1279,7 +1286,7 @@ case 16:
|
|
1279
1286
|
_out: {}
|
1280
1287
|
}
|
1281
1288
|
|
1282
|
-
#line
|
1289
|
+
#line 390 "parser.rl"
|
1283
1290
|
|
1284
1291
|
if(cs >= JSON_array_first_final) {
|
1285
1292
|
return p + 1;
|
@@ -1360,7 +1367,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1360
1367
|
}
|
1361
1368
|
|
1362
1369
|
|
1363
|
-
#line
|
1370
|
+
#line 1371 "parser.c"
|
1364
1371
|
static const int JSON_string_start = 1;
|
1365
1372
|
static const int JSON_string_first_final = 8;
|
1366
1373
|
static const int JSON_string_error = 0;
|
@@ -1368,7 +1375,7 @@ static const int JSON_string_error = 0;
|
|
1368
1375
|
static const int JSON_string_en_main = 1;
|
1369
1376
|
|
1370
1377
|
|
1371
|
-
#line
|
1378
|
+
#line 489 "parser.rl"
|
1372
1379
|
|
1373
1380
|
|
1374
1381
|
static int
|
@@ -1390,15 +1397,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1390
1397
|
|
1391
1398
|
*result = rb_str_buf_new(0);
|
1392
1399
|
|
1393
|
-
#line
|
1400
|
+
#line 1401 "parser.c"
|
1394
1401
|
{
|
1395
1402
|
cs = JSON_string_start;
|
1396
1403
|
}
|
1397
1404
|
|
1398
|
-
#line
|
1405
|
+
#line 510 "parser.rl"
|
1399
1406
|
json->memo = p;
|
1400
1407
|
|
1401
|
-
#line
|
1408
|
+
#line 1409 "parser.c"
|
1402
1409
|
{
|
1403
1410
|
if ( p == pe )
|
1404
1411
|
goto _test_eof;
|
@@ -1423,7 +1430,7 @@ case 2:
|
|
1423
1430
|
goto st0;
|
1424
1431
|
goto st2;
|
1425
1432
|
tr2:
|
1426
|
-
#line
|
1433
|
+
#line 475 "parser.rl"
|
1427
1434
|
{
|
1428
1435
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
1429
1436
|
if (NIL_P(*result)) {
|
@@ -1434,14 +1441,14 @@ tr2:
|
|
1434
1441
|
{p = (( p + 1))-1;}
|
1435
1442
|
}
|
1436
1443
|
}
|
1437
|
-
#line
|
1444
|
+
#line 486 "parser.rl"
|
1438
1445
|
{ p--; {p++; cs = 8; goto _out;} }
|
1439
1446
|
goto st8;
|
1440
1447
|
st8:
|
1441
1448
|
if ( ++p == pe )
|
1442
1449
|
goto _test_eof8;
|
1443
1450
|
case 8:
|
1444
|
-
#line
|
1451
|
+
#line 1452 "parser.c"
|
1445
1452
|
goto st0;
|
1446
1453
|
st3:
|
1447
1454
|
if ( ++p == pe )
|
@@ -1517,7 +1524,7 @@ case 7:
|
|
1517
1524
|
_out: {}
|
1518
1525
|
}
|
1519
1526
|
|
1520
|
-
#line
|
1527
|
+
#line 512 "parser.rl"
|
1521
1528
|
|
1522
1529
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1523
1530
|
VALUE klass;
|
@@ -1628,9 +1635,6 @@ static VALUE convert_encoding(VALUE source)
|
|
1628
1635
|
* defaults to true.
|
1629
1636
|
* * *object_class*: Defaults to Hash
|
1630
1637
|
* * *array_class*: Defaults to Array
|
1631
|
-
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
|
1632
|
-
* parsing single JSON values instead of documents is possible.
|
1633
|
-
*
|
1634
1638
|
*/
|
1635
1639
|
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
1636
1640
|
{
|
@@ -1717,6 +1721,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1717
1721
|
json->object_class = Qnil;
|
1718
1722
|
json->array_class = Qnil;
|
1719
1723
|
}
|
1724
|
+
source = rb_convert_type(source, T_STRING, "String", "to_str");
|
1720
1725
|
if (!json->quirks_mode) {
|
1721
1726
|
source = convert_encoding(StringValue(source));
|
1722
1727
|
}
|
@@ -1728,7 +1733,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1728
1733
|
}
|
1729
1734
|
|
1730
1735
|
|
1731
|
-
#line
|
1736
|
+
#line 1737 "parser.c"
|
1732
1737
|
static const int JSON_start = 1;
|
1733
1738
|
static const int JSON_first_final = 10;
|
1734
1739
|
static const int JSON_error = 0;
|
@@ -1736,7 +1741,7 @@ static const int JSON_error = 0;
|
|
1736
1741
|
static const int JSON_en_main = 1;
|
1737
1742
|
|
1738
1743
|
|
1739
|
-
#line
|
1744
|
+
#line 744 "parser.rl"
|
1740
1745
|
|
1741
1746
|
|
1742
1747
|
static VALUE cParser_parse_strict(VALUE self)
|
@@ -1747,16 +1752,16 @@ static VALUE cParser_parse_strict(VALUE self)
|
|
1747
1752
|
GET_PARSER;
|
1748
1753
|
|
1749
1754
|
|
1750
|
-
#line
|
1755
|
+
#line 1756 "parser.c"
|
1751
1756
|
{
|
1752
1757
|
cs = JSON_start;
|
1753
1758
|
}
|
1754
1759
|
|
1755
|
-
#line
|
1760
|
+
#line 754 "parser.rl"
|
1756
1761
|
p = json->source;
|
1757
1762
|
pe = p + json->len;
|
1758
1763
|
|
1759
|
-
#line
|
1764
|
+
#line 1765 "parser.c"
|
1760
1765
|
{
|
1761
1766
|
if ( p == pe )
|
1762
1767
|
goto _test_eof;
|
@@ -1812,7 +1817,7 @@ case 5:
|
|
1812
1817
|
goto st1;
|
1813
1818
|
goto st5;
|
1814
1819
|
tr3:
|
1815
|
-
#line
|
1820
|
+
#line 733 "parser.rl"
|
1816
1821
|
{
|
1817
1822
|
char *np;
|
1818
1823
|
json->current_nesting = 1;
|
@@ -1821,7 +1826,7 @@ tr3:
|
|
1821
1826
|
}
|
1822
1827
|
goto st10;
|
1823
1828
|
tr4:
|
1824
|
-
#line
|
1829
|
+
#line 726 "parser.rl"
|
1825
1830
|
{
|
1826
1831
|
char *np;
|
1827
1832
|
json->current_nesting = 1;
|
@@ -1833,7 +1838,7 @@ st10:
|
|
1833
1838
|
if ( ++p == pe )
|
1834
1839
|
goto _test_eof10;
|
1835
1840
|
case 10:
|
1836
|
-
#line
|
1841
|
+
#line 1842 "parser.c"
|
1837
1842
|
switch( (*p) ) {
|
1838
1843
|
case 13: goto st10;
|
1839
1844
|
case 32: goto st10;
|
@@ -1890,7 +1895,7 @@ case 9:
|
|
1890
1895
|
_out: {}
|
1891
1896
|
}
|
1892
1897
|
|
1893
|
-
#line
|
1898
|
+
#line 757 "parser.rl"
|
1894
1899
|
|
1895
1900
|
if (cs >= JSON_first_final && p == pe) {
|
1896
1901
|
return result;
|
@@ -1902,7 +1907,7 @@ case 9:
|
|
1902
1907
|
|
1903
1908
|
|
1904
1909
|
|
1905
|
-
#line
|
1910
|
+
#line 1911 "parser.c"
|
1906
1911
|
static const int JSON_quirks_mode_start = 1;
|
1907
1912
|
static const int JSON_quirks_mode_first_final = 10;
|
1908
1913
|
static const int JSON_quirks_mode_error = 0;
|
@@ -1910,7 +1915,7 @@ static const int JSON_quirks_mode_error = 0;
|
|
1910
1915
|
static const int JSON_quirks_mode_en_main = 1;
|
1911
1916
|
|
1912
1917
|
|
1913
|
-
#line
|
1918
|
+
#line 782 "parser.rl"
|
1914
1919
|
|
1915
1920
|
|
1916
1921
|
static VALUE cParser_parse_quirks_mode(VALUE self)
|
@@ -1921,16 +1926,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
|
|
1921
1926
|
GET_PARSER;
|
1922
1927
|
|
1923
1928
|
|
1924
|
-
#line
|
1929
|
+
#line 1930 "parser.c"
|
1925
1930
|
{
|
1926
1931
|
cs = JSON_quirks_mode_start;
|
1927
1932
|
}
|
1928
1933
|
|
1929
|
-
#line
|
1934
|
+
#line 792 "parser.rl"
|
1930
1935
|
p = json->source;
|
1931
1936
|
pe = p + json->len;
|
1932
1937
|
|
1933
|
-
#line
|
1938
|
+
#line 1939 "parser.c"
|
1934
1939
|
{
|
1935
1940
|
if ( p == pe )
|
1936
1941
|
goto _test_eof;
|
@@ -1964,7 +1969,7 @@ st0:
|
|
1964
1969
|
cs = 0;
|
1965
1970
|
goto _out;
|
1966
1971
|
tr2:
|
1967
|
-
#line
|
1972
|
+
#line 774 "parser.rl"
|
1968
1973
|
{
|
1969
1974
|
char *np = JSON_parse_value(json, p, pe, &result);
|
1970
1975
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
@@ -1974,7 +1979,7 @@ st10:
|
|
1974
1979
|
if ( ++p == pe )
|
1975
1980
|
goto _test_eof10;
|
1976
1981
|
case 10:
|
1977
|
-
#line
|
1982
|
+
#line 1983 "parser.c"
|
1978
1983
|
switch( (*p) ) {
|
1979
1984
|
case 13: goto st10;
|
1980
1985
|
case 32: goto st10;
|
@@ -2063,7 +2068,7 @@ case 9:
|
|
2063
2068
|
_out: {}
|
2064
2069
|
}
|
2065
2070
|
|
2066
|
-
#line
|
2071
|
+
#line 795 "parser.rl"
|
2067
2072
|
|
2068
2073
|
if (cs >= JSON_quirks_mode_first_final && p == pe) {
|
2069
2074
|
return result;
|
@@ -2095,13 +2100,13 @@ static JSON_Parser *JSON_allocate()
|
|
2095
2100
|
{
|
2096
2101
|
JSON_Parser *json = ALLOC(JSON_Parser);
|
2097
2102
|
MEMZERO(json, JSON_Parser, 1);
|
2098
|
-
json->dwrapped_parser =
|
2099
|
-
json->Vsource =
|
2100
|
-
json->create_id =
|
2101
|
-
json->object_class =
|
2102
|
-
json->array_class =
|
2103
|
-
json->match_string =
|
2104
|
-
|
2103
|
+
json->dwrapped_parser = Qfalse;
|
2104
|
+
json->Vsource = Qfalse;
|
2105
|
+
json->create_id = Qfalse;
|
2106
|
+
json->object_class = Qfalse;
|
2107
|
+
json->array_class = Qfalse;
|
2108
|
+
json->match_string = Qfalse;
|
2109
|
+
json->fbuffer = fbuffer_alloc(0);
|
2105
2110
|
return json;
|
2106
2111
|
}
|
2107
2112
|
|
@@ -2116,6 +2121,7 @@ static void JSON_mark(JSON_Parser *json)
|
|
2116
2121
|
|
2117
2122
|
static void JSON_free(JSON_Parser *json)
|
2118
2123
|
{
|
2124
|
+
fbuffer_free(json->fbuffer);
|
2119
2125
|
ruby_xfree(json);
|
2120
2126
|
}
|
2121
2127
|
|