json 1.8.3 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{CHANGES → CHANGES.md} +241 -90
- data/Gemfile +10 -6
- data/{COPYING-json-jruby → LICENSE} +5 -6
- data/{README.rdoc → README.md} +201 -134
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +264 -104
- data/ext/json/ext/generator/generator.h +12 -4
- data/ext/json/ext/parser/extconf.rb +28 -0
- data/ext/json/ext/parser/parser.c +425 -462
- data/ext/json/ext/parser/parser.h +5 -5
- data/ext/json/ext/parser/parser.rl +181 -181
- data/ext/json/extconf.rb +1 -1
- data/json.gemspec +0 -0
- data/lib/json.rb +550 -29
- data/lib/json/add/bigdecimal.rb +3 -2
- data/lib/json/add/complex.rb +4 -4
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +3 -3
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +3 -3
- data/lib/json/add/regexp.rb +3 -3
- data/lib/json/add/set.rb +29 -0
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -1
- data/lib/json/add/time.rb +1 -1
- data/lib/json/common.rb +381 -162
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure.rb +2 -8
- data/lib/json/pure/generator.rb +83 -126
- data/lib/json/pure/parser.rb +62 -84
- data/lib/json/version.rb +2 -1
- data/tests/fixtures/fail29.json +1 -0
- data/tests/fixtures/fail30.json +1 -0
- data/tests/fixtures/fail31.json +1 -0
- data/tests/fixtures/fail32.json +1 -0
- data/tests/fixtures/obsolete_fail1.json +1 -0
- data/tests/{test_json_addition.rb → json_addition_test.rb} +28 -25
- data/tests/json_common_interface_test.rb +169 -0
- data/tests/json_encoding_test.rb +107 -0
- data/tests/json_ext_parser_test.rb +15 -0
- data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +13 -8
- data/tests/{test_json_generate.rb → json_generator_test.rb} +109 -47
- data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
- data/tests/json_parser_test.rb +497 -0
- data/tests/json_string_matching_test.rb +38 -0
- data/tests/lib/core_assertions.rb +763 -0
- data/tests/lib/envutil.rb +365 -0
- data/tests/lib/find_executable.rb +22 -0
- data/tests/lib/helper.rb +4 -0
- data/tests/ractor_test.rb +30 -0
- data/tests/test_helper.rb +17 -0
- metadata +48 -76
- data/.gitignore +0 -16
- data/.travis.yml +0 -26
- data/COPYING +0 -58
- data/GPL +0 -340
- data/README-json-jruby.markdown +0 -33
- data/Rakefile +0 -412
- data/TODO +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -167
- data/java/src/json/ext/Generator.java +0 -444
- data/java/src/json/ext/GeneratorMethods.java +0 -232
- data/java/src/json/ext/GeneratorService.java +0 -43
- data/java/src/json/ext/GeneratorState.java +0 -543
- data/java/src/json/ext/OptionsReader.java +0 -114
- data/java/src/json/ext/Parser.java +0 -2645
- data/java/src/json/ext/Parser.rl +0 -969
- data/java/src/json/ext/ParserService.java +0 -35
- data/java/src/json/ext/RuntimeInfo.java +0 -121
- data/java/src/json/ext/StringDecoder.java +0 -167
- data/java/src/json/ext/StringEncoder.java +0 -106
- data/java/src/json/ext/Utils.java +0 -89
- data/json-java.gemspec +0 -23
- data/json_pure.gemspec +0 -40
- data/tests/fixtures/fail1.json +0 -1
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -553
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
- data/tools/fuzz.rb +0 -139
- data/tools/server.rb +0 -62
@@ -1,7 +1,6 @@
|
|
1
1
|
#ifndef _GENERATOR_H_
|
2
2
|
#define _GENERATOR_H_
|
3
3
|
|
4
|
-
#include <string.h>
|
5
4
|
#include <math.h>
|
6
5
|
#include <ctype.h>
|
7
6
|
|
@@ -50,8 +49,8 @@ static const UTF32 halfMask = 0x3FFUL;
|
|
50
49
|
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
51
50
|
static void unicode_escape(char *buf, UTF16 character);
|
52
51
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
53
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
|
54
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
|
52
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash);
|
53
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash);
|
55
54
|
static char *fstrndup(const char *ptr, unsigned long len);
|
56
55
|
|
57
56
|
/* ruby api and some helpers */
|
@@ -73,7 +72,7 @@ typedef struct JSON_Generator_StateStruct {
|
|
73
72
|
long max_nesting;
|
74
73
|
char allow_nan;
|
75
74
|
char ascii_only;
|
76
|
-
char
|
75
|
+
char escape_slash;
|
77
76
|
long depth;
|
78
77
|
long buffer_initial_length;
|
79
78
|
} JSON_Generator_State;
|
@@ -99,8 +98,12 @@ typedef struct JSON_Generator_StateStruct {
|
|
99
98
|
|
100
99
|
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
101
100
|
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
101
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
102
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
103
|
+
#else
|
102
104
|
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
103
105
|
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
106
|
+
#endif
|
104
107
|
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
105
108
|
static VALUE mString_included_s(VALUE self, VALUE modul);
|
106
109
|
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
@@ -122,6 +125,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
122
125
|
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
123
126
|
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
124
127
|
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
128
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
129
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
130
|
+
#endif
|
125
131
|
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
126
132
|
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
127
133
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
@@ -145,6 +151,8 @@ static VALUE cState_allow_nan_p(VALUE self);
|
|
145
151
|
static VALUE cState_ascii_only_p(VALUE self);
|
146
152
|
static VALUE cState_depth(VALUE self);
|
147
153
|
static VALUE cState_depth_set(VALUE self, VALUE depth);
|
154
|
+
static VALUE cState_escape_slash(VALUE self);
|
155
|
+
static VALUE cState_escape_slash_set(VALUE self, VALUE depth);
|
148
156
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
149
157
|
#ifndef ZALLOC
|
150
158
|
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
@@ -1,3 +1,31 @@
|
|
1
|
+
# frozen_string_literal: false
|
1
2
|
require 'mkmf'
|
2
3
|
|
4
|
+
have_func("rb_enc_raise", "ruby.h")
|
5
|
+
|
6
|
+
# checking if String#-@ (str_uminus) dedupes... '
|
7
|
+
begin
|
8
|
+
a = -(%w(t e s t).join)
|
9
|
+
b = -(%w(t e s t).join)
|
10
|
+
if a.equal?(b)
|
11
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
|
12
|
+
else
|
13
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
14
|
+
end
|
15
|
+
rescue NoMethodError
|
16
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
17
|
+
end
|
18
|
+
|
19
|
+
# checking if String#-@ (str_uminus) directly interns frozen strings... '
|
20
|
+
begin
|
21
|
+
s = rand.to_s.freeze
|
22
|
+
if (-s).equal?(s) && (-s.dup).equal?(s)
|
23
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
|
24
|
+
else
|
25
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
26
|
+
end
|
27
|
+
rescue NoMethodError
|
28
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
29
|
+
end
|
30
|
+
|
3
31
|
create_makefile 'json/ext/parser'
|
@@ -1,11 +1,33 @@
|
|
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"
|
5
5
|
|
6
|
+
#if defined HAVE_RUBY_ENCODING_H
|
7
|
+
# define EXC_ENCODING rb_utf8_encoding(),
|
8
|
+
# ifndef HAVE_RB_ENC_RAISE
|
9
|
+
static void
|
10
|
+
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
11
|
+
{
|
12
|
+
va_list args;
|
13
|
+
VALUE mesg;
|
14
|
+
|
15
|
+
va_start(args, fmt);
|
16
|
+
mesg = rb_enc_vsprintf(enc, fmt, args);
|
17
|
+
va_end(args);
|
18
|
+
|
19
|
+
rb_exc_raise(rb_exc_new3(exc, mesg));
|
20
|
+
}
|
21
|
+
# define rb_enc_raise enc_raise
|
22
|
+
# endif
|
23
|
+
#else
|
24
|
+
# define EXC_ENCODING /* nothing */
|
25
|
+
# define rb_enc_raise rb_raise
|
26
|
+
#endif
|
27
|
+
|
6
28
|
/* unicode */
|
7
29
|
|
8
|
-
static const char digit_values[256] = {
|
30
|
+
static const signed char digit_values[256] = {
|
9
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
10
32
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
11
33
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
@@ -24,7 +46,7 @@ static const char digit_values[256] = {
|
|
24
46
|
|
25
47
|
static UTF32 unescape_unicode(const unsigned char *p)
|
26
48
|
{
|
27
|
-
char b;
|
49
|
+
signed char b;
|
28
50
|
UTF32 result = 0;
|
29
51
|
b = digit_values[p[0]];
|
30
52
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
@@ -67,28 +89,21 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
67
89
|
return len;
|
68
90
|
}
|
69
91
|
|
70
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
71
|
-
static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
|
72
|
-
CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
|
73
|
-
static ID i_encoding, i_encode;
|
74
|
-
#else
|
75
|
-
static ID i_iconv;
|
76
|
-
#endif
|
77
|
-
|
78
92
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
79
93
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
80
94
|
|
81
95
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
82
|
-
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
83
|
-
i_object_class, i_array_class,
|
84
|
-
i_match_string, i_aset, i_aref,
|
96
|
+
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
97
|
+
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
98
|
+
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
99
|
+
i_leftshift, i_new, i_try_convert, i_freeze, i_uminus;
|
85
100
|
|
86
101
|
|
87
|
-
#line
|
102
|
+
#line 126 "parser.rl"
|
88
103
|
|
89
104
|
|
90
105
|
|
91
|
-
#line
|
106
|
+
#line 108 "parser.c"
|
92
107
|
enum {JSON_object_start = 1};
|
93
108
|
enum {JSON_object_first_final = 27};
|
94
109
|
enum {JSON_object_error = 0};
|
@@ -96,30 +111,30 @@ enum {JSON_object_error = 0};
|
|
96
111
|
enum {JSON_object_en_main = 1};
|
97
112
|
|
98
113
|
|
99
|
-
#line
|
114
|
+
#line 168 "parser.rl"
|
100
115
|
|
101
116
|
|
102
|
-
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
117
|
+
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
103
118
|
{
|
104
119
|
int cs = EVIL;
|
105
120
|
VALUE last_name = Qnil;
|
106
121
|
VALUE object_class = json->object_class;
|
107
122
|
|
108
|
-
if (json->max_nesting &&
|
109
|
-
rb_raise(eNestingError, "nesting of %d is too deep",
|
123
|
+
if (json->max_nesting && current_nesting > json->max_nesting) {
|
124
|
+
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
110
125
|
}
|
111
126
|
|
112
127
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
113
128
|
|
114
129
|
|
115
|
-
#line
|
130
|
+
#line 132 "parser.c"
|
116
131
|
{
|
117
132
|
cs = JSON_object_start;
|
118
133
|
}
|
119
134
|
|
120
|
-
#line
|
135
|
+
#line 183 "parser.rl"
|
121
136
|
|
122
|
-
#line
|
137
|
+
#line 139 "parser.c"
|
123
138
|
{
|
124
139
|
if ( p == pe )
|
125
140
|
goto _test_eof;
|
@@ -147,7 +162,7 @@ case 2:
|
|
147
162
|
goto st2;
|
148
163
|
goto st0;
|
149
164
|
tr2:
|
150
|
-
#line
|
165
|
+
#line 150 "parser.rl"
|
151
166
|
{
|
152
167
|
char *np;
|
153
168
|
json->parsing_name = 1;
|
@@ -160,7 +175,7 @@ st3:
|
|
160
175
|
if ( ++p == pe )
|
161
176
|
goto _test_eof3;
|
162
177
|
case 3:
|
163
|
-
#line
|
178
|
+
#line 180 "parser.c"
|
164
179
|
switch( (*p) ) {
|
165
180
|
case 13: goto st3;
|
166
181
|
case 32: goto st3;
|
@@ -227,14 +242,15 @@ case 8:
|
|
227
242
|
goto st8;
|
228
243
|
goto st0;
|
229
244
|
tr11:
|
230
|
-
#line
|
245
|
+
#line 134 "parser.rl"
|
231
246
|
{
|
232
247
|
VALUE v = Qnil;
|
233
|
-
char *np = JSON_parse_value(json, p, pe, &v);
|
248
|
+
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
234
249
|
if (np == NULL) {
|
235
250
|
p--; {p++; cs = 9; goto _out;}
|
236
251
|
} else {
|
237
252
|
if (NIL_P(json->object_class)) {
|
253
|
+
OBJ_FREEZE(last_name);
|
238
254
|
rb_hash_aset(*result, last_name, v);
|
239
255
|
} else {
|
240
256
|
rb_funcall(*result, i_aset, 2, last_name, v);
|
@@ -247,7 +263,7 @@ st9:
|
|
247
263
|
if ( ++p == pe )
|
248
264
|
goto _test_eof9;
|
249
265
|
case 9:
|
250
|
-
#line
|
266
|
+
#line 268 "parser.c"
|
251
267
|
switch( (*p) ) {
|
252
268
|
case 13: goto st9;
|
253
269
|
case 32: goto st9;
|
@@ -336,14 +352,14 @@ case 18:
|
|
336
352
|
goto st9;
|
337
353
|
goto st18;
|
338
354
|
tr4:
|
339
|
-
#line
|
355
|
+
#line 158 "parser.rl"
|
340
356
|
{ p--; {p++; cs = 27; goto _out;} }
|
341
357
|
goto st27;
|
342
358
|
st27:
|
343
359
|
if ( ++p == pe )
|
344
360
|
goto _test_eof27;
|
345
361
|
case 27:
|
346
|
-
#line
|
362
|
+
#line 364 "parser.c"
|
347
363
|
goto st0;
|
348
364
|
st19:
|
349
365
|
if ( ++p == pe )
|
@@ -441,7 +457,7 @@ case 26:
|
|
441
457
|
_out: {}
|
442
458
|
}
|
443
459
|
|
444
|
-
#line
|
460
|
+
#line 184 "parser.rl"
|
445
461
|
|
446
462
|
if (cs >= JSON_object_first_final) {
|
447
463
|
if (json->create_additions) {
|
@@ -466,281 +482,358 @@ case 26:
|
|
466
482
|
|
467
483
|
|
468
484
|
|
469
|
-
#line
|
485
|
+
#line 487 "parser.c"
|
470
486
|
enum {JSON_value_start = 1};
|
471
|
-
enum {JSON_value_first_final =
|
487
|
+
enum {JSON_value_first_final = 29};
|
472
488
|
enum {JSON_value_error = 0};
|
473
489
|
|
474
490
|
enum {JSON_value_en_main = 1};
|
475
491
|
|
476
492
|
|
477
|
-
#line
|
493
|
+
#line 284 "parser.rl"
|
478
494
|
|
479
495
|
|
480
|
-
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
496
|
+
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
481
497
|
{
|
482
498
|
int cs = EVIL;
|
483
499
|
|
484
500
|
|
485
|
-
#line
|
501
|
+
#line 503 "parser.c"
|
486
502
|
{
|
487
503
|
cs = JSON_value_start;
|
488
504
|
}
|
489
505
|
|
490
|
-
#line
|
506
|
+
#line 291 "parser.rl"
|
491
507
|
|
492
|
-
#line
|
508
|
+
#line 510 "parser.c"
|
493
509
|
{
|
494
510
|
if ( p == pe )
|
495
511
|
goto _test_eof;
|
496
512
|
switch ( cs )
|
497
513
|
{
|
514
|
+
st1:
|
515
|
+
if ( ++p == pe )
|
516
|
+
goto _test_eof1;
|
498
517
|
case 1:
|
499
518
|
switch( (*p) ) {
|
500
|
-
case
|
501
|
-
case
|
502
|
-
case
|
503
|
-
case
|
504
|
-
case
|
505
|
-
case
|
506
|
-
case
|
507
|
-
case
|
508
|
-
case
|
519
|
+
case 13: goto st1;
|
520
|
+
case 32: goto st1;
|
521
|
+
case 34: goto tr2;
|
522
|
+
case 45: goto tr3;
|
523
|
+
case 47: goto st6;
|
524
|
+
case 73: goto st10;
|
525
|
+
case 78: goto st17;
|
526
|
+
case 91: goto tr7;
|
527
|
+
case 102: goto st19;
|
528
|
+
case 110: goto st23;
|
529
|
+
case 116: goto st26;
|
530
|
+
case 123: goto tr11;
|
509
531
|
}
|
510
|
-
if (
|
511
|
-
|
532
|
+
if ( (*p) > 10 ) {
|
533
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
534
|
+
goto tr3;
|
535
|
+
} else if ( (*p) >= 9 )
|
536
|
+
goto st1;
|
512
537
|
goto st0;
|
513
538
|
st0:
|
514
539
|
cs = 0;
|
515
540
|
goto _out;
|
516
|
-
|
517
|
-
#line
|
541
|
+
tr2:
|
542
|
+
#line 236 "parser.rl"
|
518
543
|
{
|
519
544
|
char *np = JSON_parse_string(json, p, pe, result);
|
520
|
-
if (np == NULL) { p--; {p++; cs =
|
545
|
+
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
521
546
|
}
|
522
|
-
goto
|
523
|
-
|
524
|
-
#line
|
547
|
+
goto st29;
|
548
|
+
tr3:
|
549
|
+
#line 241 "parser.rl"
|
525
550
|
{
|
526
551
|
char *np;
|
527
|
-
if(pe > p +
|
552
|
+
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
528
553
|
if (json->allow_nan) {
|
529
554
|
*result = CMinusInfinity;
|
530
555
|
{p = (( p + 10))-1;}
|
531
|
-
p--; {p++; cs =
|
556
|
+
p--; {p++; cs = 29; goto _out;}
|
532
557
|
} else {
|
533
|
-
|
558
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
534
559
|
}
|
535
560
|
}
|
536
561
|
np = JSON_parse_float(json, p, pe, result);
|
537
562
|
if (np != NULL) {p = (( np))-1;}
|
538
563
|
np = JSON_parse_integer(json, p, pe, result);
|
539
564
|
if (np != NULL) {p = (( np))-1;}
|
540
|
-
p--; {p++; cs =
|
565
|
+
p--; {p++; cs = 29; goto _out;}
|
541
566
|
}
|
542
|
-
goto
|
543
|
-
|
544
|
-
#line
|
567
|
+
goto st29;
|
568
|
+
tr7:
|
569
|
+
#line 259 "parser.rl"
|
545
570
|
{
|
546
571
|
char *np;
|
547
|
-
json
|
548
|
-
np =
|
549
|
-
json->current_nesting--;
|
550
|
-
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
572
|
+
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
573
|
+
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
551
574
|
}
|
552
|
-
goto
|
553
|
-
|
554
|
-
#line
|
575
|
+
goto st29;
|
576
|
+
tr11:
|
577
|
+
#line 265 "parser.rl"
|
555
578
|
{
|
556
579
|
char *np;
|
557
|
-
json
|
558
|
-
np =
|
559
|
-
json->current_nesting--;
|
560
|
-
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
580
|
+
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
581
|
+
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
561
582
|
}
|
562
|
-
goto
|
563
|
-
|
564
|
-
#line
|
583
|
+
goto st29;
|
584
|
+
tr25:
|
585
|
+
#line 229 "parser.rl"
|
565
586
|
{
|
566
587
|
if (json->allow_nan) {
|
567
588
|
*result = CInfinity;
|
568
589
|
} else {
|
569
|
-
|
590
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
|
570
591
|
}
|
571
592
|
}
|
572
|
-
goto
|
573
|
-
|
574
|
-
#line
|
593
|
+
goto st29;
|
594
|
+
tr27:
|
595
|
+
#line 222 "parser.rl"
|
575
596
|
{
|
576
597
|
if (json->allow_nan) {
|
577
598
|
*result = CNaN;
|
578
599
|
} else {
|
579
|
-
|
600
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
|
580
601
|
}
|
581
602
|
}
|
582
|
-
goto
|
583
|
-
|
584
|
-
#line
|
603
|
+
goto st29;
|
604
|
+
tr31:
|
605
|
+
#line 216 "parser.rl"
|
585
606
|
{
|
586
607
|
*result = Qfalse;
|
587
608
|
}
|
588
|
-
goto
|
589
|
-
|
590
|
-
#line
|
609
|
+
goto st29;
|
610
|
+
tr34:
|
611
|
+
#line 213 "parser.rl"
|
591
612
|
{
|
592
613
|
*result = Qnil;
|
593
614
|
}
|
594
|
-
goto
|
595
|
-
|
596
|
-
#line
|
615
|
+
goto st29;
|
616
|
+
tr37:
|
617
|
+
#line 219 "parser.rl"
|
597
618
|
{
|
598
619
|
*result = Qtrue;
|
599
620
|
}
|
600
|
-
goto
|
601
|
-
|
621
|
+
goto st29;
|
622
|
+
st29:
|
602
623
|
if ( ++p == pe )
|
603
|
-
goto
|
604
|
-
case
|
605
|
-
#line
|
606
|
-
{ p--; {p++; cs =
|
607
|
-
#line
|
624
|
+
goto _test_eof29;
|
625
|
+
case 29:
|
626
|
+
#line 271 "parser.rl"
|
627
|
+
{ p--; {p++; cs = 29; goto _out;} }
|
628
|
+
#line 630 "parser.c"
|
629
|
+
switch( (*p) ) {
|
630
|
+
case 13: goto st29;
|
631
|
+
case 32: goto st29;
|
632
|
+
case 47: goto st2;
|
633
|
+
}
|
634
|
+
if ( 9 <= (*p) && (*p) <= 10 )
|
635
|
+
goto st29;
|
608
636
|
goto st0;
|
609
637
|
st2:
|
610
638
|
if ( ++p == pe )
|
611
639
|
goto _test_eof2;
|
612
640
|
case 2:
|
613
|
-
|
614
|
-
goto st3;
|
641
|
+
switch( (*p) ) {
|
642
|
+
case 42: goto st3;
|
643
|
+
case 47: goto st5;
|
644
|
+
}
|
615
645
|
goto st0;
|
616
646
|
st3:
|
617
647
|
if ( ++p == pe )
|
618
648
|
goto _test_eof3;
|
619
649
|
case 3:
|
620
|
-
if ( (*p) ==
|
650
|
+
if ( (*p) == 42 )
|
621
651
|
goto st4;
|
622
|
-
goto
|
652
|
+
goto st3;
|
623
653
|
st4:
|
624
654
|
if ( ++p == pe )
|
625
655
|
goto _test_eof4;
|
626
656
|
case 4:
|
627
|
-
|
628
|
-
goto
|
629
|
-
|
657
|
+
switch( (*p) ) {
|
658
|
+
case 42: goto st4;
|
659
|
+
case 47: goto st29;
|
660
|
+
}
|
661
|
+
goto st3;
|
630
662
|
st5:
|
631
663
|
if ( ++p == pe )
|
632
664
|
goto _test_eof5;
|
633
665
|
case 5:
|
634
|
-
if ( (*p) ==
|
635
|
-
goto
|
636
|
-
goto
|
666
|
+
if ( (*p) == 10 )
|
667
|
+
goto st29;
|
668
|
+
goto st5;
|
637
669
|
st6:
|
638
670
|
if ( ++p == pe )
|
639
671
|
goto _test_eof6;
|
640
672
|
case 6:
|
641
|
-
|
642
|
-
goto st7;
|
673
|
+
switch( (*p) ) {
|
674
|
+
case 42: goto st7;
|
675
|
+
case 47: goto st9;
|
676
|
+
}
|
643
677
|
goto st0;
|
644
678
|
st7:
|
645
679
|
if ( ++p == pe )
|
646
680
|
goto _test_eof7;
|
647
681
|
case 7:
|
648
|
-
if ( (*p) ==
|
682
|
+
if ( (*p) == 42 )
|
649
683
|
goto st8;
|
650
|
-
goto
|
684
|
+
goto st7;
|
651
685
|
st8:
|
652
686
|
if ( ++p == pe )
|
653
687
|
goto _test_eof8;
|
654
688
|
case 8:
|
655
|
-
|
656
|
-
goto
|
657
|
-
|
689
|
+
switch( (*p) ) {
|
690
|
+
case 42: goto st8;
|
691
|
+
case 47: goto st1;
|
692
|
+
}
|
693
|
+
goto st7;
|
658
694
|
st9:
|
659
695
|
if ( ++p == pe )
|
660
696
|
goto _test_eof9;
|
661
697
|
case 9:
|
662
|
-
if ( (*p) ==
|
663
|
-
goto
|
664
|
-
goto
|
698
|
+
if ( (*p) == 10 )
|
699
|
+
goto st1;
|
700
|
+
goto st9;
|
665
701
|
st10:
|
666
702
|
if ( ++p == pe )
|
667
703
|
goto _test_eof10;
|
668
704
|
case 10:
|
669
|
-
if ( (*p) ==
|
670
|
-
goto
|
705
|
+
if ( (*p) == 110 )
|
706
|
+
goto st11;
|
671
707
|
goto st0;
|
672
708
|
st11:
|
673
709
|
if ( ++p == pe )
|
674
710
|
goto _test_eof11;
|
675
711
|
case 11:
|
676
|
-
if ( (*p) ==
|
712
|
+
if ( (*p) == 102 )
|
677
713
|
goto st12;
|
678
714
|
goto st0;
|
679
715
|
st12:
|
680
716
|
if ( ++p == pe )
|
681
717
|
goto _test_eof12;
|
682
718
|
case 12:
|
683
|
-
if ( (*p) ==
|
719
|
+
if ( (*p) == 105 )
|
684
720
|
goto st13;
|
685
721
|
goto st0;
|
686
722
|
st13:
|
687
723
|
if ( ++p == pe )
|
688
724
|
goto _test_eof13;
|
689
725
|
case 13:
|
690
|
-
if ( (*p) ==
|
726
|
+
if ( (*p) == 110 )
|
691
727
|
goto st14;
|
692
728
|
goto st0;
|
693
729
|
st14:
|
694
730
|
if ( ++p == pe )
|
695
731
|
goto _test_eof14;
|
696
732
|
case 14:
|
697
|
-
if ( (*p) ==
|
698
|
-
goto
|
733
|
+
if ( (*p) == 105 )
|
734
|
+
goto st15;
|
699
735
|
goto st0;
|
700
736
|
st15:
|
701
737
|
if ( ++p == pe )
|
702
738
|
goto _test_eof15;
|
703
739
|
case 15:
|
704
|
-
if ( (*p) ==
|
740
|
+
if ( (*p) == 116 )
|
705
741
|
goto st16;
|
706
742
|
goto st0;
|
707
743
|
st16:
|
708
744
|
if ( ++p == pe )
|
709
745
|
goto _test_eof16;
|
710
746
|
case 16:
|
711
|
-
if ( (*p) ==
|
712
|
-
goto
|
747
|
+
if ( (*p) == 121 )
|
748
|
+
goto tr25;
|
713
749
|
goto st0;
|
714
750
|
st17:
|
715
751
|
if ( ++p == pe )
|
716
752
|
goto _test_eof17;
|
717
753
|
case 17:
|
718
|
-
if ( (*p) ==
|
719
|
-
goto
|
754
|
+
if ( (*p) == 97 )
|
755
|
+
goto st18;
|
720
756
|
goto st0;
|
721
757
|
st18:
|
722
758
|
if ( ++p == pe )
|
723
759
|
goto _test_eof18;
|
724
760
|
case 18:
|
725
|
-
if ( (*p) ==
|
726
|
-
goto
|
761
|
+
if ( (*p) == 78 )
|
762
|
+
goto tr27;
|
727
763
|
goto st0;
|
728
764
|
st19:
|
729
765
|
if ( ++p == pe )
|
730
766
|
goto _test_eof19;
|
731
767
|
case 19:
|
732
|
-
if ( (*p) ==
|
768
|
+
if ( (*p) == 97 )
|
733
769
|
goto st20;
|
734
770
|
goto st0;
|
735
771
|
st20:
|
736
772
|
if ( ++p == pe )
|
737
773
|
goto _test_eof20;
|
738
774
|
case 20:
|
775
|
+
if ( (*p) == 108 )
|
776
|
+
goto st21;
|
777
|
+
goto st0;
|
778
|
+
st21:
|
779
|
+
if ( ++p == pe )
|
780
|
+
goto _test_eof21;
|
781
|
+
case 21:
|
782
|
+
if ( (*p) == 115 )
|
783
|
+
goto st22;
|
784
|
+
goto st0;
|
785
|
+
st22:
|
786
|
+
if ( ++p == pe )
|
787
|
+
goto _test_eof22;
|
788
|
+
case 22:
|
739
789
|
if ( (*p) == 101 )
|
740
|
-
goto
|
790
|
+
goto tr31;
|
791
|
+
goto st0;
|
792
|
+
st23:
|
793
|
+
if ( ++p == pe )
|
794
|
+
goto _test_eof23;
|
795
|
+
case 23:
|
796
|
+
if ( (*p) == 117 )
|
797
|
+
goto st24;
|
798
|
+
goto st0;
|
799
|
+
st24:
|
800
|
+
if ( ++p == pe )
|
801
|
+
goto _test_eof24;
|
802
|
+
case 24:
|
803
|
+
if ( (*p) == 108 )
|
804
|
+
goto st25;
|
805
|
+
goto st0;
|
806
|
+
st25:
|
807
|
+
if ( ++p == pe )
|
808
|
+
goto _test_eof25;
|
809
|
+
case 25:
|
810
|
+
if ( (*p) == 108 )
|
811
|
+
goto tr34;
|
812
|
+
goto st0;
|
813
|
+
st26:
|
814
|
+
if ( ++p == pe )
|
815
|
+
goto _test_eof26;
|
816
|
+
case 26:
|
817
|
+
if ( (*p) == 114 )
|
818
|
+
goto st27;
|
819
|
+
goto st0;
|
820
|
+
st27:
|
821
|
+
if ( ++p == pe )
|
822
|
+
goto _test_eof27;
|
823
|
+
case 27:
|
824
|
+
if ( (*p) == 117 )
|
825
|
+
goto st28;
|
826
|
+
goto st0;
|
827
|
+
st28:
|
828
|
+
if ( ++p == pe )
|
829
|
+
goto _test_eof28;
|
830
|
+
case 28:
|
831
|
+
if ( (*p) == 101 )
|
832
|
+
goto tr37;
|
741
833
|
goto st0;
|
742
834
|
}
|
743
|
-
|
835
|
+
_test_eof1: cs = 1; goto _test_eof;
|
836
|
+
_test_eof29: cs = 29; goto _test_eof;
|
744
837
|
_test_eof2: cs = 2; goto _test_eof;
|
745
838
|
_test_eof3: cs = 3; goto _test_eof;
|
746
839
|
_test_eof4: cs = 4; goto _test_eof;
|
@@ -760,12 +853,24 @@ case 20:
|
|
760
853
|
_test_eof18: cs = 18; goto _test_eof;
|
761
854
|
_test_eof19: cs = 19; goto _test_eof;
|
762
855
|
_test_eof20: cs = 20; goto _test_eof;
|
856
|
+
_test_eof21: cs = 21; goto _test_eof;
|
857
|
+
_test_eof22: cs = 22; goto _test_eof;
|
858
|
+
_test_eof23: cs = 23; goto _test_eof;
|
859
|
+
_test_eof24: cs = 24; goto _test_eof;
|
860
|
+
_test_eof25: cs = 25; goto _test_eof;
|
861
|
+
_test_eof26: cs = 26; goto _test_eof;
|
862
|
+
_test_eof27: cs = 27; goto _test_eof;
|
863
|
+
_test_eof28: cs = 28; goto _test_eof;
|
763
864
|
|
764
865
|
_test_eof: {}
|
765
866
|
_out: {}
|
766
867
|
}
|
767
868
|
|
768
|
-
#line
|
869
|
+
#line 292 "parser.rl"
|
870
|
+
|
871
|
+
if (json->freeze) {
|
872
|
+
OBJ_FREEZE(*result);
|
873
|
+
}
|
769
874
|
|
770
875
|
if (cs >= JSON_value_first_final) {
|
771
876
|
return p;
|
@@ -775,7 +880,7 @@ case 20:
|
|
775
880
|
}
|
776
881
|
|
777
882
|
|
778
|
-
#line
|
883
|
+
#line 885 "parser.c"
|
779
884
|
enum {JSON_integer_start = 1};
|
780
885
|
enum {JSON_integer_first_final = 3};
|
781
886
|
enum {JSON_integer_error = 0};
|
@@ -783,7 +888,7 @@ enum {JSON_integer_error = 0};
|
|
783
888
|
enum {JSON_integer_en_main = 1};
|
784
889
|
|
785
890
|
|
786
|
-
#line
|
891
|
+
#line 312 "parser.rl"
|
787
892
|
|
788
893
|
|
789
894
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -791,15 +896,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
791
896
|
int cs = EVIL;
|
792
897
|
|
793
898
|
|
794
|
-
#line
|
899
|
+
#line 901 "parser.c"
|
795
900
|
{
|
796
901
|
cs = JSON_integer_start;
|
797
902
|
}
|
798
903
|
|
799
|
-
#line
|
904
|
+
#line 319 "parser.rl"
|
800
905
|
json->memo = p;
|
801
906
|
|
802
|
-
#line
|
907
|
+
#line 909 "parser.c"
|
803
908
|
{
|
804
909
|
if ( p == pe )
|
805
910
|
goto _test_eof;
|
@@ -833,14 +938,14 @@ case 3:
|
|
833
938
|
goto st0;
|
834
939
|
goto tr4;
|
835
940
|
tr4:
|
836
|
-
#line
|
941
|
+
#line 309 "parser.rl"
|
837
942
|
{ p--; {p++; cs = 4; goto _out;} }
|
838
943
|
goto st4;
|
839
944
|
st4:
|
840
945
|
if ( ++p == pe )
|
841
946
|
goto _test_eof4;
|
842
947
|
case 4:
|
843
|
-
#line
|
948
|
+
#line 950 "parser.c"
|
844
949
|
goto st0;
|
845
950
|
st5:
|
846
951
|
if ( ++p == pe )
|
@@ -859,7 +964,7 @@ case 5:
|
|
859
964
|
_out: {}
|
860
965
|
}
|
861
966
|
|
862
|
-
#line
|
967
|
+
#line 321 "parser.rl"
|
863
968
|
|
864
969
|
if (cs >= JSON_integer_first_final) {
|
865
970
|
long len = p - json->memo;
|
@@ -874,7 +979,7 @@ case 5:
|
|
874
979
|
}
|
875
980
|
|
876
981
|
|
877
|
-
#line
|
982
|
+
#line 984 "parser.c"
|
878
983
|
enum {JSON_float_start = 1};
|
879
984
|
enum {JSON_float_first_final = 8};
|
880
985
|
enum {JSON_float_error = 0};
|
@@ -882,7 +987,7 @@ enum {JSON_float_error = 0};
|
|
882
987
|
enum {JSON_float_en_main = 1};
|
883
988
|
|
884
989
|
|
885
|
-
#line
|
990
|
+
#line 346 "parser.rl"
|
886
991
|
|
887
992
|
|
888
993
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -890,15 +995,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
890
995
|
int cs = EVIL;
|
891
996
|
|
892
997
|
|
893
|
-
#line
|
998
|
+
#line 1013 "parser.c"
|
894
999
|
{
|
895
1000
|
cs = JSON_float_start;
|
896
1001
|
}
|
897
1002
|
|
898
|
-
#line
|
1003
|
+
#line 366 "parser.rl"
|
899
1004
|
json->memo = p;
|
900
1005
|
|
901
|
-
#line
|
1006
|
+
#line 1021 "parser.c"
|
902
1007
|
{
|
903
1008
|
if ( p == pe )
|
904
1009
|
goto _test_eof;
|
@@ -956,14 +1061,14 @@ case 8:
|
|
956
1061
|
goto st0;
|
957
1062
|
goto tr9;
|
958
1063
|
tr9:
|
959
|
-
#line
|
1064
|
+
#line 340 "parser.rl"
|
960
1065
|
{ p--; {p++; cs = 9; goto _out;} }
|
961
1066
|
goto st9;
|
962
1067
|
st9:
|
963
1068
|
if ( ++p == pe )
|
964
1069
|
goto _test_eof9;
|
965
1070
|
case 9:
|
966
|
-
#line
|
1071
|
+
#line 1086 "parser.c"
|
967
1072
|
goto st0;
|
968
1073
|
st5:
|
969
1074
|
if ( ++p == pe )
|
@@ -1024,14 +1129,49 @@ case 7:
|
|
1024
1129
|
_out: {}
|
1025
1130
|
}
|
1026
1131
|
|
1027
|
-
#line
|
1132
|
+
#line 368 "parser.rl"
|
1028
1133
|
|
1029
1134
|
if (cs >= JSON_float_first_final) {
|
1135
|
+
VALUE mod = Qnil;
|
1136
|
+
ID method_id = 0;
|
1137
|
+
if (rb_respond_to(json->decimal_class, i_try_convert)) {
|
1138
|
+
mod = json->decimal_class;
|
1139
|
+
method_id = i_try_convert;
|
1140
|
+
} else if (rb_respond_to(json->decimal_class, i_new)) {
|
1141
|
+
mod = json->decimal_class;
|
1142
|
+
method_id = i_new;
|
1143
|
+
} else if (RB_TYPE_P(json->decimal_class, T_CLASS)) {
|
1144
|
+
VALUE name = rb_class_name(json->decimal_class);
|
1145
|
+
const char *name_cstr = RSTRING_PTR(name);
|
1146
|
+
const char *last_colon = strrchr(name_cstr, ':');
|
1147
|
+
if (last_colon) {
|
1148
|
+
const char *mod_path_end = last_colon - 1;
|
1149
|
+
VALUE mod_path = rb_str_substr(name, 0, mod_path_end - name_cstr);
|
1150
|
+
mod = rb_path_to_class(mod_path);
|
1151
|
+
|
1152
|
+
const char *method_name_beg = last_colon + 1;
|
1153
|
+
long before_len = method_name_beg - name_cstr;
|
1154
|
+
long len = RSTRING_LEN(name) - before_len;
|
1155
|
+
VALUE method_name = rb_str_substr(name, before_len, len);
|
1156
|
+
method_id = SYM2ID(rb_str_intern(method_name));
|
1157
|
+
} else {
|
1158
|
+
mod = rb_mKernel;
|
1159
|
+
method_id = SYM2ID(rb_str_intern(name));
|
1160
|
+
}
|
1161
|
+
}
|
1162
|
+
|
1030
1163
|
long len = p - json->memo;
|
1031
1164
|
fbuffer_clear(json->fbuffer);
|
1032
1165
|
fbuffer_append(json->fbuffer, json->memo, len);
|
1033
1166
|
fbuffer_append_char(json->fbuffer, '\0');
|
1034
|
-
|
1167
|
+
|
1168
|
+
if (method_id) {
|
1169
|
+
VALUE text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
1170
|
+
*result = rb_funcallv(mod, method_id, 1, &text);
|
1171
|
+
} else {
|
1172
|
+
*result = DBL2NUM(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
1173
|
+
}
|
1174
|
+
|
1035
1175
|
return p + 1;
|
1036
1176
|
} else {
|
1037
1177
|
return NULL;
|
@@ -1040,7 +1180,7 @@ case 7:
|
|
1040
1180
|
|
1041
1181
|
|
1042
1182
|
|
1043
|
-
#line
|
1183
|
+
#line 1173 "parser.c"
|
1044
1184
|
enum {JSON_array_start = 1};
|
1045
1185
|
enum {JSON_array_first_final = 17};
|
1046
1186
|
enum {JSON_array_error = 0};
|
@@ -1048,28 +1188,28 @@ enum {JSON_array_error = 0};
|
|
1048
1188
|
enum {JSON_array_en_main = 1};
|
1049
1189
|
|
1050
1190
|
|
1051
|
-
#line
|
1191
|
+
#line 421 "parser.rl"
|
1052
1192
|
|
1053
1193
|
|
1054
|
-
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
1194
|
+
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
1055
1195
|
{
|
1056
1196
|
int cs = EVIL;
|
1057
1197
|
VALUE array_class = json->array_class;
|
1058
1198
|
|
1059
|
-
if (json->max_nesting &&
|
1060
|
-
rb_raise(eNestingError, "nesting of %d is too deep",
|
1199
|
+
if (json->max_nesting && current_nesting > json->max_nesting) {
|
1200
|
+
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
1061
1201
|
}
|
1062
1202
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1063
1203
|
|
1064
1204
|
|
1065
|
-
#line
|
1205
|
+
#line 1195 "parser.c"
|
1066
1206
|
{
|
1067
1207
|
cs = JSON_array_start;
|
1068
1208
|
}
|
1069
1209
|
|
1070
|
-
#line
|
1210
|
+
#line 434 "parser.rl"
|
1071
1211
|
|
1072
|
-
#line
|
1212
|
+
#line 1202 "parser.c"
|
1073
1213
|
{
|
1074
1214
|
if ( p == pe )
|
1075
1215
|
goto _test_eof;
|
@@ -1108,10 +1248,10 @@ case 2:
|
|
1108
1248
|
goto st2;
|
1109
1249
|
goto st0;
|
1110
1250
|
tr2:
|
1111
|
-
#line
|
1251
|
+
#line 398 "parser.rl"
|
1112
1252
|
{
|
1113
1253
|
VALUE v = Qnil;
|
1114
|
-
char *np = JSON_parse_value(json, p, pe, &v);
|
1254
|
+
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
1115
1255
|
if (np == NULL) {
|
1116
1256
|
p--; {p++; cs = 3; goto _out;}
|
1117
1257
|
} else {
|
@@ -1128,7 +1268,7 @@ st3:
|
|
1128
1268
|
if ( ++p == pe )
|
1129
1269
|
goto _test_eof3;
|
1130
1270
|
case 3:
|
1131
|
-
#line
|
1271
|
+
#line 1261 "parser.c"
|
1132
1272
|
switch( (*p) ) {
|
1133
1273
|
case 13: goto st3;
|
1134
1274
|
case 32: goto st3;
|
@@ -1228,14 +1368,14 @@ case 12:
|
|
1228
1368
|
goto st3;
|
1229
1369
|
goto st12;
|
1230
1370
|
tr4:
|
1231
|
-
#line
|
1371
|
+
#line 413 "parser.rl"
|
1232
1372
|
{ p--; {p++; cs = 17; goto _out;} }
|
1233
1373
|
goto st17;
|
1234
1374
|
st17:
|
1235
1375
|
if ( ++p == pe )
|
1236
1376
|
goto _test_eof17;
|
1237
1377
|
case 17:
|
1238
|
-
#line
|
1378
|
+
#line 1368 "parser.c"
|
1239
1379
|
goto st0;
|
1240
1380
|
st13:
|
1241
1381
|
if ( ++p == pe )
|
@@ -1291,12 +1431,12 @@ case 16:
|
|
1291
1431
|
_out: {}
|
1292
1432
|
}
|
1293
1433
|
|
1294
|
-
#line
|
1434
|
+
#line 435 "parser.rl"
|
1295
1435
|
|
1296
1436
|
if(cs >= JSON_array_first_final) {
|
1297
1437
|
return p + 1;
|
1298
1438
|
} else {
|
1299
|
-
|
1439
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
1300
1440
|
return NULL;
|
1301
1441
|
}
|
1302
1442
|
}
|
@@ -1336,13 +1476,21 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1336
1476
|
break;
|
1337
1477
|
case 'u':
|
1338
1478
|
if (pe > stringEnd - 4) {
|
1339
|
-
|
1479
|
+
rb_enc_raise(
|
1480
|
+
EXC_ENCODING eParserError,
|
1481
|
+
"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
|
1482
|
+
);
|
1340
1483
|
} else {
|
1341
1484
|
UTF32 ch = unescape_unicode((unsigned char *) ++pe);
|
1342
1485
|
pe += 3;
|
1343
1486
|
if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
|
1344
1487
|
pe++;
|
1345
|
-
if (pe > stringEnd - 6)
|
1488
|
+
if (pe > stringEnd - 6) {
|
1489
|
+
rb_enc_raise(
|
1490
|
+
EXC_ENCODING eParserError,
|
1491
|
+
"%u: incomplete surrogate pair at '%s'", __LINE__, p
|
1492
|
+
);
|
1493
|
+
}
|
1346
1494
|
if (pe[0] == '\\' && pe[1] == 'u') {
|
1347
1495
|
UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
|
1348
1496
|
ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
|
@@ -1372,7 +1520,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1372
1520
|
}
|
1373
1521
|
|
1374
1522
|
|
1375
|
-
#line
|
1523
|
+
#line 1513 "parser.c"
|
1376
1524
|
enum {JSON_string_start = 1};
|
1377
1525
|
enum {JSON_string_first_final = 8};
|
1378
1526
|
enum {JSON_string_error = 0};
|
@@ -1380,7 +1528,7 @@ enum {JSON_string_error = 0};
|
|
1380
1528
|
enum {JSON_string_en_main = 1};
|
1381
1529
|
|
1382
1530
|
|
1383
|
-
#line
|
1531
|
+
#line 542 "parser.rl"
|
1384
1532
|
|
1385
1533
|
|
1386
1534
|
static int
|
@@ -1402,15 +1550,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1402
1550
|
|
1403
1551
|
*result = rb_str_buf_new(0);
|
1404
1552
|
|
1405
|
-
#line
|
1553
|
+
#line 1543 "parser.c"
|
1406
1554
|
{
|
1407
1555
|
cs = JSON_string_start;
|
1408
1556
|
}
|
1409
1557
|
|
1410
|
-
#line
|
1558
|
+
#line 563 "parser.rl"
|
1411
1559
|
json->memo = p;
|
1412
1560
|
|
1413
|
-
#line
|
1561
|
+
#line 1551 "parser.c"
|
1414
1562
|
{
|
1415
1563
|
if ( p == pe )
|
1416
1564
|
goto _test_eof;
|
@@ -1431,11 +1579,11 @@ case 2:
|
|
1431
1579
|
case 34: goto tr2;
|
1432
1580
|
case 92: goto st3;
|
1433
1581
|
}
|
1434
|
-
if ( 0 <= (*p) && (*p) <= 31 )
|
1582
|
+
if ( 0 <= (signed char)(*p) && (*p) <= 31 )
|
1435
1583
|
goto st0;
|
1436
1584
|
goto st2;
|
1437
1585
|
tr2:
|
1438
|
-
#line
|
1586
|
+
#line 528 "parser.rl"
|
1439
1587
|
{
|
1440
1588
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
1441
1589
|
if (NIL_P(*result)) {
|
@@ -1446,14 +1594,14 @@ tr2:
|
|
1446
1594
|
{p = (( p + 1))-1;}
|
1447
1595
|
}
|
1448
1596
|
}
|
1449
|
-
#line
|
1597
|
+
#line 539 "parser.rl"
|
1450
1598
|
{ p--; {p++; cs = 8; goto _out;} }
|
1451
1599
|
goto st8;
|
1452
1600
|
st8:
|
1453
1601
|
if ( ++p == pe )
|
1454
1602
|
goto _test_eof8;
|
1455
1603
|
case 8:
|
1456
|
-
#line
|
1604
|
+
#line 1594 "parser.c"
|
1457
1605
|
goto st0;
|
1458
1606
|
st3:
|
1459
1607
|
if ( ++p == pe )
|
@@ -1461,7 +1609,7 @@ st3:
|
|
1461
1609
|
case 3:
|
1462
1610
|
if ( (*p) == 117 )
|
1463
1611
|
goto st4;
|
1464
|
-
if ( 0 <= (*p) && (*p) <= 31 )
|
1612
|
+
if ( 0 <= (signed char)(*p) && (*p) <= 31 )
|
1465
1613
|
goto st0;
|
1466
1614
|
goto st2;
|
1467
1615
|
st4:
|
@@ -1529,7 +1677,7 @@ case 7:
|
|
1529
1677
|
_out: {}
|
1530
1678
|
}
|
1531
1679
|
|
1532
|
-
#line
|
1680
|
+
#line 565 "parser.rl"
|
1533
1681
|
|
1534
1682
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1535
1683
|
VALUE klass;
|
@@ -1544,6 +1692,23 @@ case 7:
|
|
1544
1692
|
|
1545
1693
|
if (json->symbolize_names && json->parsing_name) {
|
1546
1694
|
*result = rb_str_intern(*result);
|
1695
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
1696
|
+
# if STR_UMINUS_DEDUPE_FROZEN
|
1697
|
+
if (json->freeze) {
|
1698
|
+
// Starting from MRI 2.8 it is preferable to freeze the string
|
1699
|
+
// before deduplication so that it can be interned directly
|
1700
|
+
// otherwise it would be duplicated first which is wasteful.
|
1701
|
+
*result = rb_funcall(rb_str_freeze(*result), i_uminus, 0);
|
1702
|
+
}
|
1703
|
+
# elif STR_UMINUS_DEDUPE
|
1704
|
+
if (json->freeze) {
|
1705
|
+
// MRI 2.5 and older do not deduplicate strings that are already
|
1706
|
+
// frozen.
|
1707
|
+
*result = rb_funcall(*result, i_uminus, 0);
|
1708
|
+
}
|
1709
|
+
# else
|
1710
|
+
rb_str_resize(*result, RSTRING_LEN(*result));
|
1711
|
+
# endif
|
1547
1712
|
}
|
1548
1713
|
if (cs >= JSON_string_first_final) {
|
1549
1714
|
return p + 1;
|
@@ -1566,41 +1731,16 @@ case 7:
|
|
1566
1731
|
|
1567
1732
|
static VALUE convert_encoding(VALUE source)
|
1568
1733
|
{
|
1569
|
-
char *ptr = RSTRING_PTR(source);
|
1570
|
-
long len = RSTRING_LEN(source);
|
1571
|
-
if (len < 2) {
|
1572
|
-
rb_raise(eParserError, "A JSON text must at least contain two octets!");
|
1573
|
-
}
|
1574
1734
|
#ifdef HAVE_RUBY_ENCODING_H
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
|
1580
|
-
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
1581
|
-
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
|
1582
|
-
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
1583
|
-
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
|
1584
|
-
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
1585
|
-
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
|
1586
|
-
} else {
|
1587
|
-
source = rb_str_dup(source);
|
1588
|
-
FORCE_UTF8(source);
|
1589
|
-
}
|
1590
|
-
} else {
|
1591
|
-
source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
|
1592
|
-
}
|
1593
|
-
}
|
1594
|
-
#else
|
1595
|
-
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
|
1596
|
-
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
|
1597
|
-
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
1598
|
-
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
|
1599
|
-
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
1600
|
-
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
|
1601
|
-
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
1602
|
-
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
|
1735
|
+
rb_encoding *enc = rb_enc_get(source);
|
1736
|
+
if (enc == rb_ascii8bit_encoding()) {
|
1737
|
+
if (OBJ_FROZEN(source)) {
|
1738
|
+
source = rb_str_dup(source);
|
1603
1739
|
}
|
1740
|
+
FORCE_UTF8(source);
|
1741
|
+
} else {
|
1742
|
+
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
|
1743
|
+
}
|
1604
1744
|
#endif
|
1605
1745
|
return source;
|
1606
1746
|
}
|
@@ -1623,8 +1763,9 @@ static VALUE convert_encoding(VALUE source)
|
|
1623
1763
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
1624
1764
|
* false.
|
1625
1765
|
* * *symbolize_names*: If set to true, returns symbols for the names
|
1626
|
-
* (keys) in a JSON object. Otherwise strings are returned, which is
|
1627
|
-
* the default.
|
1766
|
+
* (keys) in a JSON object. Otherwise strings are returned, which is
|
1767
|
+
* also the default. It's not possible to use this option in
|
1768
|
+
* conjunction with the *create_additions* option.
|
1628
1769
|
* * *create_additions*: If set to false, the Parser doesn't create
|
1629
1770
|
* additions even if a matching class and create_id was found. This option
|
1630
1771
|
* defaults to false.
|
@@ -1639,12 +1780,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1639
1780
|
if (json->Vsource) {
|
1640
1781
|
rb_raise(rb_eTypeError, "already initialized instance");
|
1641
1782
|
}
|
1783
|
+
#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1784
|
+
rb_scan_args(argc, argv, "1:", &source, &opts);
|
1785
|
+
#else
|
1642
1786
|
rb_scan_args(argc, argv, "11", &source, &opts);
|
1787
|
+
#endif
|
1643
1788
|
if (!NIL_P(opts)) {
|
1789
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1644
1790
|
opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
|
1645
1791
|
if (NIL_P(opts)) {
|
1646
1792
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
1647
1793
|
} else {
|
1794
|
+
#endif
|
1648
1795
|
VALUE tmp = ID2SYM(i_max_nesting);
|
1649
1796
|
if (option_given_p(opts, tmp)) {
|
1650
1797
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
@@ -1669,12 +1816,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1669
1816
|
} else {
|
1670
1817
|
json->symbolize_names = 0;
|
1671
1818
|
}
|
1672
|
-
tmp = ID2SYM(
|
1819
|
+
tmp = ID2SYM(i_freeze);
|
1673
1820
|
if (option_given_p(opts, tmp)) {
|
1674
|
-
|
1675
|
-
json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
|
1821
|
+
json->freeze = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
|
1676
1822
|
} else {
|
1677
|
-
json->
|
1823
|
+
json->freeze = 0;
|
1678
1824
|
}
|
1679
1825
|
tmp = ID2SYM(i_create_additions);
|
1680
1826
|
if (option_given_p(opts, tmp)) {
|
@@ -1682,6 +1828,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1682
1828
|
} else {
|
1683
1829
|
json->create_additions = 0;
|
1684
1830
|
}
|
1831
|
+
if (json->symbolize_names && json->create_additions) {
|
1832
|
+
rb_raise(rb_eArgError,
|
1833
|
+
"options :symbolize_names and :create_additions cannot be "
|
1834
|
+
" used in conjunction");
|
1835
|
+
}
|
1685
1836
|
tmp = ID2SYM(i_create_id);
|
1686
1837
|
if (option_given_p(opts, tmp)) {
|
1687
1838
|
json->create_id = rb_hash_aref(opts, tmp);
|
@@ -1700,6 +1851,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1700
1851
|
} else {
|
1701
1852
|
json->array_class = Qnil;
|
1702
1853
|
}
|
1854
|
+
tmp = ID2SYM(i_decimal_class);
|
1855
|
+
if (option_given_p(opts, tmp)) {
|
1856
|
+
json->decimal_class = rb_hash_aref(opts, tmp);
|
1857
|
+
} else {
|
1858
|
+
json->decimal_class = Qnil;
|
1859
|
+
}
|
1703
1860
|
tmp = ID2SYM(i_match_string);
|
1704
1861
|
if (option_given_p(opts, tmp)) {
|
1705
1862
|
VALUE match_string = rb_hash_aref(opts, tmp);
|
@@ -1707,20 +1864,19 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1707
1864
|
} else {
|
1708
1865
|
json->match_string = Qnil;
|
1709
1866
|
}
|
1867
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1710
1868
|
}
|
1869
|
+
#endif
|
1711
1870
|
} else {
|
1712
1871
|
json->max_nesting = 100;
|
1713
1872
|
json->allow_nan = 0;
|
1714
|
-
json->create_additions =
|
1873
|
+
json->create_additions = 0;
|
1715
1874
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1716
1875
|
json->object_class = Qnil;
|
1717
1876
|
json->array_class = Qnil;
|
1877
|
+
json->decimal_class = Qnil;
|
1718
1878
|
}
|
1719
|
-
source =
|
1720
|
-
if (!json->quirks_mode) {
|
1721
|
-
source = convert_encoding(StringValue(source));
|
1722
|
-
}
|
1723
|
-
json->current_nesting = 0;
|
1879
|
+
source = convert_encoding(StringValue(source));
|
1724
1880
|
StringValue(source);
|
1725
1881
|
json->len = RSTRING_LEN(source);
|
1726
1882
|
json->source = RSTRING_PTR(source);;
|
@@ -1729,7 +1885,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1729
1885
|
}
|
1730
1886
|
|
1731
1887
|
|
1732
|
-
#line
|
1888
|
+
#line 1878 "parser.c"
|
1733
1889
|
enum {JSON_start = 1};
|
1734
1890
|
enum {JSON_first_final = 10};
|
1735
1891
|
enum {JSON_error = 0};
|
@@ -1737,201 +1893,33 @@ enum {JSON_error = 0};
|
|
1737
1893
|
enum {JSON_en_main = 1};
|
1738
1894
|
|
1739
1895
|
|
1740
|
-
#line
|
1896
|
+
#line 786 "parser.rl"
|
1741
1897
|
|
1742
1898
|
|
1743
|
-
|
1899
|
+
/*
|
1900
|
+
* call-seq: parse()
|
1901
|
+
*
|
1902
|
+
* Parses the current JSON text _source_ and returns the complete data
|
1903
|
+
* structure as a result.
|
1904
|
+
*/
|
1905
|
+
static VALUE cParser_parse(VALUE self)
|
1744
1906
|
{
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1907
|
+
char *p, *pe;
|
1908
|
+
int cs = EVIL;
|
1909
|
+
VALUE result = Qnil;
|
1910
|
+
GET_PARSER;
|
1749
1911
|
|
1750
1912
|
|
1751
|
-
#line
|
1913
|
+
#line 1903 "parser.c"
|
1752
1914
|
{
|
1753
1915
|
cs = JSON_start;
|
1754
1916
|
}
|
1755
1917
|
|
1756
|
-
#line
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
#line 1761 "parser.c"
|
1761
|
-
{
|
1762
|
-
if ( p == pe )
|
1763
|
-
goto _test_eof;
|
1764
|
-
switch ( cs )
|
1765
|
-
{
|
1766
|
-
st1:
|
1767
|
-
if ( ++p == pe )
|
1768
|
-
goto _test_eof1;
|
1769
|
-
case 1:
|
1770
|
-
switch( (*p) ) {
|
1771
|
-
case 13: goto st1;
|
1772
|
-
case 32: goto st1;
|
1773
|
-
case 47: goto st2;
|
1774
|
-
case 91: goto tr3;
|
1775
|
-
case 123: goto tr4;
|
1776
|
-
}
|
1777
|
-
if ( 9 <= (*p) && (*p) <= 10 )
|
1778
|
-
goto st1;
|
1779
|
-
goto st0;
|
1780
|
-
st0:
|
1781
|
-
cs = 0;
|
1782
|
-
goto _out;
|
1783
|
-
st2:
|
1784
|
-
if ( ++p == pe )
|
1785
|
-
goto _test_eof2;
|
1786
|
-
case 2:
|
1787
|
-
switch( (*p) ) {
|
1788
|
-
case 42: goto st3;
|
1789
|
-
case 47: goto st5;
|
1790
|
-
}
|
1791
|
-
goto st0;
|
1792
|
-
st3:
|
1793
|
-
if ( ++p == pe )
|
1794
|
-
goto _test_eof3;
|
1795
|
-
case 3:
|
1796
|
-
if ( (*p) == 42 )
|
1797
|
-
goto st4;
|
1798
|
-
goto st3;
|
1799
|
-
st4:
|
1800
|
-
if ( ++p == pe )
|
1801
|
-
goto _test_eof4;
|
1802
|
-
case 4:
|
1803
|
-
switch( (*p) ) {
|
1804
|
-
case 42: goto st4;
|
1805
|
-
case 47: goto st1;
|
1806
|
-
}
|
1807
|
-
goto st3;
|
1808
|
-
st5:
|
1809
|
-
if ( ++p == pe )
|
1810
|
-
goto _test_eof5;
|
1811
|
-
case 5:
|
1812
|
-
if ( (*p) == 10 )
|
1813
|
-
goto st1;
|
1814
|
-
goto st5;
|
1815
|
-
tr3:
|
1816
|
-
#line 729 "parser.rl"
|
1817
|
-
{
|
1818
|
-
char *np;
|
1819
|
-
json->current_nesting = 1;
|
1820
|
-
np = JSON_parse_array(json, p, pe, &result);
|
1821
|
-
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
1822
|
-
}
|
1823
|
-
goto st10;
|
1824
|
-
tr4:
|
1825
|
-
#line 722 "parser.rl"
|
1826
|
-
{
|
1827
|
-
char *np;
|
1828
|
-
json->current_nesting = 1;
|
1829
|
-
np = JSON_parse_object(json, p, pe, &result);
|
1830
|
-
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
1831
|
-
}
|
1832
|
-
goto st10;
|
1833
|
-
st10:
|
1834
|
-
if ( ++p == pe )
|
1835
|
-
goto _test_eof10;
|
1836
|
-
case 10:
|
1837
|
-
#line 1838 "parser.c"
|
1838
|
-
switch( (*p) ) {
|
1839
|
-
case 13: goto st10;
|
1840
|
-
case 32: goto st10;
|
1841
|
-
case 47: goto st6;
|
1842
|
-
}
|
1843
|
-
if ( 9 <= (*p) && (*p) <= 10 )
|
1844
|
-
goto st10;
|
1845
|
-
goto st0;
|
1846
|
-
st6:
|
1847
|
-
if ( ++p == pe )
|
1848
|
-
goto _test_eof6;
|
1849
|
-
case 6:
|
1850
|
-
switch( (*p) ) {
|
1851
|
-
case 42: goto st7;
|
1852
|
-
case 47: goto st9;
|
1853
|
-
}
|
1854
|
-
goto st0;
|
1855
|
-
st7:
|
1856
|
-
if ( ++p == pe )
|
1857
|
-
goto _test_eof7;
|
1858
|
-
case 7:
|
1859
|
-
if ( (*p) == 42 )
|
1860
|
-
goto st8;
|
1861
|
-
goto st7;
|
1862
|
-
st8:
|
1863
|
-
if ( ++p == pe )
|
1864
|
-
goto _test_eof8;
|
1865
|
-
case 8:
|
1866
|
-
switch( (*p) ) {
|
1867
|
-
case 42: goto st8;
|
1868
|
-
case 47: goto st10;
|
1869
|
-
}
|
1870
|
-
goto st7;
|
1871
|
-
st9:
|
1872
|
-
if ( ++p == pe )
|
1873
|
-
goto _test_eof9;
|
1874
|
-
case 9:
|
1875
|
-
if ( (*p) == 10 )
|
1876
|
-
goto st10;
|
1877
|
-
goto st9;
|
1878
|
-
}
|
1879
|
-
_test_eof1: cs = 1; goto _test_eof;
|
1880
|
-
_test_eof2: cs = 2; goto _test_eof;
|
1881
|
-
_test_eof3: cs = 3; goto _test_eof;
|
1882
|
-
_test_eof4: cs = 4; goto _test_eof;
|
1883
|
-
_test_eof5: cs = 5; goto _test_eof;
|
1884
|
-
_test_eof10: cs = 10; goto _test_eof;
|
1885
|
-
_test_eof6: cs = 6; goto _test_eof;
|
1886
|
-
_test_eof7: cs = 7; goto _test_eof;
|
1887
|
-
_test_eof8: cs = 8; goto _test_eof;
|
1888
|
-
_test_eof9: cs = 9; goto _test_eof;
|
1889
|
-
|
1890
|
-
_test_eof: {}
|
1891
|
-
_out: {}
|
1892
|
-
}
|
1893
|
-
|
1894
|
-
#line 753 "parser.rl"
|
1895
|
-
|
1896
|
-
if (cs >= JSON_first_final && p == pe) {
|
1897
|
-
return result;
|
1898
|
-
} else {
|
1899
|
-
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
1900
|
-
return Qnil;
|
1901
|
-
}
|
1902
|
-
}
|
1918
|
+
#line 802 "parser.rl"
|
1919
|
+
p = json->source;
|
1920
|
+
pe = p + json->len;
|
1903
1921
|
|
1904
|
-
|
1905
|
-
|
1906
|
-
#line 1907 "parser.c"
|
1907
|
-
enum {JSON_quirks_mode_start = 1};
|
1908
|
-
enum {JSON_quirks_mode_first_final = 10};
|
1909
|
-
enum {JSON_quirks_mode_error = 0};
|
1910
|
-
|
1911
|
-
enum {JSON_quirks_mode_en_main = 1};
|
1912
|
-
|
1913
|
-
|
1914
|
-
#line 778 "parser.rl"
|
1915
|
-
|
1916
|
-
|
1917
|
-
static VALUE cParser_parse_quirks_mode(VALUE self)
|
1918
|
-
{
|
1919
|
-
char *p, *pe;
|
1920
|
-
int cs = EVIL;
|
1921
|
-
VALUE result = Qnil;
|
1922
|
-
GET_PARSER;
|
1923
|
-
|
1924
|
-
|
1925
|
-
#line 1926 "parser.c"
|
1926
|
-
{
|
1927
|
-
cs = JSON_quirks_mode_start;
|
1928
|
-
}
|
1929
|
-
|
1930
|
-
#line 788 "parser.rl"
|
1931
|
-
p = json->source;
|
1932
|
-
pe = p + json->len;
|
1933
|
-
|
1934
|
-
#line 1935 "parser.c"
|
1922
|
+
#line 1912 "parser.c"
|
1935
1923
|
{
|
1936
1924
|
if ( p == pe )
|
1937
1925
|
goto _test_eof;
|
@@ -1965,9 +1953,9 @@ st0:
|
|
1965
1953
|
cs = 0;
|
1966
1954
|
goto _out;
|
1967
1955
|
tr2:
|
1968
|
-
#line
|
1956
|
+
#line 778 "parser.rl"
|
1969
1957
|
{
|
1970
|
-
char *np = JSON_parse_value(json, p, pe, &result);
|
1958
|
+
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
1971
1959
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
1972
1960
|
}
|
1973
1961
|
goto st10;
|
@@ -1975,7 +1963,7 @@ st10:
|
|
1975
1963
|
if ( ++p == pe )
|
1976
1964
|
goto _test_eof10;
|
1977
1965
|
case 10:
|
1978
|
-
#line
|
1966
|
+
#line 1956 "parser.c"
|
1979
1967
|
switch( (*p) ) {
|
1980
1968
|
case 13: goto st10;
|
1981
1969
|
case 32: goto st10;
|
@@ -2064,30 +2052,13 @@ case 9:
|
|
2064
2052
|
_out: {}
|
2065
2053
|
}
|
2066
2054
|
|
2067
|
-
#line
|
2068
|
-
|
2069
|
-
if (cs >= JSON_quirks_mode_first_final && p == pe) {
|
2070
|
-
return result;
|
2071
|
-
} else {
|
2072
|
-
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
2073
|
-
return Qnil;
|
2074
|
-
}
|
2075
|
-
}
|
2076
|
-
|
2077
|
-
/*
|
2078
|
-
* call-seq: parse()
|
2079
|
-
*
|
2080
|
-
* Parses the current JSON text _source_ and returns the complete data
|
2081
|
-
* structure as a result.
|
2082
|
-
*/
|
2083
|
-
static VALUE cParser_parse(VALUE self)
|
2084
|
-
{
|
2085
|
-
GET_PARSER;
|
2055
|
+
#line 805 "parser.rl"
|
2086
2056
|
|
2087
|
-
if (
|
2088
|
-
return
|
2057
|
+
if (cs >= JSON_first_final && p == pe) {
|
2058
|
+
return result;
|
2089
2059
|
} else {
|
2090
|
-
|
2060
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
2061
|
+
return Qnil;
|
2091
2062
|
}
|
2092
2063
|
}
|
2093
2064
|
|
@@ -2098,6 +2069,7 @@ static void JSON_mark(void *ptr)
|
|
2098
2069
|
rb_gc_mark_maybe(json->create_id);
|
2099
2070
|
rb_gc_mark_maybe(json->object_class);
|
2100
2071
|
rb_gc_mark_maybe(json->array_class);
|
2072
|
+
rb_gc_mark_maybe(json->decimal_class);
|
2101
2073
|
rb_gc_mark_maybe(json->match_string);
|
2102
2074
|
}
|
2103
2075
|
|
@@ -2145,35 +2117,34 @@ static VALUE cParser_source(VALUE self)
|
|
2145
2117
|
return rb_str_dup(json->Vsource);
|
2146
2118
|
}
|
2147
2119
|
|
2148
|
-
/*
|
2149
|
-
* call-seq: quirks_mode?()
|
2150
|
-
*
|
2151
|
-
* Returns a true, if this parser is in quirks_mode, false otherwise.
|
2152
|
-
*/
|
2153
|
-
static VALUE cParser_quirks_mode_p(VALUE self)
|
2154
|
-
{
|
2155
|
-
GET_PARSER;
|
2156
|
-
return json->quirks_mode ? Qtrue : Qfalse;
|
2157
|
-
}
|
2158
|
-
|
2159
|
-
|
2160
2120
|
void Init_parser(void)
|
2161
2121
|
{
|
2122
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
2123
|
+
rb_ext_ractor_safe(true);
|
2124
|
+
#endif
|
2125
|
+
|
2126
|
+
#undef rb_intern
|
2162
2127
|
rb_require("json/common");
|
2163
2128
|
mJSON = rb_define_module("JSON");
|
2164
2129
|
mExt = rb_define_module_under(mJSON, "Ext");
|
2165
2130
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
2166
2131
|
eParserError = rb_path2class("JSON::ParserError");
|
2167
2132
|
eNestingError = rb_path2class("JSON::NestingError");
|
2133
|
+
rb_gc_register_mark_object(eParserError);
|
2134
|
+
rb_gc_register_mark_object(eNestingError);
|
2168
2135
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
2169
2136
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
2170
2137
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
2171
2138
|
rb_define_method(cParser, "source", cParser_source, 0);
|
2172
|
-
rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
|
2173
2139
|
|
2174
2140
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
2141
|
+
rb_gc_register_mark_object(CNaN);
|
2142
|
+
|
2175
2143
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
2144
|
+
rb_gc_register_mark_object(CInfinity);
|
2145
|
+
|
2176
2146
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
2147
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
2177
2148
|
|
2178
2149
|
i_json_creatable_p = rb_intern("json_creatable?");
|
2179
2150
|
i_json_create = rb_intern("json_create");
|
@@ -2183,9 +2154,9 @@ void Init_parser(void)
|
|
2183
2154
|
i_max_nesting = rb_intern("max_nesting");
|
2184
2155
|
i_allow_nan = rb_intern("allow_nan");
|
2185
2156
|
i_symbolize_names = rb_intern("symbolize_names");
|
2186
|
-
i_quirks_mode = rb_intern("quirks_mode");
|
2187
2157
|
i_object_class = rb_intern("object_class");
|
2188
2158
|
i_array_class = rb_intern("array_class");
|
2159
|
+
i_decimal_class = rb_intern("decimal_class");
|
2189
2160
|
i_match = rb_intern("match");
|
2190
2161
|
i_match_string = rb_intern("match_string");
|
2191
2162
|
i_key_p = rb_intern("key?");
|
@@ -2193,18 +2164,10 @@ void Init_parser(void)
|
|
2193
2164
|
i_aset = rb_intern("[]=");
|
2194
2165
|
i_aref = rb_intern("[]");
|
2195
2166
|
i_leftshift = rb_intern("<<");
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
|
2201
|
-
CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
|
2202
|
-
CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
|
2203
|
-
i_encoding = rb_intern("encoding");
|
2204
|
-
i_encode = rb_intern("encode");
|
2205
|
-
#else
|
2206
|
-
i_iconv = rb_intern("iconv");
|
2207
|
-
#endif
|
2167
|
+
i_new = rb_intern("new");
|
2168
|
+
i_try_convert = rb_intern("try_convert");
|
2169
|
+
i_freeze = rb_intern("freeze");
|
2170
|
+
i_uminus = rb_intern("-@");
|
2208
2171
|
}
|
2209
2172
|
|
2210
2173
|
/*
|