json_pure 2.2.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +51 -0
  3. data/LICENSE +56 -0
  4. data/README.md +17 -1
  5. data/VERSION +1 -1
  6. data/json_pure.gemspec +49 -26
  7. data/lib/json.rb +549 -29
  8. data/lib/json/add/bigdecimal.rb +2 -2
  9. data/lib/json/add/complex.rb +2 -3
  10. data/lib/json/add/rational.rb +2 -3
  11. data/lib/json/add/regexp.rb +2 -2
  12. data/lib/json/common.rb +370 -125
  13. data/lib/json/pure/generator.rb +31 -10
  14. data/lib/json/pure/parser.rb +31 -5
  15. data/lib/json/version.rb +1 -1
  16. data/tests/fixtures/fail29.json +1 -0
  17. data/tests/fixtures/fail30.json +1 -0
  18. data/tests/fixtures/fail31.json +1 -0
  19. data/tests/fixtures/fail32.json +1 -0
  20. data/tests/json_addition_test.rb +0 -4
  21. data/tests/json_common_interface_test.rb +47 -4
  22. data/tests/json_fixtures_test.rb +9 -1
  23. data/tests/json_generator_test.rb +30 -8
  24. data/tests/json_parser_test.rb +39 -14
  25. data/tests/lib/core_assertions.rb +763 -0
  26. data/tests/lib/envutil.rb +365 -0
  27. data/tests/lib/find_executable.rb +22 -0
  28. data/tests/lib/helper.rb +4 -0
  29. data/tests/ractor_test.rb +30 -0
  30. data/tests/test_helper.rb +3 -3
  31. metadata +28 -48
  32. data/.gitignore +0 -17
  33. data/.travis.yml +0 -23
  34. data/README-json-jruby.md +0 -33
  35. data/Rakefile +0 -408
  36. data/diagrams/.keep +0 -0
  37. data/ext/json/ext/fbuffer/fbuffer.h +0 -187
  38. data/ext/json/ext/generator/depend +0 -1
  39. data/ext/json/ext/generator/extconf.rb +0 -4
  40. data/ext/json/ext/generator/generator.c +0 -1444
  41. data/ext/json/ext/generator/generator.h +0 -171
  42. data/ext/json/ext/parser/depend +0 -1
  43. data/ext/json/ext/parser/extconf.rb +0 -6
  44. data/ext/json/ext/parser/parser.c +0 -2131
  45. data/ext/json/ext/parser/parser.h +0 -91
  46. data/ext/json/ext/parser/parser.rl +0 -891
  47. data/ext/json/extconf.rb +0 -2
  48. data/install.rb +0 -23
  49. data/java/src/json/ext/ByteListTranscoder.java +0 -166
  50. data/java/src/json/ext/Generator.java +0 -443
  51. data/java/src/json/ext/GeneratorMethods.java +0 -231
  52. data/java/src/json/ext/GeneratorService.java +0 -42
  53. data/java/src/json/ext/GeneratorState.java +0 -490
  54. data/java/src/json/ext/OptionsReader.java +0 -113
  55. data/java/src/json/ext/Parser.java +0 -2362
  56. data/java/src/json/ext/Parser.rl +0 -893
  57. data/java/src/json/ext/ParserService.java +0 -34
  58. data/java/src/json/ext/RuntimeInfo.java +0 -116
  59. data/java/src/json/ext/StringDecoder.java +0 -166
  60. data/java/src/json/ext/StringEncoder.java +0 -111
  61. data/java/src/json/ext/Utils.java +0 -88
  62. data/json-java.gemspec +0 -38
  63. data/json.gemspec +0 -0
  64. data/references/rfc7159.txt +0 -899
  65. data/tools/diff.sh +0 -18
  66. data/tools/fuzz.rb +0 -131
  67. data/tools/server.rb +0 -62
@@ -1,171 +0,0 @@
1
- #ifndef _GENERATOR_H_
2
- #define _GENERATOR_H_
3
-
4
- #include <math.h>
5
- #include <ctype.h>
6
-
7
- #include "ruby.h"
8
-
9
- #ifdef HAVE_RUBY_RE_H
10
- #include "ruby/re.h"
11
- #else
12
- #include "re.h"
13
- #endif
14
-
15
- #ifndef rb_intern_str
16
- #define rb_intern_str(string) SYM2ID(rb_str_intern(string))
17
- #endif
18
-
19
- #ifndef rb_obj_instance_variables
20
- #define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
21
- #endif
22
-
23
- #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
24
-
25
- /* unicode definitions */
26
-
27
- #define UNI_STRICT_CONVERSION 1
28
-
29
- typedef unsigned long UTF32; /* at least 32 bits */
30
- typedef unsigned short UTF16; /* at least 16 bits */
31
- typedef unsigned char UTF8; /* typically 8 bits */
32
-
33
- #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
34
- #define UNI_MAX_BMP (UTF32)0x0000FFFF
35
- #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
36
- #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
37
- #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
38
-
39
- #define UNI_SUR_HIGH_START (UTF32)0xD800
40
- #define UNI_SUR_HIGH_END (UTF32)0xDBFF
41
- #define UNI_SUR_LOW_START (UTF32)0xDC00
42
- #define UNI_SUR_LOW_END (UTF32)0xDFFF
43
-
44
- static const int halfShift = 10; /* used for shifting by 10 bits */
45
-
46
- static const UTF32 halfBase = 0x0010000UL;
47
- static const UTF32 halfMask = 0x3FFUL;
48
-
49
- static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
50
- static void unicode_escape(char *buf, UTF16 character);
51
- static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
52
- static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
53
- static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
54
- static char *fstrndup(const char *ptr, unsigned long len);
55
-
56
- /* ruby api and some helpers */
57
-
58
- typedef struct JSON_Generator_StateStruct {
59
- char *indent;
60
- long indent_len;
61
- char *space;
62
- long space_len;
63
- char *space_before;
64
- long space_before_len;
65
- char *object_nl;
66
- long object_nl_len;
67
- char *array_nl;
68
- long array_nl_len;
69
- FBuffer *array_delim;
70
- FBuffer *object_delim;
71
- FBuffer *object_delim2;
72
- long max_nesting;
73
- char allow_nan;
74
- char ascii_only;
75
- long depth;
76
- long buffer_initial_length;
77
- } JSON_Generator_State;
78
-
79
- #define GET_STATE_TO(self, state) \
80
- TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
81
-
82
- #define GET_STATE(self) \
83
- JSON_Generator_State *state; \
84
- GET_STATE_TO(self, state)
85
-
86
- #define GENERATE_JSON(type) \
87
- FBuffer *buffer; \
88
- VALUE Vstate; \
89
- JSON_Generator_State *state; \
90
- \
91
- rb_scan_args(argc, argv, "01", &Vstate); \
92
- Vstate = cState_from_state_s(cState, Vstate); \
93
- TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
94
- buffer = cState_prepare_buffer(Vstate); \
95
- generate_json_##type(buffer, Vstate, state, self); \
96
- return fbuffer_to_s(buffer)
97
-
98
- static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
99
- static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
100
- #ifdef RUBY_INTEGER_UNIFICATION
101
- static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
102
- #else
103
- static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
104
- static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
105
- #endif
106
- static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
107
- static VALUE mString_included_s(VALUE self, VALUE modul);
108
- static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
109
- static VALUE mString_to_json_raw_object(VALUE self);
110
- static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self);
111
- static VALUE mString_Extend_json_create(VALUE self, VALUE o);
112
- static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
113
- static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
114
- static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
115
- static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
116
- static void State_free(void *state);
117
- static VALUE cState_s_allocate(VALUE klass);
118
- static VALUE cState_configure(VALUE self, VALUE opts);
119
- static VALUE cState_to_h(VALUE self);
120
- static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
121
- static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
122
- static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
123
- static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
124
- static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
125
- static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
126
- static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
127
- #ifdef RUBY_INTEGER_UNIFICATION
128
- static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
129
- #endif
130
- static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
131
- static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
132
- static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
133
- static VALUE cState_partial_generate(VALUE self, VALUE obj);
134
- static VALUE cState_generate(VALUE self, VALUE obj);
135
- static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
136
- static VALUE cState_from_state_s(VALUE self, VALUE opts);
137
- static VALUE cState_indent(VALUE self);
138
- static VALUE cState_indent_set(VALUE self, VALUE indent);
139
- static VALUE cState_space(VALUE self);
140
- static VALUE cState_space_set(VALUE self, VALUE space);
141
- static VALUE cState_space_before(VALUE self);
142
- static VALUE cState_space_before_set(VALUE self, VALUE space_before);
143
- static VALUE cState_object_nl(VALUE self);
144
- static VALUE cState_object_nl_set(VALUE self, VALUE object_nl);
145
- static VALUE cState_array_nl(VALUE self);
146
- static VALUE cState_array_nl_set(VALUE self, VALUE array_nl);
147
- static VALUE cState_max_nesting(VALUE self);
148
- static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
149
- static VALUE cState_allow_nan_p(VALUE self);
150
- static VALUE cState_ascii_only_p(VALUE self);
151
- static VALUE cState_depth(VALUE self);
152
- static VALUE cState_depth_set(VALUE self, VALUE depth);
153
- static FBuffer *cState_prepare_buffer(VALUE self);
154
- #ifndef ZALLOC
155
- #define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
156
- static inline void *ruby_zalloc(size_t n)
157
- {
158
- void *p = ruby_xmalloc(n);
159
- memset(p, 0, n);
160
- return p;
161
- }
162
- #endif
163
- #ifdef TypedData_Make_Struct
164
- static const rb_data_type_t JSON_Generator_State_type;
165
- #define NEW_TYPEDDATA_WRAPPER 1
166
- #else
167
- #define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
168
- #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
169
- #endif
170
-
171
- #endif
@@ -1 +0,0 @@
1
- parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'mkmf'
3
-
4
- have_func("rb_enc_raise", "ruby.h")
5
-
6
- create_makefile 'json/ext/parser'
@@ -1,2131 +0,0 @@
1
-
2
- #line 1 "parser.rl"
3
- #include "../fbuffer/fbuffer.h"
4
- #include "parser.h"
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
-
28
- /* unicode */
29
-
30
- static const char digit_values[256] = {
31
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
34
- -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
35
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36
- 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
39
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44
- -1, -1, -1, -1, -1, -1, -1
45
- };
46
-
47
- static UTF32 unescape_unicode(const unsigned char *p)
48
- {
49
- char b;
50
- UTF32 result = 0;
51
- b = digit_values[p[0]];
52
- if (b < 0) return UNI_REPLACEMENT_CHAR;
53
- result = (result << 4) | (unsigned char)b;
54
- b = digit_values[p[1]];
55
- if (b < 0) return UNI_REPLACEMENT_CHAR;
56
- result = (result << 4) | (unsigned char)b;
57
- b = digit_values[p[2]];
58
- if (b < 0) return UNI_REPLACEMENT_CHAR;
59
- result = (result << 4) | (unsigned char)b;
60
- b = digit_values[p[3]];
61
- if (b < 0) return UNI_REPLACEMENT_CHAR;
62
- result = (result << 4) | (unsigned char)b;
63
- return result;
64
- }
65
-
66
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
67
- {
68
- int len = 1;
69
- if (ch <= 0x7F) {
70
- buf[0] = (char) ch;
71
- } else if (ch <= 0x07FF) {
72
- buf[0] = (char) ((ch >> 6) | 0xC0);
73
- buf[1] = (char) ((ch & 0x3F) | 0x80);
74
- len++;
75
- } else if (ch <= 0xFFFF) {
76
- buf[0] = (char) ((ch >> 12) | 0xE0);
77
- buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
78
- buf[2] = (char) ((ch & 0x3F) | 0x80);
79
- len += 2;
80
- } else if (ch <= 0x1fffff) {
81
- buf[0] =(char) ((ch >> 18) | 0xF0);
82
- buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
83
- buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
84
- buf[3] =(char) ((ch & 0x3F) | 0x80);
85
- len += 3;
86
- } else {
87
- buf[0] = '?';
88
- }
89
- return len;
90
- }
91
-
92
- static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
93
- static VALUE CNaN, CInfinity, CMinusInfinity;
94
- static VALUE cBigDecimal = Qundef;
95
-
96
- static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
97
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
98
- i_object_class, i_array_class, i_decimal_class, i_key_p,
99
- i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
100
- i_leftshift, i_new, i_BigDecimal;
101
-
102
-
103
- #line 126 "parser.rl"
104
-
105
-
106
-
107
- #line 108 "parser.c"
108
- enum {JSON_object_start = 1};
109
- enum {JSON_object_first_final = 27};
110
- enum {JSON_object_error = 0};
111
-
112
- enum {JSON_object_en_main = 1};
113
-
114
-
115
- #line 167 "parser.rl"
116
-
117
-
118
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
119
- {
120
- int cs = EVIL;
121
- VALUE last_name = Qnil;
122
- VALUE object_class = json->object_class;
123
-
124
- if (json->max_nesting && current_nesting > json->max_nesting) {
125
- rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
126
- }
127
-
128
- *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
129
-
130
-
131
- #line 132 "parser.c"
132
- {
133
- cs = JSON_object_start;
134
- }
135
-
136
- #line 182 "parser.rl"
137
-
138
- #line 139 "parser.c"
139
- {
140
- if ( p == pe )
141
- goto _test_eof;
142
- switch ( cs )
143
- {
144
- case 1:
145
- if ( (*p) == 123 )
146
- goto st2;
147
- goto st0;
148
- st0:
149
- cs = 0;
150
- goto _out;
151
- st2:
152
- if ( ++p == pe )
153
- goto _test_eof2;
154
- case 2:
155
- switch( (*p) ) {
156
- case 13: goto st2;
157
- case 32: goto st2;
158
- case 34: goto tr2;
159
- case 47: goto st23;
160
- case 125: goto tr4;
161
- }
162
- if ( 9 <= (*p) && (*p) <= 10 )
163
- goto st2;
164
- goto st0;
165
- tr2:
166
- #line 149 "parser.rl"
167
- {
168
- char *np;
169
- json->parsing_name = 1;
170
- np = JSON_parse_string(json, p, pe, &last_name);
171
- json->parsing_name = 0;
172
- if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
173
- }
174
- goto st3;
175
- st3:
176
- if ( ++p == pe )
177
- goto _test_eof3;
178
- case 3:
179
- #line 180 "parser.c"
180
- switch( (*p) ) {
181
- case 13: goto st3;
182
- case 32: goto st3;
183
- case 47: goto st4;
184
- case 58: goto st8;
185
- }
186
- if ( 9 <= (*p) && (*p) <= 10 )
187
- goto st3;
188
- goto st0;
189
- st4:
190
- if ( ++p == pe )
191
- goto _test_eof4;
192
- case 4:
193
- switch( (*p) ) {
194
- case 42: goto st5;
195
- case 47: goto st7;
196
- }
197
- goto st0;
198
- st5:
199
- if ( ++p == pe )
200
- goto _test_eof5;
201
- case 5:
202
- if ( (*p) == 42 )
203
- goto st6;
204
- goto st5;
205
- st6:
206
- if ( ++p == pe )
207
- goto _test_eof6;
208
- case 6:
209
- switch( (*p) ) {
210
- case 42: goto st6;
211
- case 47: goto st3;
212
- }
213
- goto st5;
214
- st7:
215
- if ( ++p == pe )
216
- goto _test_eof7;
217
- case 7:
218
- if ( (*p) == 10 )
219
- goto st3;
220
- goto st7;
221
- st8:
222
- if ( ++p == pe )
223
- goto _test_eof8;
224
- case 8:
225
- switch( (*p) ) {
226
- case 13: goto st8;
227
- case 32: goto st8;
228
- case 34: goto tr11;
229
- case 45: goto tr11;
230
- case 47: goto st19;
231
- case 73: goto tr11;
232
- case 78: goto tr11;
233
- case 91: goto tr11;
234
- case 102: goto tr11;
235
- case 110: goto tr11;
236
- case 116: goto tr11;
237
- case 123: goto tr11;
238
- }
239
- if ( (*p) > 10 ) {
240
- if ( 48 <= (*p) && (*p) <= 57 )
241
- goto tr11;
242
- } else if ( (*p) >= 9 )
243
- goto st8;
244
- goto st0;
245
- tr11:
246
- #line 134 "parser.rl"
247
- {
248
- VALUE v = Qnil;
249
- char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
250
- if (np == NULL) {
251
- p--; {p++; cs = 9; goto _out;}
252
- } else {
253
- if (NIL_P(json->object_class)) {
254
- rb_hash_aset(*result, last_name, v);
255
- } else {
256
- rb_funcall(*result, i_aset, 2, last_name, v);
257
- }
258
- {p = (( np))-1;}
259
- }
260
- }
261
- goto st9;
262
- st9:
263
- if ( ++p == pe )
264
- goto _test_eof9;
265
- case 9:
266
- #line 267 "parser.c"
267
- switch( (*p) ) {
268
- case 13: goto st9;
269
- case 32: goto st9;
270
- case 44: goto st10;
271
- case 47: goto st15;
272
- case 125: goto tr4;
273
- }
274
- if ( 9 <= (*p) && (*p) <= 10 )
275
- goto st9;
276
- goto st0;
277
- st10:
278
- if ( ++p == pe )
279
- goto _test_eof10;
280
- case 10:
281
- switch( (*p) ) {
282
- case 13: goto st10;
283
- case 32: goto st10;
284
- case 34: goto tr2;
285
- case 47: goto st11;
286
- }
287
- if ( 9 <= (*p) && (*p) <= 10 )
288
- goto st10;
289
- goto st0;
290
- st11:
291
- if ( ++p == pe )
292
- goto _test_eof11;
293
- case 11:
294
- switch( (*p) ) {
295
- case 42: goto st12;
296
- case 47: goto st14;
297
- }
298
- goto st0;
299
- st12:
300
- if ( ++p == pe )
301
- goto _test_eof12;
302
- case 12:
303
- if ( (*p) == 42 )
304
- goto st13;
305
- goto st12;
306
- st13:
307
- if ( ++p == pe )
308
- goto _test_eof13;
309
- case 13:
310
- switch( (*p) ) {
311
- case 42: goto st13;
312
- case 47: goto st10;
313
- }
314
- goto st12;
315
- st14:
316
- if ( ++p == pe )
317
- goto _test_eof14;
318
- case 14:
319
- if ( (*p) == 10 )
320
- goto st10;
321
- goto st14;
322
- st15:
323
- if ( ++p == pe )
324
- goto _test_eof15;
325
- case 15:
326
- switch( (*p) ) {
327
- case 42: goto st16;
328
- case 47: goto st18;
329
- }
330
- goto st0;
331
- st16:
332
- if ( ++p == pe )
333
- goto _test_eof16;
334
- case 16:
335
- if ( (*p) == 42 )
336
- goto st17;
337
- goto st16;
338
- st17:
339
- if ( ++p == pe )
340
- goto _test_eof17;
341
- case 17:
342
- switch( (*p) ) {
343
- case 42: goto st17;
344
- case 47: goto st9;
345
- }
346
- goto st16;
347
- st18:
348
- if ( ++p == pe )
349
- goto _test_eof18;
350
- case 18:
351
- if ( (*p) == 10 )
352
- goto st9;
353
- goto st18;
354
- tr4:
355
- #line 157 "parser.rl"
356
- { p--; {p++; cs = 27; goto _out;} }
357
- goto st27;
358
- st27:
359
- if ( ++p == pe )
360
- goto _test_eof27;
361
- case 27:
362
- #line 363 "parser.c"
363
- goto st0;
364
- st19:
365
- if ( ++p == pe )
366
- goto _test_eof19;
367
- case 19:
368
- switch( (*p) ) {
369
- case 42: goto st20;
370
- case 47: goto st22;
371
- }
372
- goto st0;
373
- st20:
374
- if ( ++p == pe )
375
- goto _test_eof20;
376
- case 20:
377
- if ( (*p) == 42 )
378
- goto st21;
379
- goto st20;
380
- st21:
381
- if ( ++p == pe )
382
- goto _test_eof21;
383
- case 21:
384
- switch( (*p) ) {
385
- case 42: goto st21;
386
- case 47: goto st8;
387
- }
388
- goto st20;
389
- st22:
390
- if ( ++p == pe )
391
- goto _test_eof22;
392
- case 22:
393
- if ( (*p) == 10 )
394
- goto st8;
395
- goto st22;
396
- st23:
397
- if ( ++p == pe )
398
- goto _test_eof23;
399
- case 23:
400
- switch( (*p) ) {
401
- case 42: goto st24;
402
- case 47: goto st26;
403
- }
404
- goto st0;
405
- st24:
406
- if ( ++p == pe )
407
- goto _test_eof24;
408
- case 24:
409
- if ( (*p) == 42 )
410
- goto st25;
411
- goto st24;
412
- st25:
413
- if ( ++p == pe )
414
- goto _test_eof25;
415
- case 25:
416
- switch( (*p) ) {
417
- case 42: goto st25;
418
- case 47: goto st2;
419
- }
420
- goto st24;
421
- st26:
422
- if ( ++p == pe )
423
- goto _test_eof26;
424
- case 26:
425
- if ( (*p) == 10 )
426
- goto st2;
427
- goto st26;
428
- }
429
- _test_eof2: cs = 2; goto _test_eof;
430
- _test_eof3: cs = 3; goto _test_eof;
431
- _test_eof4: cs = 4; goto _test_eof;
432
- _test_eof5: cs = 5; goto _test_eof;
433
- _test_eof6: cs = 6; goto _test_eof;
434
- _test_eof7: cs = 7; goto _test_eof;
435
- _test_eof8: cs = 8; goto _test_eof;
436
- _test_eof9: cs = 9; goto _test_eof;
437
- _test_eof10: cs = 10; goto _test_eof;
438
- _test_eof11: cs = 11; goto _test_eof;
439
- _test_eof12: cs = 12; goto _test_eof;
440
- _test_eof13: cs = 13; goto _test_eof;
441
- _test_eof14: cs = 14; goto _test_eof;
442
- _test_eof15: cs = 15; goto _test_eof;
443
- _test_eof16: cs = 16; goto _test_eof;
444
- _test_eof17: cs = 17; goto _test_eof;
445
- _test_eof18: cs = 18; goto _test_eof;
446
- _test_eof27: cs = 27; goto _test_eof;
447
- _test_eof19: cs = 19; goto _test_eof;
448
- _test_eof20: cs = 20; goto _test_eof;
449
- _test_eof21: cs = 21; goto _test_eof;
450
- _test_eof22: cs = 22; goto _test_eof;
451
- _test_eof23: cs = 23; goto _test_eof;
452
- _test_eof24: cs = 24; goto _test_eof;
453
- _test_eof25: cs = 25; goto _test_eof;
454
- _test_eof26: cs = 26; goto _test_eof;
455
-
456
- _test_eof: {}
457
- _out: {}
458
- }
459
-
460
- #line 183 "parser.rl"
461
-
462
- if (cs >= JSON_object_first_final) {
463
- if (json->create_additions) {
464
- VALUE klassname;
465
- if (NIL_P(json->object_class)) {
466
- klassname = rb_hash_aref(*result, json->create_id);
467
- } else {
468
- klassname = rb_funcall(*result, i_aref, 1, json->create_id);
469
- }
470
- if (!NIL_P(klassname)) {
471
- VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
472
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
473
- *result = rb_funcall(klass, i_json_create, 1, *result);
474
- }
475
- }
476
- }
477
- return p + 1;
478
- } else {
479
- return NULL;
480
- }
481
- }
482
-
483
-
484
-
485
- #line 486 "parser.c"
486
- enum {JSON_value_start = 1};
487
- enum {JSON_value_first_final = 29};
488
- enum {JSON_value_error = 0};
489
-
490
- enum {JSON_value_en_main = 1};
491
-
492
-
493
- #line 283 "parser.rl"
494
-
495
-
496
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
497
- {
498
- int cs = EVIL;
499
-
500
-
501
- #line 502 "parser.c"
502
- {
503
- cs = JSON_value_start;
504
- }
505
-
506
- #line 290 "parser.rl"
507
-
508
- #line 509 "parser.c"
509
- {
510
- if ( p == pe )
511
- goto _test_eof;
512
- switch ( cs )
513
- {
514
- st1:
515
- if ( ++p == pe )
516
- goto _test_eof1;
517
- case 1:
518
- switch( (*p) ) {
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;
531
- }
532
- if ( (*p) > 10 ) {
533
- if ( 48 <= (*p) && (*p) <= 57 )
534
- goto tr3;
535
- } else if ( (*p) >= 9 )
536
- goto st1;
537
- goto st0;
538
- st0:
539
- cs = 0;
540
- goto _out;
541
- tr2:
542
- #line 235 "parser.rl"
543
- {
544
- char *np = JSON_parse_string(json, p, pe, result);
545
- if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
546
- }
547
- goto st29;
548
- tr3:
549
- #line 240 "parser.rl"
550
- {
551
- char *np;
552
- if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
553
- if (json->allow_nan) {
554
- *result = CMinusInfinity;
555
- {p = (( p + 10))-1;}
556
- p--; {p++; cs = 29; goto _out;}
557
- } else {
558
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
559
- }
560
- }
561
- np = JSON_parse_float(json, p, pe, result);
562
- if (np != NULL) {p = (( np))-1;}
563
- np = JSON_parse_integer(json, p, pe, result);
564
- if (np != NULL) {p = (( np))-1;}
565
- p--; {p++; cs = 29; goto _out;}
566
- }
567
- goto st29;
568
- tr7:
569
- #line 258 "parser.rl"
570
- {
571
- char *np;
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;}
574
- }
575
- goto st29;
576
- tr11:
577
- #line 264 "parser.rl"
578
- {
579
- char *np;
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;}
582
- }
583
- goto st29;
584
- tr25:
585
- #line 228 "parser.rl"
586
- {
587
- if (json->allow_nan) {
588
- *result = CInfinity;
589
- } else {
590
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
591
- }
592
- }
593
- goto st29;
594
- tr27:
595
- #line 221 "parser.rl"
596
- {
597
- if (json->allow_nan) {
598
- *result = CNaN;
599
- } else {
600
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
601
- }
602
- }
603
- goto st29;
604
- tr31:
605
- #line 215 "parser.rl"
606
- {
607
- *result = Qfalse;
608
- }
609
- goto st29;
610
- tr34:
611
- #line 212 "parser.rl"
612
- {
613
- *result = Qnil;
614
- }
615
- goto st29;
616
- tr37:
617
- #line 218 "parser.rl"
618
- {
619
- *result = Qtrue;
620
- }
621
- goto st29;
622
- st29:
623
- if ( ++p == pe )
624
- goto _test_eof29;
625
- case 29:
626
- #line 270 "parser.rl"
627
- { p--; {p++; cs = 29; goto _out;} }
628
- #line 629 "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;
636
- goto st0;
637
- st2:
638
- if ( ++p == pe )
639
- goto _test_eof2;
640
- case 2:
641
- switch( (*p) ) {
642
- case 42: goto st3;
643
- case 47: goto st5;
644
- }
645
- goto st0;
646
- st3:
647
- if ( ++p == pe )
648
- goto _test_eof3;
649
- case 3:
650
- if ( (*p) == 42 )
651
- goto st4;
652
- goto st3;
653
- st4:
654
- if ( ++p == pe )
655
- goto _test_eof4;
656
- case 4:
657
- switch( (*p) ) {
658
- case 42: goto st4;
659
- case 47: goto st29;
660
- }
661
- goto st3;
662
- st5:
663
- if ( ++p == pe )
664
- goto _test_eof5;
665
- case 5:
666
- if ( (*p) == 10 )
667
- goto st29;
668
- goto st5;
669
- st6:
670
- if ( ++p == pe )
671
- goto _test_eof6;
672
- case 6:
673
- switch( (*p) ) {
674
- case 42: goto st7;
675
- case 47: goto st9;
676
- }
677
- goto st0;
678
- st7:
679
- if ( ++p == pe )
680
- goto _test_eof7;
681
- case 7:
682
- if ( (*p) == 42 )
683
- goto st8;
684
- goto st7;
685
- st8:
686
- if ( ++p == pe )
687
- goto _test_eof8;
688
- case 8:
689
- switch( (*p) ) {
690
- case 42: goto st8;
691
- case 47: goto st1;
692
- }
693
- goto st7;
694
- st9:
695
- if ( ++p == pe )
696
- goto _test_eof9;
697
- case 9:
698
- if ( (*p) == 10 )
699
- goto st1;
700
- goto st9;
701
- st10:
702
- if ( ++p == pe )
703
- goto _test_eof10;
704
- case 10:
705
- if ( (*p) == 110 )
706
- goto st11;
707
- goto st0;
708
- st11:
709
- if ( ++p == pe )
710
- goto _test_eof11;
711
- case 11:
712
- if ( (*p) == 102 )
713
- goto st12;
714
- goto st0;
715
- st12:
716
- if ( ++p == pe )
717
- goto _test_eof12;
718
- case 12:
719
- if ( (*p) == 105 )
720
- goto st13;
721
- goto st0;
722
- st13:
723
- if ( ++p == pe )
724
- goto _test_eof13;
725
- case 13:
726
- if ( (*p) == 110 )
727
- goto st14;
728
- goto st0;
729
- st14:
730
- if ( ++p == pe )
731
- goto _test_eof14;
732
- case 14:
733
- if ( (*p) == 105 )
734
- goto st15;
735
- goto st0;
736
- st15:
737
- if ( ++p == pe )
738
- goto _test_eof15;
739
- case 15:
740
- if ( (*p) == 116 )
741
- goto st16;
742
- goto st0;
743
- st16:
744
- if ( ++p == pe )
745
- goto _test_eof16;
746
- case 16:
747
- if ( (*p) == 121 )
748
- goto tr25;
749
- goto st0;
750
- st17:
751
- if ( ++p == pe )
752
- goto _test_eof17;
753
- case 17:
754
- if ( (*p) == 97 )
755
- goto st18;
756
- goto st0;
757
- st18:
758
- if ( ++p == pe )
759
- goto _test_eof18;
760
- case 18:
761
- if ( (*p) == 78 )
762
- goto tr27;
763
- goto st0;
764
- st19:
765
- if ( ++p == pe )
766
- goto _test_eof19;
767
- case 19:
768
- if ( (*p) == 97 )
769
- goto st20;
770
- goto st0;
771
- st20:
772
- if ( ++p == pe )
773
- goto _test_eof20;
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:
789
- if ( (*p) == 101 )
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;
833
- goto st0;
834
- }
835
- _test_eof1: cs = 1; goto _test_eof;
836
- _test_eof29: cs = 29; goto _test_eof;
837
- _test_eof2: cs = 2; goto _test_eof;
838
- _test_eof3: cs = 3; goto _test_eof;
839
- _test_eof4: cs = 4; goto _test_eof;
840
- _test_eof5: cs = 5; goto _test_eof;
841
- _test_eof6: cs = 6; goto _test_eof;
842
- _test_eof7: cs = 7; goto _test_eof;
843
- _test_eof8: cs = 8; goto _test_eof;
844
- _test_eof9: cs = 9; goto _test_eof;
845
- _test_eof10: cs = 10; goto _test_eof;
846
- _test_eof11: cs = 11; goto _test_eof;
847
- _test_eof12: cs = 12; goto _test_eof;
848
- _test_eof13: cs = 13; goto _test_eof;
849
- _test_eof14: cs = 14; goto _test_eof;
850
- _test_eof15: cs = 15; goto _test_eof;
851
- _test_eof16: cs = 16; goto _test_eof;
852
- _test_eof17: cs = 17; goto _test_eof;
853
- _test_eof18: cs = 18; goto _test_eof;
854
- _test_eof19: cs = 19; goto _test_eof;
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;
864
-
865
- _test_eof: {}
866
- _out: {}
867
- }
868
-
869
- #line 291 "parser.rl"
870
-
871
- if (cs >= JSON_value_first_final) {
872
- return p;
873
- } else {
874
- return NULL;
875
- }
876
- }
877
-
878
-
879
- #line 880 "parser.c"
880
- enum {JSON_integer_start = 1};
881
- enum {JSON_integer_first_final = 3};
882
- enum {JSON_integer_error = 0};
883
-
884
- enum {JSON_integer_en_main = 1};
885
-
886
-
887
- #line 307 "parser.rl"
888
-
889
-
890
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
891
- {
892
- int cs = EVIL;
893
-
894
-
895
- #line 896 "parser.c"
896
- {
897
- cs = JSON_integer_start;
898
- }
899
-
900
- #line 314 "parser.rl"
901
- json->memo = p;
902
-
903
- #line 904 "parser.c"
904
- {
905
- if ( p == pe )
906
- goto _test_eof;
907
- switch ( cs )
908
- {
909
- case 1:
910
- switch( (*p) ) {
911
- case 45: goto st2;
912
- case 48: goto st3;
913
- }
914
- if ( 49 <= (*p) && (*p) <= 57 )
915
- goto st5;
916
- goto st0;
917
- st0:
918
- cs = 0;
919
- goto _out;
920
- st2:
921
- if ( ++p == pe )
922
- goto _test_eof2;
923
- case 2:
924
- if ( (*p) == 48 )
925
- goto st3;
926
- if ( 49 <= (*p) && (*p) <= 57 )
927
- goto st5;
928
- goto st0;
929
- st3:
930
- if ( ++p == pe )
931
- goto _test_eof3;
932
- case 3:
933
- if ( 48 <= (*p) && (*p) <= 57 )
934
- goto st0;
935
- goto tr4;
936
- tr4:
937
- #line 304 "parser.rl"
938
- { p--; {p++; cs = 4; goto _out;} }
939
- goto st4;
940
- st4:
941
- if ( ++p == pe )
942
- goto _test_eof4;
943
- case 4:
944
- #line 945 "parser.c"
945
- goto st0;
946
- st5:
947
- if ( ++p == pe )
948
- goto _test_eof5;
949
- case 5:
950
- if ( 48 <= (*p) && (*p) <= 57 )
951
- goto st5;
952
- goto tr4;
953
- }
954
- _test_eof2: cs = 2; goto _test_eof;
955
- _test_eof3: cs = 3; goto _test_eof;
956
- _test_eof4: cs = 4; goto _test_eof;
957
- _test_eof5: cs = 5; goto _test_eof;
958
-
959
- _test_eof: {}
960
- _out: {}
961
- }
962
-
963
- #line 316 "parser.rl"
964
-
965
- if (cs >= JSON_integer_first_final) {
966
- long len = p - json->memo;
967
- fbuffer_clear(json->fbuffer);
968
- fbuffer_append(json->fbuffer, json->memo, len);
969
- fbuffer_append_char(json->fbuffer, '\0');
970
- *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
971
- return p + 1;
972
- } else {
973
- return NULL;
974
- }
975
- }
976
-
977
-
978
- #line 979 "parser.c"
979
- enum {JSON_float_start = 1};
980
- enum {JSON_float_first_final = 8};
981
- enum {JSON_float_error = 0};
982
-
983
- enum {JSON_float_en_main = 1};
984
-
985
-
986
- #line 341 "parser.rl"
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
-
1002
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
1003
- {
1004
- int cs = EVIL;
1005
-
1006
-
1007
- #line 1008 "parser.c"
1008
- {
1009
- cs = JSON_float_start;
1010
- }
1011
-
1012
- #line 361 "parser.rl"
1013
- json->memo = p;
1014
-
1015
- #line 1016 "parser.c"
1016
- {
1017
- if ( p == pe )
1018
- goto _test_eof;
1019
- switch ( cs )
1020
- {
1021
- case 1:
1022
- switch( (*p) ) {
1023
- case 45: goto st2;
1024
- case 48: goto st3;
1025
- }
1026
- if ( 49 <= (*p) && (*p) <= 57 )
1027
- goto st7;
1028
- goto st0;
1029
- st0:
1030
- cs = 0;
1031
- goto _out;
1032
- st2:
1033
- if ( ++p == pe )
1034
- goto _test_eof2;
1035
- case 2:
1036
- if ( (*p) == 48 )
1037
- goto st3;
1038
- if ( 49 <= (*p) && (*p) <= 57 )
1039
- goto st7;
1040
- goto st0;
1041
- st3:
1042
- if ( ++p == pe )
1043
- goto _test_eof3;
1044
- case 3:
1045
- switch( (*p) ) {
1046
- case 46: goto st4;
1047
- case 69: goto st5;
1048
- case 101: goto st5;
1049
- }
1050
- goto st0;
1051
- st4:
1052
- if ( ++p == pe )
1053
- goto _test_eof4;
1054
- case 4:
1055
- if ( 48 <= (*p) && (*p) <= 57 )
1056
- goto st8;
1057
- goto st0;
1058
- st8:
1059
- if ( ++p == pe )
1060
- goto _test_eof8;
1061
- case 8:
1062
- switch( (*p) ) {
1063
- case 69: goto st5;
1064
- case 101: goto st5;
1065
- }
1066
- if ( (*p) > 46 ) {
1067
- if ( 48 <= (*p) && (*p) <= 57 )
1068
- goto st8;
1069
- } else if ( (*p) >= 45 )
1070
- goto st0;
1071
- goto tr9;
1072
- tr9:
1073
- #line 335 "parser.rl"
1074
- { p--; {p++; cs = 9; goto _out;} }
1075
- goto st9;
1076
- st9:
1077
- if ( ++p == pe )
1078
- goto _test_eof9;
1079
- case 9:
1080
- #line 1081 "parser.c"
1081
- goto st0;
1082
- st5:
1083
- if ( ++p == pe )
1084
- goto _test_eof5;
1085
- case 5:
1086
- switch( (*p) ) {
1087
- case 43: goto st6;
1088
- case 45: goto st6;
1089
- }
1090
- if ( 48 <= (*p) && (*p) <= 57 )
1091
- goto st10;
1092
- goto st0;
1093
- st6:
1094
- if ( ++p == pe )
1095
- goto _test_eof6;
1096
- case 6:
1097
- if ( 48 <= (*p) && (*p) <= 57 )
1098
- goto st10;
1099
- goto st0;
1100
- st10:
1101
- if ( ++p == pe )
1102
- goto _test_eof10;
1103
- case 10:
1104
- switch( (*p) ) {
1105
- case 69: goto st0;
1106
- case 101: goto st0;
1107
- }
1108
- if ( (*p) > 46 ) {
1109
- if ( 48 <= (*p) && (*p) <= 57 )
1110
- goto st10;
1111
- } else if ( (*p) >= 45 )
1112
- goto st0;
1113
- goto tr9;
1114
- st7:
1115
- if ( ++p == pe )
1116
- goto _test_eof7;
1117
- case 7:
1118
- switch( (*p) ) {
1119
- case 46: goto st4;
1120
- case 69: goto st5;
1121
- case 101: goto st5;
1122
- }
1123
- if ( 48 <= (*p) && (*p) <= 57 )
1124
- goto st7;
1125
- goto st0;
1126
- }
1127
- _test_eof2: cs = 2; goto _test_eof;
1128
- _test_eof3: cs = 3; goto _test_eof;
1129
- _test_eof4: cs = 4; goto _test_eof;
1130
- _test_eof8: cs = 8; goto _test_eof;
1131
- _test_eof9: cs = 9; goto _test_eof;
1132
- _test_eof5: cs = 5; goto _test_eof;
1133
- _test_eof6: cs = 6; goto _test_eof;
1134
- _test_eof10: cs = 10; goto _test_eof;
1135
- _test_eof7: cs = 7; goto _test_eof;
1136
-
1137
- _test_eof: {}
1138
- _out: {}
1139
- }
1140
-
1141
- #line 363 "parser.rl"
1142
-
1143
- if (cs >= JSON_float_first_final) {
1144
- long len = p - json->memo;
1145
- fbuffer_clear(json->fbuffer);
1146
- fbuffer_append(json->fbuffer, json->memo, len);
1147
- fbuffer_append_char(json->fbuffer, '\0');
1148
- if (NIL_P(json->decimal_class)) {
1149
- *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1150
- } else {
1151
- VALUE text;
1152
- text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
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
- }
1158
- }
1159
- return p + 1;
1160
- } else {
1161
- return NULL;
1162
- }
1163
- }
1164
-
1165
-
1166
-
1167
- #line 1168 "parser.c"
1168
- enum {JSON_array_start = 1};
1169
- enum {JSON_array_first_final = 17};
1170
- enum {JSON_array_error = 0};
1171
-
1172
- enum {JSON_array_en_main = 1};
1173
-
1174
-
1175
- #line 416 "parser.rl"
1176
-
1177
-
1178
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
1179
- {
1180
- int cs = EVIL;
1181
- VALUE array_class = json->array_class;
1182
-
1183
- if (json->max_nesting && current_nesting > json->max_nesting) {
1184
- rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
1185
- }
1186
- *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1187
-
1188
-
1189
- #line 1190 "parser.c"
1190
- {
1191
- cs = JSON_array_start;
1192
- }
1193
-
1194
- #line 429 "parser.rl"
1195
-
1196
- #line 1197 "parser.c"
1197
- {
1198
- if ( p == pe )
1199
- goto _test_eof;
1200
- switch ( cs )
1201
- {
1202
- case 1:
1203
- if ( (*p) == 91 )
1204
- goto st2;
1205
- goto st0;
1206
- st0:
1207
- cs = 0;
1208
- goto _out;
1209
- st2:
1210
- if ( ++p == pe )
1211
- goto _test_eof2;
1212
- case 2:
1213
- switch( (*p) ) {
1214
- case 13: goto st2;
1215
- case 32: goto st2;
1216
- case 34: goto tr2;
1217
- case 45: goto tr2;
1218
- case 47: goto st13;
1219
- case 73: goto tr2;
1220
- case 78: goto tr2;
1221
- case 91: goto tr2;
1222
- case 93: goto tr4;
1223
- case 102: goto tr2;
1224
- case 110: goto tr2;
1225
- case 116: goto tr2;
1226
- case 123: goto tr2;
1227
- }
1228
- if ( (*p) > 10 ) {
1229
- if ( 48 <= (*p) && (*p) <= 57 )
1230
- goto tr2;
1231
- } else if ( (*p) >= 9 )
1232
- goto st2;
1233
- goto st0;
1234
- tr2:
1235
- #line 393 "parser.rl"
1236
- {
1237
- VALUE v = Qnil;
1238
- char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
1239
- if (np == NULL) {
1240
- p--; {p++; cs = 3; goto _out;}
1241
- } else {
1242
- if (NIL_P(json->array_class)) {
1243
- rb_ary_push(*result, v);
1244
- } else {
1245
- rb_funcall(*result, i_leftshift, 1, v);
1246
- }
1247
- {p = (( np))-1;}
1248
- }
1249
- }
1250
- goto st3;
1251
- st3:
1252
- if ( ++p == pe )
1253
- goto _test_eof3;
1254
- case 3:
1255
- #line 1256 "parser.c"
1256
- switch( (*p) ) {
1257
- case 13: goto st3;
1258
- case 32: goto st3;
1259
- case 44: goto st4;
1260
- case 47: goto st9;
1261
- case 93: goto tr4;
1262
- }
1263
- if ( 9 <= (*p) && (*p) <= 10 )
1264
- goto st3;
1265
- goto st0;
1266
- st4:
1267
- if ( ++p == pe )
1268
- goto _test_eof4;
1269
- case 4:
1270
- switch( (*p) ) {
1271
- case 13: goto st4;
1272
- case 32: goto st4;
1273
- case 34: goto tr2;
1274
- case 45: goto tr2;
1275
- case 47: goto st5;
1276
- case 73: goto tr2;
1277
- case 78: goto tr2;
1278
- case 91: goto tr2;
1279
- case 102: goto tr2;
1280
- case 110: goto tr2;
1281
- case 116: goto tr2;
1282
- case 123: goto tr2;
1283
- }
1284
- if ( (*p) > 10 ) {
1285
- if ( 48 <= (*p) && (*p) <= 57 )
1286
- goto tr2;
1287
- } else if ( (*p) >= 9 )
1288
- goto st4;
1289
- goto st0;
1290
- st5:
1291
- if ( ++p == pe )
1292
- goto _test_eof5;
1293
- case 5:
1294
- switch( (*p) ) {
1295
- case 42: goto st6;
1296
- case 47: goto st8;
1297
- }
1298
- goto st0;
1299
- st6:
1300
- if ( ++p == pe )
1301
- goto _test_eof6;
1302
- case 6:
1303
- if ( (*p) == 42 )
1304
- goto st7;
1305
- goto st6;
1306
- st7:
1307
- if ( ++p == pe )
1308
- goto _test_eof7;
1309
- case 7:
1310
- switch( (*p) ) {
1311
- case 42: goto st7;
1312
- case 47: goto st4;
1313
- }
1314
- goto st6;
1315
- st8:
1316
- if ( ++p == pe )
1317
- goto _test_eof8;
1318
- case 8:
1319
- if ( (*p) == 10 )
1320
- goto st4;
1321
- goto st8;
1322
- st9:
1323
- if ( ++p == pe )
1324
- goto _test_eof9;
1325
- case 9:
1326
- switch( (*p) ) {
1327
- case 42: goto st10;
1328
- case 47: goto st12;
1329
- }
1330
- goto st0;
1331
- st10:
1332
- if ( ++p == pe )
1333
- goto _test_eof10;
1334
- case 10:
1335
- if ( (*p) == 42 )
1336
- goto st11;
1337
- goto st10;
1338
- st11:
1339
- if ( ++p == pe )
1340
- goto _test_eof11;
1341
- case 11:
1342
- switch( (*p) ) {
1343
- case 42: goto st11;
1344
- case 47: goto st3;
1345
- }
1346
- goto st10;
1347
- st12:
1348
- if ( ++p == pe )
1349
- goto _test_eof12;
1350
- case 12:
1351
- if ( (*p) == 10 )
1352
- goto st3;
1353
- goto st12;
1354
- tr4:
1355
- #line 408 "parser.rl"
1356
- { p--; {p++; cs = 17; goto _out;} }
1357
- goto st17;
1358
- st17:
1359
- if ( ++p == pe )
1360
- goto _test_eof17;
1361
- case 17:
1362
- #line 1363 "parser.c"
1363
- goto st0;
1364
- st13:
1365
- if ( ++p == pe )
1366
- goto _test_eof13;
1367
- case 13:
1368
- switch( (*p) ) {
1369
- case 42: goto st14;
1370
- case 47: goto st16;
1371
- }
1372
- goto st0;
1373
- st14:
1374
- if ( ++p == pe )
1375
- goto _test_eof14;
1376
- case 14:
1377
- if ( (*p) == 42 )
1378
- goto st15;
1379
- goto st14;
1380
- st15:
1381
- if ( ++p == pe )
1382
- goto _test_eof15;
1383
- case 15:
1384
- switch( (*p) ) {
1385
- case 42: goto st15;
1386
- case 47: goto st2;
1387
- }
1388
- goto st14;
1389
- st16:
1390
- if ( ++p == pe )
1391
- goto _test_eof16;
1392
- case 16:
1393
- if ( (*p) == 10 )
1394
- goto st2;
1395
- goto st16;
1396
- }
1397
- _test_eof2: cs = 2; goto _test_eof;
1398
- _test_eof3: cs = 3; goto _test_eof;
1399
- _test_eof4: cs = 4; goto _test_eof;
1400
- _test_eof5: cs = 5; goto _test_eof;
1401
- _test_eof6: cs = 6; goto _test_eof;
1402
- _test_eof7: cs = 7; goto _test_eof;
1403
- _test_eof8: cs = 8; goto _test_eof;
1404
- _test_eof9: cs = 9; goto _test_eof;
1405
- _test_eof10: cs = 10; goto _test_eof;
1406
- _test_eof11: cs = 11; goto _test_eof;
1407
- _test_eof12: cs = 12; goto _test_eof;
1408
- _test_eof17: cs = 17; goto _test_eof;
1409
- _test_eof13: cs = 13; goto _test_eof;
1410
- _test_eof14: cs = 14; goto _test_eof;
1411
- _test_eof15: cs = 15; goto _test_eof;
1412
- _test_eof16: cs = 16; goto _test_eof;
1413
-
1414
- _test_eof: {}
1415
- _out: {}
1416
- }
1417
-
1418
- #line 430 "parser.rl"
1419
-
1420
- if(cs >= JSON_array_first_final) {
1421
- return p + 1;
1422
- } else {
1423
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1424
- return NULL;
1425
- }
1426
- }
1427
-
1428
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1429
- {
1430
- char *p = string, *pe = string, *unescape;
1431
- int unescape_len;
1432
- char buf[4];
1433
-
1434
- while (pe < stringEnd) {
1435
- if (*pe == '\\') {
1436
- unescape = (char *) "?";
1437
- unescape_len = 1;
1438
- if (pe > p) rb_str_buf_cat(result, p, pe - p);
1439
- switch (*++pe) {
1440
- case 'n':
1441
- unescape = (char *) "\n";
1442
- break;
1443
- case 'r':
1444
- unescape = (char *) "\r";
1445
- break;
1446
- case 't':
1447
- unescape = (char *) "\t";
1448
- break;
1449
- case '"':
1450
- unescape = (char *) "\"";
1451
- break;
1452
- case '\\':
1453
- unescape = (char *) "\\";
1454
- break;
1455
- case 'b':
1456
- unescape = (char *) "\b";
1457
- break;
1458
- case 'f':
1459
- unescape = (char *) "\f";
1460
- break;
1461
- case 'u':
1462
- if (pe > stringEnd - 4) {
1463
- rb_enc_raise(
1464
- EXC_ENCODING eParserError,
1465
- "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
1466
- );
1467
- } else {
1468
- UTF32 ch = unescape_unicode((unsigned char *) ++pe);
1469
- pe += 3;
1470
- if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
1471
- pe++;
1472
- if (pe > stringEnd - 6) {
1473
- rb_enc_raise(
1474
- EXC_ENCODING eParserError,
1475
- "%u: incomplete surrogate pair at '%s'", __LINE__, p
1476
- );
1477
- }
1478
- if (pe[0] == '\\' && pe[1] == 'u') {
1479
- UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
1480
- ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
1481
- | (sur & 0x3FF));
1482
- pe += 5;
1483
- } else {
1484
- unescape = (char *) "?";
1485
- break;
1486
- }
1487
- }
1488
- unescape_len = convert_UTF32_to_UTF8(buf, ch);
1489
- unescape = buf;
1490
- }
1491
- break;
1492
- default:
1493
- p = pe;
1494
- continue;
1495
- }
1496
- rb_str_buf_cat(result, unescape, unescape_len);
1497
- p = ++pe;
1498
- } else {
1499
- pe++;
1500
- }
1501
- }
1502
- rb_str_buf_cat(result, p, pe - p);
1503
- return result;
1504
- }
1505
-
1506
-
1507
- #line 1508 "parser.c"
1508
- enum {JSON_string_start = 1};
1509
- enum {JSON_string_first_final = 8};
1510
- enum {JSON_string_error = 0};
1511
-
1512
- enum {JSON_string_en_main = 1};
1513
-
1514
-
1515
- #line 537 "parser.rl"
1516
-
1517
-
1518
- static int
1519
- match_i(VALUE regexp, VALUE klass, VALUE memo)
1520
- {
1521
- if (regexp == Qundef) return ST_STOP;
1522
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
1523
- RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
1524
- rb_ary_push(memo, klass);
1525
- return ST_STOP;
1526
- }
1527
- return ST_CONTINUE;
1528
- }
1529
-
1530
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
1531
- {
1532
- int cs = EVIL;
1533
- VALUE match_string;
1534
-
1535
- *result = rb_str_buf_new(0);
1536
-
1537
- #line 1538 "parser.c"
1538
- {
1539
- cs = JSON_string_start;
1540
- }
1541
-
1542
- #line 558 "parser.rl"
1543
- json->memo = p;
1544
-
1545
- #line 1546 "parser.c"
1546
- {
1547
- if ( p == pe )
1548
- goto _test_eof;
1549
- switch ( cs )
1550
- {
1551
- case 1:
1552
- if ( (*p) == 34 )
1553
- goto st2;
1554
- goto st0;
1555
- st0:
1556
- cs = 0;
1557
- goto _out;
1558
- st2:
1559
- if ( ++p == pe )
1560
- goto _test_eof2;
1561
- case 2:
1562
- switch( (*p) ) {
1563
- case 34: goto tr2;
1564
- case 92: goto st3;
1565
- }
1566
- if ( 0 <= (*p) && (*p) <= 31 )
1567
- goto st0;
1568
- goto st2;
1569
- tr2:
1570
- #line 523 "parser.rl"
1571
- {
1572
- *result = json_string_unescape(*result, json->memo + 1, p);
1573
- if (NIL_P(*result)) {
1574
- p--;
1575
- {p++; cs = 8; goto _out;}
1576
- } else {
1577
- FORCE_UTF8(*result);
1578
- {p = (( p + 1))-1;}
1579
- }
1580
- }
1581
- #line 534 "parser.rl"
1582
- { p--; {p++; cs = 8; goto _out;} }
1583
- goto st8;
1584
- st8:
1585
- if ( ++p == pe )
1586
- goto _test_eof8;
1587
- case 8:
1588
- #line 1589 "parser.c"
1589
- goto st0;
1590
- st3:
1591
- if ( ++p == pe )
1592
- goto _test_eof3;
1593
- case 3:
1594
- if ( (*p) == 117 )
1595
- goto st4;
1596
- if ( 0 <= (*p) && (*p) <= 31 )
1597
- goto st0;
1598
- goto st2;
1599
- st4:
1600
- if ( ++p == pe )
1601
- goto _test_eof4;
1602
- case 4:
1603
- if ( (*p) < 65 ) {
1604
- if ( 48 <= (*p) && (*p) <= 57 )
1605
- goto st5;
1606
- } else if ( (*p) > 70 ) {
1607
- if ( 97 <= (*p) && (*p) <= 102 )
1608
- goto st5;
1609
- } else
1610
- goto st5;
1611
- goto st0;
1612
- st5:
1613
- if ( ++p == pe )
1614
- goto _test_eof5;
1615
- case 5:
1616
- if ( (*p) < 65 ) {
1617
- if ( 48 <= (*p) && (*p) <= 57 )
1618
- goto st6;
1619
- } else if ( (*p) > 70 ) {
1620
- if ( 97 <= (*p) && (*p) <= 102 )
1621
- goto st6;
1622
- } else
1623
- goto st6;
1624
- goto st0;
1625
- st6:
1626
- if ( ++p == pe )
1627
- goto _test_eof6;
1628
- case 6:
1629
- if ( (*p) < 65 ) {
1630
- if ( 48 <= (*p) && (*p) <= 57 )
1631
- goto st7;
1632
- } else if ( (*p) > 70 ) {
1633
- if ( 97 <= (*p) && (*p) <= 102 )
1634
- goto st7;
1635
- } else
1636
- goto st7;
1637
- goto st0;
1638
- st7:
1639
- if ( ++p == pe )
1640
- goto _test_eof7;
1641
- case 7:
1642
- if ( (*p) < 65 ) {
1643
- if ( 48 <= (*p) && (*p) <= 57 )
1644
- goto st2;
1645
- } else if ( (*p) > 70 ) {
1646
- if ( 97 <= (*p) && (*p) <= 102 )
1647
- goto st2;
1648
- } else
1649
- goto st2;
1650
- goto st0;
1651
- }
1652
- _test_eof2: cs = 2; goto _test_eof;
1653
- _test_eof8: cs = 8; goto _test_eof;
1654
- _test_eof3: cs = 3; goto _test_eof;
1655
- _test_eof4: cs = 4; goto _test_eof;
1656
- _test_eof5: cs = 5; goto _test_eof;
1657
- _test_eof6: cs = 6; goto _test_eof;
1658
- _test_eof7: cs = 7; goto _test_eof;
1659
-
1660
- _test_eof: {}
1661
- _out: {}
1662
- }
1663
-
1664
- #line 560 "parser.rl"
1665
-
1666
- if (json->create_additions && RTEST(match_string = json->match_string)) {
1667
- VALUE klass;
1668
- VALUE memo = rb_ary_new2(2);
1669
- rb_ary_push(memo, *result);
1670
- rb_hash_foreach(match_string, match_i, memo);
1671
- klass = rb_ary_entry(memo, 1);
1672
- if (RTEST(klass)) {
1673
- *result = rb_funcall(klass, i_json_create, 1, *result);
1674
- }
1675
- }
1676
-
1677
- if (json->symbolize_names && json->parsing_name) {
1678
- *result = rb_str_intern(*result);
1679
- } else {
1680
- if (RB_TYPE_P(*result, T_STRING)) {
1681
- rb_str_resize(*result, RSTRING_LEN(*result));
1682
- }
1683
- }
1684
- if (cs >= JSON_string_first_final) {
1685
- return p + 1;
1686
- } else {
1687
- return NULL;
1688
- }
1689
- }
1690
-
1691
- /*
1692
- * Document-class: JSON::Ext::Parser
1693
- *
1694
- * This is the JSON parser implemented as a C extension. It can be configured
1695
- * to be used by setting
1696
- *
1697
- * JSON.parser = JSON::Ext::Parser
1698
- *
1699
- * with the method parser= in JSON.
1700
- *
1701
- */
1702
-
1703
- static VALUE convert_encoding(VALUE source)
1704
- {
1705
- #ifdef HAVE_RUBY_ENCODING_H
1706
- rb_encoding *enc = rb_enc_get(source);
1707
- if (enc == rb_ascii8bit_encoding()) {
1708
- if (OBJ_FROZEN(source)) {
1709
- source = rb_str_dup(source);
1710
- }
1711
- FORCE_UTF8(source);
1712
- } else {
1713
- source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
1714
- }
1715
- #endif
1716
- return source;
1717
- }
1718
-
1719
- /*
1720
- * call-seq: new(source, opts => {})
1721
- *
1722
- * Creates a new JSON::Ext::Parser instance for the string _source_.
1723
- *
1724
- * Creates a new JSON::Ext::Parser instance for the string _source_.
1725
- *
1726
- * It will be configured by the _opts_ hash. _opts_ can have the following
1727
- * keys:
1728
- *
1729
- * _opts_ can have the following keys:
1730
- * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
1731
- * structures. Disable depth checking with :max_nesting => false|nil|0, it
1732
- * defaults to 100.
1733
- * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
1734
- * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1735
- * false.
1736
- * * *symbolize_names*: If set to true, returns symbols for the names
1737
- * (keys) in a JSON object. Otherwise strings are returned, which is
1738
- * also the default. It's not possible to use this option in
1739
- * conjunction with the *create_additions* option.
1740
- * * *create_additions*: If set to false, the Parser doesn't create
1741
- * additions even if a matching class and create_id was found. This option
1742
- * defaults to false.
1743
- * * *object_class*: Defaults to Hash
1744
- * * *array_class*: Defaults to Array
1745
- */
1746
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1747
- {
1748
- VALUE source, opts;
1749
- GET_PARSER_INIT;
1750
-
1751
- if (json->Vsource) {
1752
- rb_raise(rb_eTypeError, "already initialized instance");
1753
- }
1754
- #ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1755
- rb_scan_args(argc, argv, "1:", &source, &opts);
1756
- #else
1757
- rb_scan_args(argc, argv, "11", &source, &opts);
1758
- #endif
1759
- if (!NIL_P(opts)) {
1760
- #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1761
- opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1762
- if (NIL_P(opts)) {
1763
- rb_raise(rb_eArgError, "opts needs to be like a hash");
1764
- } else {
1765
- #endif
1766
- VALUE tmp = ID2SYM(i_max_nesting);
1767
- if (option_given_p(opts, tmp)) {
1768
- VALUE max_nesting = rb_hash_aref(opts, tmp);
1769
- if (RTEST(max_nesting)) {
1770
- Check_Type(max_nesting, T_FIXNUM);
1771
- json->max_nesting = FIX2INT(max_nesting);
1772
- } else {
1773
- json->max_nesting = 0;
1774
- }
1775
- } else {
1776
- json->max_nesting = 100;
1777
- }
1778
- tmp = ID2SYM(i_allow_nan);
1779
- if (option_given_p(opts, tmp)) {
1780
- json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1781
- } else {
1782
- json->allow_nan = 0;
1783
- }
1784
- tmp = ID2SYM(i_symbolize_names);
1785
- if (option_given_p(opts, tmp)) {
1786
- json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1787
- } else {
1788
- json->symbolize_names = 0;
1789
- }
1790
- tmp = ID2SYM(i_create_additions);
1791
- if (option_given_p(opts, tmp)) {
1792
- json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1793
- } else {
1794
- json->create_additions = 0;
1795
- }
1796
- if (json->symbolize_names && json->create_additions) {
1797
- rb_raise(rb_eArgError,
1798
- "options :symbolize_names and :create_additions cannot be "
1799
- " used in conjunction");
1800
- }
1801
- tmp = ID2SYM(i_create_id);
1802
- if (option_given_p(opts, tmp)) {
1803
- json->create_id = rb_hash_aref(opts, tmp);
1804
- } else {
1805
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
1806
- }
1807
- tmp = ID2SYM(i_object_class);
1808
- if (option_given_p(opts, tmp)) {
1809
- json->object_class = rb_hash_aref(opts, tmp);
1810
- } else {
1811
- json->object_class = Qnil;
1812
- }
1813
- tmp = ID2SYM(i_array_class);
1814
- if (option_given_p(opts, tmp)) {
1815
- json->array_class = rb_hash_aref(opts, tmp);
1816
- } else {
1817
- json->array_class = Qnil;
1818
- }
1819
- tmp = ID2SYM(i_decimal_class);
1820
- if (option_given_p(opts, tmp)) {
1821
- json->decimal_class = rb_hash_aref(opts, tmp);
1822
- } else {
1823
- json->decimal_class = Qnil;
1824
- }
1825
- tmp = ID2SYM(i_match_string);
1826
- if (option_given_p(opts, tmp)) {
1827
- VALUE match_string = rb_hash_aref(opts, tmp);
1828
- json->match_string = RTEST(match_string) ? match_string : Qnil;
1829
- } else {
1830
- json->match_string = Qnil;
1831
- }
1832
- #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1833
- }
1834
- #endif
1835
- } else {
1836
- json->max_nesting = 100;
1837
- json->allow_nan = 0;
1838
- json->create_additions = 1;
1839
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
1840
- json->object_class = Qnil;
1841
- json->array_class = Qnil;
1842
- json->decimal_class = Qnil;
1843
- }
1844
- source = convert_encoding(StringValue(source));
1845
- StringValue(source);
1846
- json->len = RSTRING_LEN(source);
1847
- json->source = RSTRING_PTR(source);;
1848
- json->Vsource = source;
1849
- return self;
1850
- }
1851
-
1852
-
1853
- #line 1854 "parser.c"
1854
- enum {JSON_start = 1};
1855
- enum {JSON_first_final = 10};
1856
- enum {JSON_error = 0};
1857
-
1858
- enum {JSON_en_main = 1};
1859
-
1860
-
1861
- #line 762 "parser.rl"
1862
-
1863
-
1864
- /*
1865
- * call-seq: parse()
1866
- *
1867
- * Parses the current JSON text _source_ and returns the complete data
1868
- * structure as a result.
1869
- */
1870
- static VALUE cParser_parse(VALUE self)
1871
- {
1872
- char *p, *pe;
1873
- int cs = EVIL;
1874
- VALUE result = Qnil;
1875
- GET_PARSER;
1876
-
1877
-
1878
- #line 1879 "parser.c"
1879
- {
1880
- cs = JSON_start;
1881
- }
1882
-
1883
- #line 778 "parser.rl"
1884
- p = json->source;
1885
- pe = p + json->len;
1886
-
1887
- #line 1888 "parser.c"
1888
- {
1889
- if ( p == pe )
1890
- goto _test_eof;
1891
- switch ( cs )
1892
- {
1893
- st1:
1894
- if ( ++p == pe )
1895
- goto _test_eof1;
1896
- case 1:
1897
- switch( (*p) ) {
1898
- case 13: goto st1;
1899
- case 32: goto st1;
1900
- case 34: goto tr2;
1901
- case 45: goto tr2;
1902
- case 47: goto st6;
1903
- case 73: goto tr2;
1904
- case 78: goto tr2;
1905
- case 91: goto tr2;
1906
- case 102: goto tr2;
1907
- case 110: goto tr2;
1908
- case 116: goto tr2;
1909
- case 123: goto tr2;
1910
- }
1911
- if ( (*p) > 10 ) {
1912
- if ( 48 <= (*p) && (*p) <= 57 )
1913
- goto tr2;
1914
- } else if ( (*p) >= 9 )
1915
- goto st1;
1916
- goto st0;
1917
- st0:
1918
- cs = 0;
1919
- goto _out;
1920
- tr2:
1921
- #line 754 "parser.rl"
1922
- {
1923
- char *np = JSON_parse_value(json, p, pe, &result, 0);
1924
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1925
- }
1926
- goto st10;
1927
- st10:
1928
- if ( ++p == pe )
1929
- goto _test_eof10;
1930
- case 10:
1931
- #line 1932 "parser.c"
1932
- switch( (*p) ) {
1933
- case 13: goto st10;
1934
- case 32: goto st10;
1935
- case 47: goto st2;
1936
- }
1937
- if ( 9 <= (*p) && (*p) <= 10 )
1938
- goto st10;
1939
- goto st0;
1940
- st2:
1941
- if ( ++p == pe )
1942
- goto _test_eof2;
1943
- case 2:
1944
- switch( (*p) ) {
1945
- case 42: goto st3;
1946
- case 47: goto st5;
1947
- }
1948
- goto st0;
1949
- st3:
1950
- if ( ++p == pe )
1951
- goto _test_eof3;
1952
- case 3:
1953
- if ( (*p) == 42 )
1954
- goto st4;
1955
- goto st3;
1956
- st4:
1957
- if ( ++p == pe )
1958
- goto _test_eof4;
1959
- case 4:
1960
- switch( (*p) ) {
1961
- case 42: goto st4;
1962
- case 47: goto st10;
1963
- }
1964
- goto st3;
1965
- st5:
1966
- if ( ++p == pe )
1967
- goto _test_eof5;
1968
- case 5:
1969
- if ( (*p) == 10 )
1970
- goto st10;
1971
- goto st5;
1972
- st6:
1973
- if ( ++p == pe )
1974
- goto _test_eof6;
1975
- case 6:
1976
- switch( (*p) ) {
1977
- case 42: goto st7;
1978
- case 47: goto st9;
1979
- }
1980
- goto st0;
1981
- st7:
1982
- if ( ++p == pe )
1983
- goto _test_eof7;
1984
- case 7:
1985
- if ( (*p) == 42 )
1986
- goto st8;
1987
- goto st7;
1988
- st8:
1989
- if ( ++p == pe )
1990
- goto _test_eof8;
1991
- case 8:
1992
- switch( (*p) ) {
1993
- case 42: goto st8;
1994
- case 47: goto st1;
1995
- }
1996
- goto st7;
1997
- st9:
1998
- if ( ++p == pe )
1999
- goto _test_eof9;
2000
- case 9:
2001
- if ( (*p) == 10 )
2002
- goto st1;
2003
- goto st9;
2004
- }
2005
- _test_eof1: cs = 1; goto _test_eof;
2006
- _test_eof10: cs = 10; goto _test_eof;
2007
- _test_eof2: cs = 2; goto _test_eof;
2008
- _test_eof3: cs = 3; goto _test_eof;
2009
- _test_eof4: cs = 4; goto _test_eof;
2010
- _test_eof5: cs = 5; goto _test_eof;
2011
- _test_eof6: cs = 6; goto _test_eof;
2012
- _test_eof7: cs = 7; goto _test_eof;
2013
- _test_eof8: cs = 8; goto _test_eof;
2014
- _test_eof9: cs = 9; goto _test_eof;
2015
-
2016
- _test_eof: {}
2017
- _out: {}
2018
- }
2019
-
2020
- #line 781 "parser.rl"
2021
-
2022
- if (cs >= JSON_first_final && p == pe) {
2023
- return result;
2024
- } else {
2025
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2026
- return Qnil;
2027
- }
2028
- }
2029
-
2030
- static void JSON_mark(void *ptr)
2031
- {
2032
- JSON_Parser *json = ptr;
2033
- rb_gc_mark_maybe(json->Vsource);
2034
- rb_gc_mark_maybe(json->create_id);
2035
- rb_gc_mark_maybe(json->object_class);
2036
- rb_gc_mark_maybe(json->array_class);
2037
- rb_gc_mark_maybe(json->decimal_class);
2038
- rb_gc_mark_maybe(json->match_string);
2039
- }
2040
-
2041
- static void JSON_free(void *ptr)
2042
- {
2043
- JSON_Parser *json = ptr;
2044
- fbuffer_free(json->fbuffer);
2045
- ruby_xfree(json);
2046
- }
2047
-
2048
- static size_t JSON_memsize(const void *ptr)
2049
- {
2050
- const JSON_Parser *json = ptr;
2051
- return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
2052
- }
2053
-
2054
- #ifdef NEW_TYPEDDATA_WRAPPER
2055
- static const rb_data_type_t JSON_Parser_type = {
2056
- "JSON/Parser",
2057
- {JSON_mark, JSON_free, JSON_memsize,},
2058
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
2059
- 0, 0,
2060
- RUBY_TYPED_FREE_IMMEDIATELY,
2061
- #endif
2062
- };
2063
- #endif
2064
-
2065
- static VALUE cJSON_parser_s_allocate(VALUE klass)
2066
- {
2067
- JSON_Parser *json;
2068
- VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
2069
- json->fbuffer = fbuffer_alloc(0);
2070
- return obj;
2071
- }
2072
-
2073
- /*
2074
- * call-seq: source()
2075
- *
2076
- * Returns a copy of the current _source_ string, that was used to construct
2077
- * this Parser.
2078
- */
2079
- static VALUE cParser_source(VALUE self)
2080
- {
2081
- GET_PARSER;
2082
- return rb_str_dup(json->Vsource);
2083
- }
2084
-
2085
- void Init_parser(void)
2086
- {
2087
- #undef rb_intern
2088
- rb_require("json/common");
2089
- mJSON = rb_define_module("JSON");
2090
- mExt = rb_define_module_under(mJSON, "Ext");
2091
- cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
2092
- eParserError = rb_path2class("JSON::ParserError");
2093
- eNestingError = rb_path2class("JSON::NestingError");
2094
- rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
2095
- rb_define_method(cParser, "initialize", cParser_initialize, -1);
2096
- rb_define_method(cParser, "parse", cParser_parse, 0);
2097
- rb_define_method(cParser, "source", cParser_source, 0);
2098
-
2099
- CNaN = rb_const_get(mJSON, rb_intern("NaN"));
2100
- CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
2101
- CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
2102
-
2103
- i_json_creatable_p = rb_intern("json_creatable?");
2104
- i_json_create = rb_intern("json_create");
2105
- i_create_id = rb_intern("create_id");
2106
- i_create_additions = rb_intern("create_additions");
2107
- i_chr = rb_intern("chr");
2108
- i_max_nesting = rb_intern("max_nesting");
2109
- i_allow_nan = rb_intern("allow_nan");
2110
- i_symbolize_names = rb_intern("symbolize_names");
2111
- i_object_class = rb_intern("object_class");
2112
- i_array_class = rb_intern("array_class");
2113
- i_decimal_class = rb_intern("decimal_class");
2114
- i_match = rb_intern("match");
2115
- i_match_string = rb_intern("match_string");
2116
- i_key_p = rb_intern("key?");
2117
- i_deep_const_get = rb_intern("deep_const_get");
2118
- i_aset = rb_intern("[]=");
2119
- i_aref = rb_intern("[]");
2120
- i_leftshift = rb_intern("<<");
2121
- i_new = rb_intern("new");
2122
- i_BigDecimal = rb_intern("BigDecimal");
2123
- }
2124
-
2125
- /*
2126
- * Local variables:
2127
- * mode: c
2128
- * c-file-style: ruby
2129
- * indent-tabs-mode: nil
2130
- * End:
2131
- */