json_pure 2.1.0 → 2.4.1

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