json 1.0.3-mswin32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

Files changed (84) hide show
  1. data/CHANGES +32 -0
  2. data/GPL +340 -0
  3. data/README +77 -0
  4. data/Rakefile +304 -0
  5. data/TODO +1 -0
  6. data/VERSION +1 -0
  7. data/benchmarks/benchmark.txt +133 -0
  8. data/benchmarks/benchmark_generator.rb +44 -0
  9. data/benchmarks/benchmark_parser.rb +22 -0
  10. data/benchmarks/benchmark_rails.rb +26 -0
  11. data/bin/edit_json.rb +11 -0
  12. data/bin/prettify_json.rb +75 -0
  13. data/data/example.json +1 -0
  14. data/data/index.html +37 -0
  15. data/data/prototype.js +2515 -0
  16. data/ext/json/ext/generator.so +0 -0
  17. data/ext/json/ext/generator/extconf.rb +9 -0
  18. data/ext/json/ext/generator/generator.c +729 -0
  19. data/ext/json/ext/generator/unicode.c +184 -0
  20. data/ext/json/ext/generator/unicode.h +40 -0
  21. data/ext/json/ext/parser.so +0 -0
  22. data/ext/json/ext/parser/extconf.rb +9 -0
  23. data/ext/json/ext/parser/parser.c +1554 -0
  24. data/ext/json/ext/parser/parser.rl +515 -0
  25. data/ext/json/ext/parser/unicode.c +156 -0
  26. data/ext/json/ext/parser/unicode.h +44 -0
  27. data/install.rb +26 -0
  28. data/lib/json.rb +205 -0
  29. data/lib/json/Array.xpm +21 -0
  30. data/lib/json/FalseClass.xpm +21 -0
  31. data/lib/json/Hash.xpm +21 -0
  32. data/lib/json/Key.xpm +73 -0
  33. data/lib/json/NilClass.xpm +21 -0
  34. data/lib/json/Numeric.xpm +28 -0
  35. data/lib/json/String.xpm +96 -0
  36. data/lib/json/TrueClass.xpm +21 -0
  37. data/lib/json/common.rb +184 -0
  38. data/lib/json/editor.rb +1207 -0
  39. data/lib/json/ext.rb +13 -0
  40. data/lib/json/json.xpm +1499 -0
  41. data/lib/json/pure.rb +75 -0
  42. data/lib/json/pure/generator.rb +321 -0
  43. data/lib/json/pure/parser.rb +214 -0
  44. data/lib/json/version.rb +8 -0
  45. data/tests/fixtures/fail1.json +1 -0
  46. data/tests/fixtures/fail10.json +1 -0
  47. data/tests/fixtures/fail11.json +1 -0
  48. data/tests/fixtures/fail12.json +1 -0
  49. data/tests/fixtures/fail13.json +1 -0
  50. data/tests/fixtures/fail14.json +1 -0
  51. data/tests/fixtures/fail15.json +1 -0
  52. data/tests/fixtures/fail16.json +1 -0
  53. data/tests/fixtures/fail17.json +1 -0
  54. data/tests/fixtures/fail19.json +1 -0
  55. data/tests/fixtures/fail2.json +1 -0
  56. data/tests/fixtures/fail20.json +1 -0
  57. data/tests/fixtures/fail21.json +1 -0
  58. data/tests/fixtures/fail22.json +1 -0
  59. data/tests/fixtures/fail23.json +1 -0
  60. data/tests/fixtures/fail24.json +1 -0
  61. data/tests/fixtures/fail25.json +1 -0
  62. data/tests/fixtures/fail26.json +1 -0
  63. data/tests/fixtures/fail27.json +2 -0
  64. data/tests/fixtures/fail28.json +2 -0
  65. data/tests/fixtures/fail3.json +1 -0
  66. data/tests/fixtures/fail4.json +1 -0
  67. data/tests/fixtures/fail5.json +1 -0
  68. data/tests/fixtures/fail6.json +1 -0
  69. data/tests/fixtures/fail7.json +1 -0
  70. data/tests/fixtures/fail8.json +1 -0
  71. data/tests/fixtures/fail9.json +1 -0
  72. data/tests/fixtures/pass1.json +56 -0
  73. data/tests/fixtures/pass18.json +1 -0
  74. data/tests/fixtures/pass2.json +1 -0
  75. data/tests/fixtures/pass3.json +6 -0
  76. data/tests/runner.rb +24 -0
  77. data/tests/test_json.rb +236 -0
  78. data/tests/test_json_addition.rb +94 -0
  79. data/tests/test_json_fixtures.rb +30 -0
  80. data/tests/test_json_generate.rb +81 -0
  81. data/tests/test_json_unicode.rb +58 -0
  82. data/tools/fuzz.rb +131 -0
  83. data/tools/server.rb +62 -0
  84. metadata +149 -0
@@ -0,0 +1,184 @@
1
+ /* vim: set cin et sw=4 ts=4: */
2
+
3
+ #include "unicode.h"
4
+
5
+ #define unicode_escape(buffer, character) \
6
+ sprintf(buf, "\\u%04x", (unsigned int) (character)); \
7
+ rb_str_buf_cat(buffer, buf, 6);
8
+
9
+ /*
10
+ * Copyright 2001-2004 Unicode, Inc.
11
+ *
12
+ * Disclaimer
13
+ *
14
+ * This source code is provided as is by Unicode, Inc. No claims are
15
+ * made as to fitness for any particular purpose. No warranties of any
16
+ * kind are expressed or implied. The recipient agrees to determine
17
+ * applicability of information provided. If this file has been
18
+ * purchased on magnetic or optical media from Unicode, Inc., the
19
+ * sole remedy for any claim will be exchange of defective media
20
+ * within 90 days of receipt.
21
+ *
22
+ * Limitations on Rights to Redistribute This Code
23
+ *
24
+ * Unicode, Inc. hereby grants the right to freely use the information
25
+ * supplied in this file in the creation of products supporting the
26
+ * Unicode Standard, and to make copies of this file in any form
27
+ * for internal or external distribution as long as this notice
28
+ * remains attached.
29
+ */
30
+
31
+ /*
32
+ * Index into the table below with the first byte of a UTF-8 sequence to
33
+ * get the number of trailing bytes that are supposed to follow it.
34
+ * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
35
+ * left as-is for anyone who may want to do such conversion, which was
36
+ * allowed in earlier algorithms.
37
+ */
38
+ static const char trailingBytesForUTF8[256] = {
39
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
40
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
42
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
46
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
47
+ };
48
+
49
+ /*
50
+ * Magic values subtracted from a buffer value during UTF8 conversion.
51
+ * This table contains as many values as there might be trailing bytes
52
+ * in a UTF-8 sequence.
53
+ */
54
+ static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
55
+ 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
56
+
57
+ /*
58
+ * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
59
+ * into the first byte, depending on how many bytes follow. There are
60
+ * as many entries in this table as there are UTF-8 sequence types.
61
+ * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
62
+ * for *legal* UTF-8 will be 4 or fewer bytes total.
63
+ */
64
+ static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
65
+
66
+ /*
67
+ * Utility routine to tell whether a sequence of bytes is legal UTF-8.
68
+ * This must be called with the length pre-determined by the first byte.
69
+ * If not calling this from ConvertUTF8to*, then the length can be set by:
70
+ * length = trailingBytesForUTF8[*source]+1;
71
+ * and the sequence is illegal right away if there aren't that many bytes
72
+ * available.
73
+ * If presented with a length > 4, this returns 0. The Unicode
74
+ * definition of UTF-8 goes up to 4-byte sequences.
75
+ */
76
+
77
+ inline static unsigned char isLegalUTF8(const UTF8 *source, int length)
78
+ {
79
+ UTF8 a;
80
+ const UTF8 *srcptr = source+length;
81
+ switch (length) {
82
+ default: return 0;
83
+ /* Everything else falls through when "1"... */
84
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
85
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
86
+ case 2: if ((a = (*--srcptr)) > 0xBF) return 0;
87
+
88
+ switch (*source) {
89
+ /* no fall-through in this inner switch */
90
+ case 0xE0: if (a < 0xA0) return 0; break;
91
+ case 0xED: if (a > 0x9F) return 0; break;
92
+ case 0xF0: if (a < 0x90) return 0; break;
93
+ case 0xF4: if (a > 0x8F) return 0; break;
94
+ default: if (a < 0x80) return 0;
95
+ }
96
+
97
+ case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
98
+ }
99
+ if (*source > 0xF4) return 0;
100
+ return 1;
101
+ }
102
+
103
+ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags)
104
+ {
105
+ char buf[7];
106
+ const UTF8* source = (UTF8 *) RSTRING(string)->ptr;
107
+ const UTF8* sourceEnd = source + RSTRING(string)->len;
108
+
109
+ while (source < sourceEnd) {
110
+ UTF32 ch = 0;
111
+ unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
112
+ if (source + extraBytesToRead >= sourceEnd) {
113
+ rb_raise(rb_path2class("JSON::GeneratorError"),
114
+ "partial character in source, but hit end");
115
+ }
116
+ if (!isLegalUTF8(source, extraBytesToRead+1)) {
117
+ rb_raise(rb_path2class("JSON::GeneratorError"),
118
+ "source sequence is illegal/malformed");
119
+ }
120
+ /*
121
+ * The cases all fall through. See "Note A" below.
122
+ */
123
+ switch (extraBytesToRead) {
124
+ case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
125
+ case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
126
+ case 3: ch += *source++; ch <<= 6;
127
+ case 2: ch += *source++; ch <<= 6;
128
+ case 1: ch += *source++; ch <<= 6;
129
+ case 0: ch += *source++;
130
+ }
131
+ ch -= offsetsFromUTF8[extraBytesToRead];
132
+
133
+ if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
134
+ /* UTF-16 surrogate values are illegal in UTF-32 */
135
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
136
+ if (flags == strictConversion) {
137
+ source -= (extraBytesToRead+1); /* return to the illegal value itself */
138
+ rb_raise(rb_path2class("JSON::GeneratorError"),
139
+ "source sequence is illegal/malformed");
140
+ } else {
141
+ unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
142
+ }
143
+ } else {
144
+ /* normal case */
145
+ if (ch == '"') {
146
+ rb_str_buf_cat2(buffer, "\\\"");
147
+ } else if (ch == '\\') {
148
+ rb_str_buf_cat2(buffer, "\\\\");
149
+ } else if (ch == '/') {
150
+ rb_str_buf_cat2(buffer, "\\/");
151
+ } else if (ch >= 0x20 && ch <= 0x7f) {
152
+ rb_str_buf_cat(buffer, (char *) source - 1, 1);
153
+ } else if (ch == '\n') {
154
+ rb_str_buf_cat2(buffer, "\\n");
155
+ } else if (ch == '\r') {
156
+ rb_str_buf_cat2(buffer, "\\r");
157
+ } else if (ch == '\t') {
158
+ rb_str_buf_cat2(buffer, "\\t");
159
+ } else if (ch == '\f') {
160
+ rb_str_buf_cat2(buffer, "\\f");
161
+ } else if (ch == '\b') {
162
+ rb_str_buf_cat2(buffer, "\\b");
163
+ } else if (ch < 0x20) {
164
+ unicode_escape(buffer, (UTF16) ch);
165
+ } else {
166
+ unicode_escape(buffer, (UTF16) ch);
167
+ }
168
+ }
169
+ } else if (ch > UNI_MAX_UTF16) {
170
+ if (flags == strictConversion) {
171
+ source -= (extraBytesToRead+1); /* return to the start */
172
+ rb_raise(rb_path2class("JSON::GeneratorError"),
173
+ "source sequence is illegal/malformed");
174
+ } else {
175
+ unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
176
+ }
177
+ } else {
178
+ /* target is a character in range 0xFFFF - 0x10FFFF. */
179
+ ch -= halfBase;
180
+ unicode_escape(buffer, (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START));
181
+ unicode_escape(buffer, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START));
182
+ }
183
+ }
184
+ }
@@ -0,0 +1,40 @@
1
+ #include "ruby.h"
2
+
3
+ #ifndef _GENERATOR_UNICODE_H_
4
+ #define _GENERATOR_UNICODE_H_
5
+
6
+ typedef enum {
7
+ conversionOK = 0, /* conversion successful */
8
+ sourceExhausted, /* partial character in source, but hit end */
9
+ targetExhausted, /* insuff. room in target for conversion */
10
+ sourceIllegal /* source sequence is illegal/malformed */
11
+ } ConversionResult;
12
+
13
+ typedef enum {
14
+ strictConversion = 0,
15
+ lenientConversion
16
+ } ConversionFlags;
17
+
18
+ typedef unsigned long UTF32; /* at least 32 bits */
19
+ typedef unsigned short UTF16; /* at least 16 bits */
20
+ typedef unsigned char UTF8; /* typically 8 bits */
21
+
22
+ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
23
+ #define UNI_MAX_BMP (UTF32)0x0000FFFF
24
+ #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
25
+ #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
26
+ #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
27
+
28
+ #define UNI_SUR_HIGH_START (UTF32)0xD800
29
+ #define UNI_SUR_HIGH_END (UTF32)0xDBFF
30
+ #define UNI_SUR_LOW_START (UTF32)0xDC00
31
+ #define UNI_SUR_LOW_END (UTF32)0xDFFF
32
+
33
+ static const int halfShift = 10; /* used for shifting by 10 bits */
34
+
35
+ static const UTF32 halfBase = 0x0010000UL;
36
+ static const UTF32 halfMask = 0x3FFUL;
37
+
38
+ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags);
39
+
40
+ #endif
Binary file
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+
4
+ if CONFIG['CC'] =~ /gcc/
5
+ #CONFIG['CC'] += ' -Wall -ggdb'
6
+ CONFIG['CC'] += ' -Wall'
7
+ end
8
+
9
+ create_makefile 'parser'
@@ -0,0 +1,1554 @@
1
+ #line 1 "parser.rl"
2
+ /* vim: set cin et sw=4 ts=4: */
3
+
4
+ #include "ruby.h"
5
+ #include "re.h"
6
+ #include "unicode.h"
7
+
8
+ #ifndef swap16
9
+ #define swap16(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
10
+ #endif
11
+
12
+ #define EVIL 0x666
13
+
14
+ static VALUE mJSON, mExt, cParser, eParserError;
15
+
16
+ static ID i_json_creatable_p, i_json_create, i_create_id, i_chr;
17
+
18
+ typedef struct JSON_ParserStruct {
19
+ VALUE Vsource;
20
+ char *source;
21
+ long len;
22
+ char *memo;
23
+ VALUE create_id;
24
+ } JSON_Parser;
25
+
26
+ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
27
+ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
28
+ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
29
+ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
30
+ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
31
+ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
32
+
33
+ #define GET_STRUCT \
34
+ JSON_Parser *json; \
35
+ Data_Get_Struct(self, JSON_Parser, json);
36
+
37
+ #line 59 "parser.rl"
38
+
39
+
40
+
41
+ #line 42 "parser.c"
42
+ static const int JSON_object_start = 1;
43
+ static const int JSON_object_first_final = 27;
44
+ static const int JSON_object_error = 0;
45
+
46
+ static const int JSON_object_en_main = 1;
47
+
48
+ #line 92 "parser.rl"
49
+
50
+
51
+ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
52
+ {
53
+ int cs = EVIL;
54
+ VALUE last_name = Qnil;
55
+ *result = rb_hash_new();
56
+
57
+
58
+ #line 59 "parser.c"
59
+ {
60
+ cs = JSON_object_start;
61
+ }
62
+ #line 101 "parser.rl"
63
+
64
+ #line 65 "parser.c"
65
+ {
66
+ if ( p == pe )
67
+ goto _out;
68
+ switch ( cs )
69
+ {
70
+ case 1:
71
+ if ( (*p) == 123 )
72
+ goto st2;
73
+ goto st0;
74
+ st0:
75
+ goto _out0;
76
+ st2:
77
+ if ( ++p == pe )
78
+ goto _out2;
79
+ case 2:
80
+ switch( (*p) ) {
81
+ case 13: goto st2;
82
+ case 32: goto st2;
83
+ case 34: goto tr2;
84
+ case 47: goto st23;
85
+ case 125: goto tr4;
86
+ }
87
+ if ( 9 <= (*p) && (*p) <= 10 )
88
+ goto st2;
89
+ goto st0;
90
+ tr2:
91
+ #line 78 "parser.rl"
92
+ {
93
+ char *np = JSON_parse_string(json, p, pe, &last_name);
94
+ if (np == NULL) goto _out3; else {p = (( np))-1;}
95
+ }
96
+ goto st3;
97
+ st3:
98
+ if ( ++p == pe )
99
+ goto _out3;
100
+ case 3:
101
+ #line 102 "parser.c"
102
+ switch( (*p) ) {
103
+ case 13: goto st3;
104
+ case 32: goto st3;
105
+ case 47: goto st4;
106
+ case 58: goto st8;
107
+ }
108
+ if ( 9 <= (*p) && (*p) <= 10 )
109
+ goto st3;
110
+ goto st0;
111
+ st4:
112
+ if ( ++p == pe )
113
+ goto _out4;
114
+ case 4:
115
+ switch( (*p) ) {
116
+ case 42: goto st5;
117
+ case 47: goto st7;
118
+ }
119
+ goto st0;
120
+ st5:
121
+ if ( ++p == pe )
122
+ goto _out5;
123
+ case 5:
124
+ if ( (*p) == 42 )
125
+ goto st6;
126
+ goto st5;
127
+ st6:
128
+ if ( ++p == pe )
129
+ goto _out6;
130
+ case 6:
131
+ switch( (*p) ) {
132
+ case 42: goto st6;
133
+ case 47: goto st3;
134
+ }
135
+ goto st5;
136
+ st7:
137
+ if ( ++p == pe )
138
+ goto _out7;
139
+ case 7:
140
+ if ( (*p) == 10 )
141
+ goto st3;
142
+ goto st7;
143
+ st8:
144
+ if ( ++p == pe )
145
+ goto _out8;
146
+ case 8:
147
+ switch( (*p) ) {
148
+ case 13: goto st8;
149
+ case 32: goto st8;
150
+ case 34: goto tr11;
151
+ case 45: goto tr11;
152
+ case 47: goto st19;
153
+ case 91: goto tr11;
154
+ case 102: goto tr11;
155
+ case 110: goto tr11;
156
+ case 116: goto tr11;
157
+ case 123: goto tr11;
158
+ }
159
+ if ( (*p) > 10 ) {
160
+ if ( 48 <= (*p) && (*p) <= 57 )
161
+ goto tr11;
162
+ } else if ( (*p) >= 9 )
163
+ goto st8;
164
+ goto st0;
165
+ tr11:
166
+ #line 67 "parser.rl"
167
+ {
168
+ VALUE v = Qnil;
169
+ char *np = JSON_parse_value(json, p, pe, &v);
170
+ if (np == NULL) {
171
+ goto _out9;
172
+ } else {
173
+ rb_hash_aset(*result, last_name, v);
174
+ {p = (( np))-1;}
175
+ }
176
+ }
177
+ goto st9;
178
+ st9:
179
+ if ( ++p == pe )
180
+ goto _out9;
181
+ case 9:
182
+ #line 183 "parser.c"
183
+ switch( (*p) ) {
184
+ case 13: goto st9;
185
+ case 32: goto st9;
186
+ case 44: goto st10;
187
+ case 47: goto st15;
188
+ case 125: goto tr4;
189
+ }
190
+ if ( 9 <= (*p) && (*p) <= 10 )
191
+ goto st9;
192
+ goto st0;
193
+ st10:
194
+ if ( ++p == pe )
195
+ goto _out10;
196
+ case 10:
197
+ switch( (*p) ) {
198
+ case 13: goto st10;
199
+ case 32: goto st10;
200
+ case 34: goto tr2;
201
+ case 47: goto st11;
202
+ }
203
+ if ( 9 <= (*p) && (*p) <= 10 )
204
+ goto st10;
205
+ goto st0;
206
+ st11:
207
+ if ( ++p == pe )
208
+ goto _out11;
209
+ case 11:
210
+ switch( (*p) ) {
211
+ case 42: goto st12;
212
+ case 47: goto st14;
213
+ }
214
+ goto st0;
215
+ st12:
216
+ if ( ++p == pe )
217
+ goto _out12;
218
+ case 12:
219
+ if ( (*p) == 42 )
220
+ goto st13;
221
+ goto st12;
222
+ st13:
223
+ if ( ++p == pe )
224
+ goto _out13;
225
+ case 13:
226
+ switch( (*p) ) {
227
+ case 42: goto st13;
228
+ case 47: goto st10;
229
+ }
230
+ goto st12;
231
+ st14:
232
+ if ( ++p == pe )
233
+ goto _out14;
234
+ case 14:
235
+ if ( (*p) == 10 )
236
+ goto st10;
237
+ goto st14;
238
+ st15:
239
+ if ( ++p == pe )
240
+ goto _out15;
241
+ case 15:
242
+ switch( (*p) ) {
243
+ case 42: goto st16;
244
+ case 47: goto st18;
245
+ }
246
+ goto st0;
247
+ st16:
248
+ if ( ++p == pe )
249
+ goto _out16;
250
+ case 16:
251
+ if ( (*p) == 42 )
252
+ goto st17;
253
+ goto st16;
254
+ st17:
255
+ if ( ++p == pe )
256
+ goto _out17;
257
+ case 17:
258
+ switch( (*p) ) {
259
+ case 42: goto st17;
260
+ case 47: goto st9;
261
+ }
262
+ goto st16;
263
+ st18:
264
+ if ( ++p == pe )
265
+ goto _out18;
266
+ case 18:
267
+ if ( (*p) == 10 )
268
+ goto st9;
269
+ goto st18;
270
+ tr4:
271
+ #line 83 "parser.rl"
272
+ { goto _out27; }
273
+ goto st27;
274
+ st27:
275
+ if ( ++p == pe )
276
+ goto _out27;
277
+ case 27:
278
+ #line 279 "parser.c"
279
+ goto st0;
280
+ st19:
281
+ if ( ++p == pe )
282
+ goto _out19;
283
+ case 19:
284
+ switch( (*p) ) {
285
+ case 42: goto st20;
286
+ case 47: goto st22;
287
+ }
288
+ goto st0;
289
+ st20:
290
+ if ( ++p == pe )
291
+ goto _out20;
292
+ case 20:
293
+ if ( (*p) == 42 )
294
+ goto st21;
295
+ goto st20;
296
+ st21:
297
+ if ( ++p == pe )
298
+ goto _out21;
299
+ case 21:
300
+ switch( (*p) ) {
301
+ case 42: goto st21;
302
+ case 47: goto st8;
303
+ }
304
+ goto st20;
305
+ st22:
306
+ if ( ++p == pe )
307
+ goto _out22;
308
+ case 22:
309
+ if ( (*p) == 10 )
310
+ goto st8;
311
+ goto st22;
312
+ st23:
313
+ if ( ++p == pe )
314
+ goto _out23;
315
+ case 23:
316
+ switch( (*p) ) {
317
+ case 42: goto st24;
318
+ case 47: goto st26;
319
+ }
320
+ goto st0;
321
+ st24:
322
+ if ( ++p == pe )
323
+ goto _out24;
324
+ case 24:
325
+ if ( (*p) == 42 )
326
+ goto st25;
327
+ goto st24;
328
+ st25:
329
+ if ( ++p == pe )
330
+ goto _out25;
331
+ case 25:
332
+ switch( (*p) ) {
333
+ case 42: goto st25;
334
+ case 47: goto st2;
335
+ }
336
+ goto st24;
337
+ st26:
338
+ if ( ++p == pe )
339
+ goto _out26;
340
+ case 26:
341
+ if ( (*p) == 10 )
342
+ goto st2;
343
+ goto st26;
344
+ }
345
+ _out0: cs = 0; goto _out;
346
+ _out2: cs = 2; goto _out;
347
+ _out3: cs = 3; goto _out;
348
+ _out4: cs = 4; goto _out;
349
+ _out5: cs = 5; goto _out;
350
+ _out6: cs = 6; goto _out;
351
+ _out7: cs = 7; goto _out;
352
+ _out8: cs = 8; goto _out;
353
+ _out9: cs = 9; goto _out;
354
+ _out10: cs = 10; goto _out;
355
+ _out11: cs = 11; goto _out;
356
+ _out12: cs = 12; goto _out;
357
+ _out13: cs = 13; goto _out;
358
+ _out14: cs = 14; goto _out;
359
+ _out15: cs = 15; goto _out;
360
+ _out16: cs = 16; goto _out;
361
+ _out17: cs = 17; goto _out;
362
+ _out18: cs = 18; goto _out;
363
+ _out27: cs = 27; goto _out;
364
+ _out19: cs = 19; goto _out;
365
+ _out20: cs = 20; goto _out;
366
+ _out21: cs = 21; goto _out;
367
+ _out22: cs = 22; goto _out;
368
+ _out23: cs = 23; goto _out;
369
+ _out24: cs = 24; goto _out;
370
+ _out25: cs = 25; goto _out;
371
+ _out26: cs = 26; goto _out;
372
+
373
+ _out: {}
374
+ }
375
+ #line 102 "parser.rl"
376
+
377
+ if (cs >= JSON_object_first_final) {
378
+ VALUE klassname = rb_hash_aref(*result, json->create_id);
379
+ if (!NIL_P(klassname)) {
380
+ VALUE klass = rb_path2class(StringValueCStr(klassname));
381
+ if RTEST(rb_funcall(klass, i_json_creatable_p, 0)) {
382
+ *result = rb_funcall(klass, i_json_create, 1, *result);
383
+ }
384
+ }
385
+ return p + 1;
386
+ } else {
387
+ return NULL;
388
+ }
389
+ }
390
+
391
+
392
+ #line 393 "parser.c"
393
+ static const int JSON_value_start = 1;
394
+ static const int JSON_value_first_final = 12;
395
+ static const int JSON_value_error = 0;
396
+
397
+ static const int JSON_value_en_main = 1;
398
+
399
+ #line 167 "parser.rl"
400
+
401
+
402
+ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
403
+ {
404
+ int cs = EVIL;
405
+
406
+
407
+ #line 408 "parser.c"
408
+ {
409
+ cs = JSON_value_start;
410
+ }
411
+ #line 174 "parser.rl"
412
+
413
+ #line 414 "parser.c"
414
+ {
415
+ if ( p == pe )
416
+ goto _out;
417
+ switch ( cs )
418
+ {
419
+ case 1:
420
+ switch( (*p) ) {
421
+ case 34: goto tr0;
422
+ case 45: goto tr2;
423
+ case 91: goto tr3;
424
+ case 102: goto st2;
425
+ case 110: goto st6;
426
+ case 116: goto st9;
427
+ case 123: goto tr7;
428
+ }
429
+ if ( 48 <= (*p) && (*p) <= 57 )
430
+ goto tr2;
431
+ goto st0;
432
+ st0:
433
+ goto _out0;
434
+ tr0:
435
+ #line 132 "parser.rl"
436
+ {
437
+ char *np = JSON_parse_string(json, p, pe, result);
438
+ if (np == NULL) goto _out12; else {p = (( np))-1;}
439
+ }
440
+ goto st12;
441
+ tr2:
442
+ #line 137 "parser.rl"
443
+ {
444
+ char *np;
445
+ np = JSON_parse_float(json, p, pe, result);
446
+ if (np != NULL) {p = (( np))-1;}
447
+ np = JSON_parse_integer(json, p, pe, result);
448
+ if (np != NULL) {p = (( np))-1;}
449
+ goto _out12;
450
+ }
451
+ goto st12;
452
+ tr3:
453
+ #line 146 "parser.rl"
454
+ {
455
+ char *np = JSON_parse_array(json, p, pe, result);
456
+ if (np == NULL) goto _out12; else {p = (( np))-1;}
457
+ }
458
+ goto st12;
459
+ tr7:
460
+ #line 151 "parser.rl"
461
+ {
462
+ char *np = JSON_parse_object(json, p, pe, result);
463
+ if (np == NULL) goto _out12; else {p = (( np))-1;}
464
+ }
465
+ goto st12;
466
+ tr11:
467
+ #line 126 "parser.rl"
468
+ {
469
+ *result = Qfalse;
470
+ }
471
+ goto st12;
472
+ tr14:
473
+ #line 123 "parser.rl"
474
+ {
475
+ *result = Qnil;
476
+ }
477
+ goto st12;
478
+ tr17:
479
+ #line 129 "parser.rl"
480
+ {
481
+ *result = Qtrue;
482
+ }
483
+ goto st12;
484
+ st12:
485
+ if ( ++p == pe )
486
+ goto _out12;
487
+ case 12:
488
+ #line 156 "parser.rl"
489
+ { goto _out12; }
490
+ #line 491 "parser.c"
491
+ goto st0;
492
+ st2:
493
+ if ( ++p == pe )
494
+ goto _out2;
495
+ case 2:
496
+ if ( (*p) == 97 )
497
+ goto st3;
498
+ goto st0;
499
+ st3:
500
+ if ( ++p == pe )
501
+ goto _out3;
502
+ case 3:
503
+ if ( (*p) == 108 )
504
+ goto st4;
505
+ goto st0;
506
+ st4:
507
+ if ( ++p == pe )
508
+ goto _out4;
509
+ case 4:
510
+ if ( (*p) == 115 )
511
+ goto st5;
512
+ goto st0;
513
+ st5:
514
+ if ( ++p == pe )
515
+ goto _out5;
516
+ case 5:
517
+ if ( (*p) == 101 )
518
+ goto tr11;
519
+ goto st0;
520
+ st6:
521
+ if ( ++p == pe )
522
+ goto _out6;
523
+ case 6:
524
+ if ( (*p) == 117 )
525
+ goto st7;
526
+ goto st0;
527
+ st7:
528
+ if ( ++p == pe )
529
+ goto _out7;
530
+ case 7:
531
+ if ( (*p) == 108 )
532
+ goto st8;
533
+ goto st0;
534
+ st8:
535
+ if ( ++p == pe )
536
+ goto _out8;
537
+ case 8:
538
+ if ( (*p) == 108 )
539
+ goto tr14;
540
+ goto st0;
541
+ st9:
542
+ if ( ++p == pe )
543
+ goto _out9;
544
+ case 9:
545
+ if ( (*p) == 114 )
546
+ goto st10;
547
+ goto st0;
548
+ st10:
549
+ if ( ++p == pe )
550
+ goto _out10;
551
+ case 10:
552
+ if ( (*p) == 117 )
553
+ goto st11;
554
+ goto st0;
555
+ st11:
556
+ if ( ++p == pe )
557
+ goto _out11;
558
+ case 11:
559
+ if ( (*p) == 101 )
560
+ goto tr17;
561
+ goto st0;
562
+ }
563
+ _out0: cs = 0; goto _out;
564
+ _out12: cs = 12; goto _out;
565
+ _out2: cs = 2; goto _out;
566
+ _out3: cs = 3; goto _out;
567
+ _out4: cs = 4; goto _out;
568
+ _out5: cs = 5; goto _out;
569
+ _out6: cs = 6; goto _out;
570
+ _out7: cs = 7; goto _out;
571
+ _out8: cs = 8; goto _out;
572
+ _out9: cs = 9; goto _out;
573
+ _out10: cs = 10; goto _out;
574
+ _out11: cs = 11; goto _out;
575
+
576
+ _out: {}
577
+ }
578
+ #line 175 "parser.rl"
579
+
580
+ if (cs >= JSON_value_first_final) {
581
+ return p;
582
+ } else {
583
+ return NULL;
584
+ }
585
+ }
586
+
587
+
588
+ #line 589 "parser.c"
589
+ static const int JSON_integer_start = 1;
590
+ static const int JSON_integer_first_final = 5;
591
+ static const int JSON_integer_error = 0;
592
+
593
+ static const int JSON_integer_en_main = 1;
594
+
595
+ #line 191 "parser.rl"
596
+
597
+
598
+ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
599
+ {
600
+ int cs = EVIL;
601
+
602
+
603
+ #line 604 "parser.c"
604
+ {
605
+ cs = JSON_integer_start;
606
+ }
607
+ #line 198 "parser.rl"
608
+ json->memo = p;
609
+
610
+ #line 611 "parser.c"
611
+ {
612
+ if ( p == pe )
613
+ goto _out;
614
+ switch ( cs )
615
+ {
616
+ case 1:
617
+ switch( (*p) ) {
618
+ case 45: goto st2;
619
+ case 48: goto st3;
620
+ }
621
+ if ( 49 <= (*p) && (*p) <= 57 )
622
+ goto st4;
623
+ goto st0;
624
+ st0:
625
+ goto _out0;
626
+ st2:
627
+ if ( ++p == pe )
628
+ goto _out2;
629
+ case 2:
630
+ if ( (*p) == 48 )
631
+ goto st3;
632
+ if ( 49 <= (*p) && (*p) <= 57 )
633
+ goto st4;
634
+ goto st0;
635
+ st3:
636
+ if ( ++p == pe )
637
+ goto _out3;
638
+ case 3:
639
+ if ( 48 <= (*p) && (*p) <= 57 )
640
+ goto st0;
641
+ goto tr4;
642
+ tr4:
643
+ #line 188 "parser.rl"
644
+ { goto _out5; }
645
+ goto st5;
646
+ st5:
647
+ if ( ++p == pe )
648
+ goto _out5;
649
+ case 5:
650
+ #line 651 "parser.c"
651
+ goto st0;
652
+ st4:
653
+ if ( ++p == pe )
654
+ goto _out4;
655
+ case 4:
656
+ if ( 48 <= (*p) && (*p) <= 57 )
657
+ goto st4;
658
+ goto tr4;
659
+ }
660
+ _out0: cs = 0; goto _out;
661
+ _out2: cs = 2; goto _out;
662
+ _out3: cs = 3; goto _out;
663
+ _out5: cs = 5; goto _out;
664
+ _out4: cs = 4; goto _out;
665
+
666
+ _out: {}
667
+ }
668
+ #line 200 "parser.rl"
669
+
670
+ if (cs >= JSON_integer_first_final) {
671
+ long len = p - json->memo;
672
+ *result = rb_Integer(rb_str_new(json->memo, len));
673
+ return p + 1;
674
+ } else {
675
+ return NULL;
676
+ }
677
+ }
678
+
679
+
680
+ #line 681 "parser.c"
681
+ static const int JSON_float_start = 1;
682
+ static const int JSON_float_first_final = 10;
683
+ static const int JSON_float_error = 0;
684
+
685
+ static const int JSON_float_en_main = 1;
686
+
687
+ #line 222 "parser.rl"
688
+
689
+
690
+ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
691
+ {
692
+ int cs = EVIL;
693
+
694
+
695
+ #line 696 "parser.c"
696
+ {
697
+ cs = JSON_float_start;
698
+ }
699
+ #line 229 "parser.rl"
700
+ json->memo = p;
701
+
702
+ #line 703 "parser.c"
703
+ {
704
+ if ( p == pe )
705
+ goto _out;
706
+ switch ( cs )
707
+ {
708
+ case 1:
709
+ switch( (*p) ) {
710
+ case 45: goto st2;
711
+ case 48: goto st3;
712
+ }
713
+ if ( 49 <= (*p) && (*p) <= 57 )
714
+ goto st9;
715
+ goto st0;
716
+ st0:
717
+ goto _out0;
718
+ st2:
719
+ if ( ++p == pe )
720
+ goto _out2;
721
+ case 2:
722
+ if ( (*p) == 48 )
723
+ goto st3;
724
+ if ( 49 <= (*p) && (*p) <= 57 )
725
+ goto st9;
726
+ goto st0;
727
+ st3:
728
+ if ( ++p == pe )
729
+ goto _out3;
730
+ case 3:
731
+ switch( (*p) ) {
732
+ case 46: goto st4;
733
+ case 69: goto st6;
734
+ case 101: goto st6;
735
+ }
736
+ goto st0;
737
+ st4:
738
+ if ( ++p == pe )
739
+ goto _out4;
740
+ case 4:
741
+ if ( 48 <= (*p) && (*p) <= 57 )
742
+ goto st5;
743
+ goto st0;
744
+ st5:
745
+ if ( ++p == pe )
746
+ goto _out5;
747
+ case 5:
748
+ switch( (*p) ) {
749
+ case 69: goto st6;
750
+ case 101: goto st6;
751
+ }
752
+ if ( (*p) > 46 ) {
753
+ if ( 48 <= (*p) && (*p) <= 57 )
754
+ goto st5;
755
+ } else if ( (*p) >= 45 )
756
+ goto st0;
757
+ goto tr7;
758
+ tr7:
759
+ #line 216 "parser.rl"
760
+ { goto _out10; }
761
+ goto st10;
762
+ st10:
763
+ if ( ++p == pe )
764
+ goto _out10;
765
+ case 10:
766
+ #line 767 "parser.c"
767
+ goto st0;
768
+ st6:
769
+ if ( ++p == pe )
770
+ goto _out6;
771
+ case 6:
772
+ switch( (*p) ) {
773
+ case 43: goto st7;
774
+ case 45: goto st7;
775
+ }
776
+ if ( 48 <= (*p) && (*p) <= 57 )
777
+ goto st8;
778
+ goto st0;
779
+ st7:
780
+ if ( ++p == pe )
781
+ goto _out7;
782
+ case 7:
783
+ if ( 48 <= (*p) && (*p) <= 57 )
784
+ goto st8;
785
+ goto st0;
786
+ st8:
787
+ if ( ++p == pe )
788
+ goto _out8;
789
+ case 8:
790
+ switch( (*p) ) {
791
+ case 69: goto st0;
792
+ case 101: goto st0;
793
+ }
794
+ if ( (*p) > 46 ) {
795
+ if ( 48 <= (*p) && (*p) <= 57 )
796
+ goto st8;
797
+ } else if ( (*p) >= 45 )
798
+ goto st0;
799
+ goto tr7;
800
+ st9:
801
+ if ( ++p == pe )
802
+ goto _out9;
803
+ case 9:
804
+ switch( (*p) ) {
805
+ case 46: goto st4;
806
+ case 69: goto st6;
807
+ case 101: goto st6;
808
+ }
809
+ if ( 48 <= (*p) && (*p) <= 57 )
810
+ goto st9;
811
+ goto st0;
812
+ }
813
+ _out0: cs = 0; goto _out;
814
+ _out2: cs = 2; goto _out;
815
+ _out3: cs = 3; goto _out;
816
+ _out4: cs = 4; goto _out;
817
+ _out5: cs = 5; goto _out;
818
+ _out10: cs = 10; goto _out;
819
+ _out6: cs = 6; goto _out;
820
+ _out7: cs = 7; goto _out;
821
+ _out8: cs = 8; goto _out;
822
+ _out9: cs = 9; goto _out;
823
+
824
+ _out: {}
825
+ }
826
+ #line 231 "parser.rl"
827
+
828
+ if (cs >= JSON_float_first_final) {
829
+ long len = p - json->memo;
830
+ *result = rb_Float(rb_str_new(json->memo, len));
831
+ return p + 1;
832
+ } else {
833
+ return NULL;
834
+ }
835
+ }
836
+
837
+
838
+
839
+ #line 840 "parser.c"
840
+ static const int JSON_array_start = 1;
841
+ static const int JSON_array_first_final = 17;
842
+ static const int JSON_array_error = 0;
843
+
844
+ static const int JSON_array_en_main = 1;
845
+
846
+ #line 267 "parser.rl"
847
+
848
+
849
+ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
850
+ {
851
+ int cs = EVIL;
852
+ *result = rb_ary_new();
853
+
854
+
855
+ #line 856 "parser.c"
856
+ {
857
+ cs = JSON_array_start;
858
+ }
859
+ #line 275 "parser.rl"
860
+
861
+ #line 862 "parser.c"
862
+ {
863
+ if ( p == pe )
864
+ goto _out;
865
+ switch ( cs )
866
+ {
867
+ case 1:
868
+ if ( (*p) == 91 )
869
+ goto st2;
870
+ goto st0;
871
+ st0:
872
+ goto _out0;
873
+ st2:
874
+ if ( ++p == pe )
875
+ goto _out2;
876
+ case 2:
877
+ switch( (*p) ) {
878
+ case 13: goto st2;
879
+ case 32: goto st2;
880
+ case 34: goto tr2;
881
+ case 45: goto tr2;
882
+ case 47: goto st13;
883
+ case 91: goto tr2;
884
+ case 93: goto tr4;
885
+ case 102: goto tr2;
886
+ case 110: goto tr2;
887
+ case 116: goto tr2;
888
+ case 123: goto tr2;
889
+ }
890
+ if ( (*p) > 10 ) {
891
+ if ( 48 <= (*p) && (*p) <= 57 )
892
+ goto tr2;
893
+ } else if ( (*p) >= 9 )
894
+ goto st2;
895
+ goto st0;
896
+ tr2:
897
+ #line 248 "parser.rl"
898
+ {
899
+ VALUE v = Qnil;
900
+ char *np = JSON_parse_value(json, p, pe, &v);
901
+ if (np == NULL) {
902
+ goto _out3;
903
+ } else {
904
+ rb_ary_push(*result, v);
905
+ {p = (( np))-1;}
906
+ }
907
+ }
908
+ goto st3;
909
+ st3:
910
+ if ( ++p == pe )
911
+ goto _out3;
912
+ case 3:
913
+ #line 914 "parser.c"
914
+ switch( (*p) ) {
915
+ case 13: goto st3;
916
+ case 32: goto st3;
917
+ case 44: goto st4;
918
+ case 47: goto st9;
919
+ case 93: goto tr4;
920
+ }
921
+ if ( 9 <= (*p) && (*p) <= 10 )
922
+ goto st3;
923
+ goto st0;
924
+ st4:
925
+ if ( ++p == pe )
926
+ goto _out4;
927
+ case 4:
928
+ switch( (*p) ) {
929
+ case 13: goto st4;
930
+ case 32: goto st4;
931
+ case 34: goto tr2;
932
+ case 45: goto tr2;
933
+ case 47: goto st5;
934
+ case 91: goto tr2;
935
+ case 102: goto tr2;
936
+ case 110: goto tr2;
937
+ case 116: goto tr2;
938
+ case 123: goto tr2;
939
+ }
940
+ if ( (*p) > 10 ) {
941
+ if ( 48 <= (*p) && (*p) <= 57 )
942
+ goto tr2;
943
+ } else if ( (*p) >= 9 )
944
+ goto st4;
945
+ goto st0;
946
+ st5:
947
+ if ( ++p == pe )
948
+ goto _out5;
949
+ case 5:
950
+ switch( (*p) ) {
951
+ case 42: goto st6;
952
+ case 47: goto st8;
953
+ }
954
+ goto st0;
955
+ st6:
956
+ if ( ++p == pe )
957
+ goto _out6;
958
+ case 6:
959
+ if ( (*p) == 42 )
960
+ goto st7;
961
+ goto st6;
962
+ st7:
963
+ if ( ++p == pe )
964
+ goto _out7;
965
+ case 7:
966
+ switch( (*p) ) {
967
+ case 42: goto st7;
968
+ case 47: goto st4;
969
+ }
970
+ goto st6;
971
+ st8:
972
+ if ( ++p == pe )
973
+ goto _out8;
974
+ case 8:
975
+ if ( (*p) == 10 )
976
+ goto st4;
977
+ goto st8;
978
+ st9:
979
+ if ( ++p == pe )
980
+ goto _out9;
981
+ case 9:
982
+ switch( (*p) ) {
983
+ case 42: goto st10;
984
+ case 47: goto st12;
985
+ }
986
+ goto st0;
987
+ st10:
988
+ if ( ++p == pe )
989
+ goto _out10;
990
+ case 10:
991
+ if ( (*p) == 42 )
992
+ goto st11;
993
+ goto st10;
994
+ st11:
995
+ if ( ++p == pe )
996
+ goto _out11;
997
+ case 11:
998
+ switch( (*p) ) {
999
+ case 42: goto st11;
1000
+ case 47: goto st3;
1001
+ }
1002
+ goto st10;
1003
+ st12:
1004
+ if ( ++p == pe )
1005
+ goto _out12;
1006
+ case 12:
1007
+ if ( (*p) == 10 )
1008
+ goto st3;
1009
+ goto st12;
1010
+ tr4:
1011
+ #line 259 "parser.rl"
1012
+ { goto _out17; }
1013
+ goto st17;
1014
+ st17:
1015
+ if ( ++p == pe )
1016
+ goto _out17;
1017
+ case 17:
1018
+ #line 1019 "parser.c"
1019
+ goto st0;
1020
+ st13:
1021
+ if ( ++p == pe )
1022
+ goto _out13;
1023
+ case 13:
1024
+ switch( (*p) ) {
1025
+ case 42: goto st14;
1026
+ case 47: goto st16;
1027
+ }
1028
+ goto st0;
1029
+ st14:
1030
+ if ( ++p == pe )
1031
+ goto _out14;
1032
+ case 14:
1033
+ if ( (*p) == 42 )
1034
+ goto st15;
1035
+ goto st14;
1036
+ st15:
1037
+ if ( ++p == pe )
1038
+ goto _out15;
1039
+ case 15:
1040
+ switch( (*p) ) {
1041
+ case 42: goto st15;
1042
+ case 47: goto st2;
1043
+ }
1044
+ goto st14;
1045
+ st16:
1046
+ if ( ++p == pe )
1047
+ goto _out16;
1048
+ case 16:
1049
+ if ( (*p) == 10 )
1050
+ goto st2;
1051
+ goto st16;
1052
+ }
1053
+ _out0: cs = 0; goto _out;
1054
+ _out2: cs = 2; goto _out;
1055
+ _out3: cs = 3; goto _out;
1056
+ _out4: cs = 4; goto _out;
1057
+ _out5: cs = 5; goto _out;
1058
+ _out6: cs = 6; goto _out;
1059
+ _out7: cs = 7; goto _out;
1060
+ _out8: cs = 8; goto _out;
1061
+ _out9: cs = 9; goto _out;
1062
+ _out10: cs = 10; goto _out;
1063
+ _out11: cs = 11; goto _out;
1064
+ _out12: cs = 12; goto _out;
1065
+ _out17: cs = 17; goto _out;
1066
+ _out13: cs = 13; goto _out;
1067
+ _out14: cs = 14; goto _out;
1068
+ _out15: cs = 15; goto _out;
1069
+ _out16: cs = 16; goto _out;
1070
+
1071
+ _out: {}
1072
+ }
1073
+ #line 276 "parser.rl"
1074
+
1075
+ if(cs >= JSON_array_first_final) {
1076
+ return p + 1;
1077
+ } else {
1078
+ rb_raise(eParserError, "unexpected token at '%s'", p);
1079
+ }
1080
+ }
1081
+
1082
+ static VALUE json_string_escape(char *p, char *pe)
1083
+ {
1084
+ VALUE result = rb_str_buf_new(pe - p + 1);
1085
+
1086
+ while (p < pe) {
1087
+ if (*p == '\\') {
1088
+ p++;
1089
+ if (p >= pe) return Qnil; /* raise an exception later, \ at end */
1090
+ switch (*p) {
1091
+ case '"':
1092
+ case '\\':
1093
+ rb_str_buf_cat(result, p, 1);
1094
+ p++;
1095
+ break;
1096
+ case 'b':
1097
+ rb_str_buf_cat2(result, "\b");
1098
+ p++;
1099
+ break;
1100
+ case 'f':
1101
+ rb_str_buf_cat2(result, "\f");
1102
+ p++;
1103
+ break;
1104
+ case 'n':
1105
+ rb_str_buf_cat2(result, "\n");
1106
+ p++;
1107
+ break;
1108
+ case 'r':
1109
+ rb_str_buf_cat2(result, "\r");
1110
+ p++;
1111
+ break;
1112
+ case 't':
1113
+ rb_str_buf_cat2(result, "\t");
1114
+ p++;
1115
+ break;
1116
+ case 'u':
1117
+ if (p > pe - 4) {
1118
+ return Qnil;
1119
+ } else {
1120
+ p = JSON_convert_UTF16_to_UTF8(result, p, pe, strictConversion);
1121
+ }
1122
+ break;
1123
+ }
1124
+ } else {
1125
+ char *q = p;
1126
+ while (*q != '\\' && q < pe) q++;
1127
+ rb_str_buf_cat(result, p, q - p);
1128
+ p = q;
1129
+ }
1130
+ }
1131
+ return result;
1132
+ }
1133
+
1134
+
1135
+ #line 1136 "parser.c"
1136
+ static const int JSON_string_start = 1;
1137
+ static const int JSON_string_first_final = 8;
1138
+ static const int JSON_string_error = 0;
1139
+
1140
+ static const int JSON_string_en_main = 1;
1141
+
1142
+ #line 350 "parser.rl"
1143
+
1144
+
1145
+ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
1146
+ {
1147
+ int cs = EVIL;
1148
+
1149
+ *result = rb_str_new("", 0);
1150
+
1151
+ #line 1152 "parser.c"
1152
+ {
1153
+ cs = JSON_string_start;
1154
+ }
1155
+ #line 358 "parser.rl"
1156
+ json->memo = p;
1157
+
1158
+ #line 1159 "parser.c"
1159
+ {
1160
+ if ( p == pe )
1161
+ goto _out;
1162
+ switch ( cs )
1163
+ {
1164
+ case 1:
1165
+ if ( (*p) == 34 )
1166
+ goto st2;
1167
+ goto st0;
1168
+ st0:
1169
+ goto _out0;
1170
+ st2:
1171
+ if ( ++p == pe )
1172
+ goto _out2;
1173
+ case 2:
1174
+ switch( (*p) ) {
1175
+ case 34: goto tr2;
1176
+ case 92: goto st3;
1177
+ }
1178
+ if ( 0 <= (*p) && (*p) <= 31 )
1179
+ goto st0;
1180
+ goto st2;
1181
+ tr2:
1182
+ #line 342 "parser.rl"
1183
+ {
1184
+ *result = json_string_escape(json->memo + 1, p);
1185
+ if (NIL_P(*result)) goto _out8; else {p = (( p + 1))-1;}
1186
+ }
1187
+ #line 347 "parser.rl"
1188
+ { goto _out8; }
1189
+ goto st8;
1190
+ st8:
1191
+ if ( ++p == pe )
1192
+ goto _out8;
1193
+ case 8:
1194
+ #line 1195 "parser.c"
1195
+ goto st0;
1196
+ st3:
1197
+ if ( ++p == pe )
1198
+ goto _out3;
1199
+ case 3:
1200
+ switch( (*p) ) {
1201
+ case 34: goto st2;
1202
+ case 47: goto st2;
1203
+ case 92: goto st2;
1204
+ case 98: goto st2;
1205
+ case 102: goto st2;
1206
+ case 110: goto st2;
1207
+ case 114: goto st2;
1208
+ case 116: goto st2;
1209
+ case 117: goto st4;
1210
+ }
1211
+ goto st0;
1212
+ st4:
1213
+ if ( ++p == pe )
1214
+ goto _out4;
1215
+ case 4:
1216
+ if ( (*p) < 65 ) {
1217
+ if ( 48 <= (*p) && (*p) <= 57 )
1218
+ goto st5;
1219
+ } else if ( (*p) > 70 ) {
1220
+ if ( 97 <= (*p) && (*p) <= 102 )
1221
+ goto st5;
1222
+ } else
1223
+ goto st5;
1224
+ goto st0;
1225
+ st5:
1226
+ if ( ++p == pe )
1227
+ goto _out5;
1228
+ case 5:
1229
+ if ( (*p) < 65 ) {
1230
+ if ( 48 <= (*p) && (*p) <= 57 )
1231
+ goto st6;
1232
+ } else if ( (*p) > 70 ) {
1233
+ if ( 97 <= (*p) && (*p) <= 102 )
1234
+ goto st6;
1235
+ } else
1236
+ goto st6;
1237
+ goto st0;
1238
+ st6:
1239
+ if ( ++p == pe )
1240
+ goto _out6;
1241
+ case 6:
1242
+ if ( (*p) < 65 ) {
1243
+ if ( 48 <= (*p) && (*p) <= 57 )
1244
+ goto st7;
1245
+ } else if ( (*p) > 70 ) {
1246
+ if ( 97 <= (*p) && (*p) <= 102 )
1247
+ goto st7;
1248
+ } else
1249
+ goto st7;
1250
+ goto st0;
1251
+ st7:
1252
+ if ( ++p == pe )
1253
+ goto _out7;
1254
+ case 7:
1255
+ if ( (*p) < 65 ) {
1256
+ if ( 48 <= (*p) && (*p) <= 57 )
1257
+ goto st2;
1258
+ } else if ( (*p) > 70 ) {
1259
+ if ( 97 <= (*p) && (*p) <= 102 )
1260
+ goto st2;
1261
+ } else
1262
+ goto st2;
1263
+ goto st0;
1264
+ }
1265
+ _out0: cs = 0; goto _out;
1266
+ _out2: cs = 2; goto _out;
1267
+ _out8: cs = 8; goto _out;
1268
+ _out3: cs = 3; goto _out;
1269
+ _out4: cs = 4; goto _out;
1270
+ _out5: cs = 5; goto _out;
1271
+ _out6: cs = 6; goto _out;
1272
+ _out7: cs = 7; goto _out;
1273
+
1274
+ _out: {}
1275
+ }
1276
+ #line 360 "parser.rl"
1277
+
1278
+ if (cs >= JSON_string_first_final) {
1279
+ return p + 1;
1280
+ } else {
1281
+ return NULL;
1282
+ }
1283
+ }
1284
+
1285
+
1286
+
1287
+ #line 1288 "parser.c"
1288
+ static const int JSON_start = 1;
1289
+ static const int JSON_first_final = 10;
1290
+ static const int JSON_error = 0;
1291
+
1292
+ static const int JSON_en_main = 1;
1293
+
1294
+ #line 390 "parser.rl"
1295
+
1296
+
1297
+ /*
1298
+ * Document-class: JSON::Ext::Parser
1299
+ *
1300
+ * This is the JSON parser implemented as a C extension. It can be configured
1301
+ * to be used by setting
1302
+ *
1303
+ * JSON.parser = JSON::Ext::Parser
1304
+ *
1305
+ * with the method parser= in JSON.
1306
+ *
1307
+ */
1308
+
1309
+ /*
1310
+ * call-seq: new(source)
1311
+ *
1312
+ * Creates a new JSON::Ext::Parser instance for the string _source_.
1313
+ */
1314
+ static VALUE cParser_initialize(VALUE self, VALUE source)
1315
+ {
1316
+ char *ptr;
1317
+ long len;
1318
+ GET_STRUCT;
1319
+ source = StringValue(source);
1320
+ ptr = RSTRING(source)->ptr;
1321
+ len = RSTRING(source)->len;
1322
+ if (len < 2) {
1323
+ rb_raise(eParserError, "A JSON text must at least contain two octets!");
1324
+ }
1325
+ /*
1326
+ Convert these?
1327
+ if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1328
+ rb_raise(eParserError, "Only UTF8 octet streams are supported atm!");
1329
+ } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1330
+ rb_raise(eParserError, "Only UTF8 octet streams are supported atm!");
1331
+ } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1332
+ rb_raise(eParserError, "Only UTF8 octet streams are supported atm!");
1333
+ } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1334
+ rb_raise(eParserError, "Only UTF8 octet streams are supported atm!");
1335
+ }
1336
+ */
1337
+ json->len = len;
1338
+ json->source = ptr;
1339
+ json->Vsource = source;
1340
+ json->create_id = rb_funcall(mJSON, i_create_id, 0);
1341
+ return self;
1342
+ }
1343
+
1344
+ /*
1345
+ * call-seq: parse()
1346
+ *
1347
+ * Parses the current JSON text _source_ and returns the complete data
1348
+ * structure as a result.
1349
+ */
1350
+ static VALUE cParser_parse(VALUE self)
1351
+ {
1352
+ char *p, *pe;
1353
+ int cs = EVIL;
1354
+ VALUE result = Qnil;
1355
+ GET_STRUCT;
1356
+
1357
+
1358
+ #line 1359 "parser.c"
1359
+ {
1360
+ cs = JSON_start;
1361
+ }
1362
+ #line 453 "parser.rl"
1363
+ p = json->source;
1364
+ pe = p + json->len;
1365
+
1366
+ #line 1367 "parser.c"
1367
+ {
1368
+ if ( p == pe )
1369
+ goto _out;
1370
+ switch ( cs )
1371
+ {
1372
+ st1:
1373
+ if ( ++p == pe )
1374
+ goto _out1;
1375
+ case 1:
1376
+ switch( (*p) ) {
1377
+ case 13: goto st1;
1378
+ case 32: goto st1;
1379
+ case 47: goto st2;
1380
+ case 91: goto tr3;
1381
+ case 123: goto tr4;
1382
+ }
1383
+ if ( 9 <= (*p) && (*p) <= 10 )
1384
+ goto st1;
1385
+ goto st0;
1386
+ st0:
1387
+ goto _out0;
1388
+ st2:
1389
+ if ( ++p == pe )
1390
+ goto _out2;
1391
+ case 2:
1392
+ switch( (*p) ) {
1393
+ case 42: goto st3;
1394
+ case 47: goto st5;
1395
+ }
1396
+ goto st0;
1397
+ st3:
1398
+ if ( ++p == pe )
1399
+ goto _out3;
1400
+ case 3:
1401
+ if ( (*p) == 42 )
1402
+ goto st4;
1403
+ goto st3;
1404
+ st4:
1405
+ if ( ++p == pe )
1406
+ goto _out4;
1407
+ case 4:
1408
+ switch( (*p) ) {
1409
+ case 42: goto st4;
1410
+ case 47: goto st1;
1411
+ }
1412
+ goto st3;
1413
+ st5:
1414
+ if ( ++p == pe )
1415
+ goto _out5;
1416
+ case 5:
1417
+ if ( (*p) == 10 )
1418
+ goto st1;
1419
+ goto st5;
1420
+ tr3:
1421
+ #line 381 "parser.rl"
1422
+ {
1423
+ char *np = JSON_parse_array(json, p, pe, &result);
1424
+ if (np == NULL) goto _out10; else {p = (( np))-1;}
1425
+ }
1426
+ goto st10;
1427
+ tr4:
1428
+ #line 376 "parser.rl"
1429
+ {
1430
+ char *np = JSON_parse_object(json, p, pe, &result);
1431
+ if (np == NULL) goto _out10; else {p = (( np))-1;}
1432
+ }
1433
+ goto st10;
1434
+ st10:
1435
+ if ( ++p == pe )
1436
+ goto _out10;
1437
+ case 10:
1438
+ #line 1439 "parser.c"
1439
+ switch( (*p) ) {
1440
+ case 13: goto st10;
1441
+ case 32: goto st10;
1442
+ case 47: goto st6;
1443
+ }
1444
+ if ( 9 <= (*p) && (*p) <= 10 )
1445
+ goto st10;
1446
+ goto st0;
1447
+ st6:
1448
+ if ( ++p == pe )
1449
+ goto _out6;
1450
+ case 6:
1451
+ switch( (*p) ) {
1452
+ case 42: goto st7;
1453
+ case 47: goto st9;
1454
+ }
1455
+ goto st0;
1456
+ st7:
1457
+ if ( ++p == pe )
1458
+ goto _out7;
1459
+ case 7:
1460
+ if ( (*p) == 42 )
1461
+ goto st8;
1462
+ goto st7;
1463
+ st8:
1464
+ if ( ++p == pe )
1465
+ goto _out8;
1466
+ case 8:
1467
+ switch( (*p) ) {
1468
+ case 42: goto st8;
1469
+ case 47: goto st10;
1470
+ }
1471
+ goto st7;
1472
+ st9:
1473
+ if ( ++p == pe )
1474
+ goto _out9;
1475
+ case 9:
1476
+ if ( (*p) == 10 )
1477
+ goto st10;
1478
+ goto st9;
1479
+ }
1480
+ _out1: cs = 1; goto _out;
1481
+ _out0: cs = 0; goto _out;
1482
+ _out2: cs = 2; goto _out;
1483
+ _out3: cs = 3; goto _out;
1484
+ _out4: cs = 4; goto _out;
1485
+ _out5: cs = 5; goto _out;
1486
+ _out10: cs = 10; goto _out;
1487
+ _out6: cs = 6; goto _out;
1488
+ _out7: cs = 7; goto _out;
1489
+ _out8: cs = 8; goto _out;
1490
+ _out9: cs = 9; goto _out;
1491
+
1492
+ _out: {}
1493
+ }
1494
+ #line 456 "parser.rl"
1495
+
1496
+ if (cs >= JSON_first_final && p == pe) {
1497
+ return result;
1498
+ } else {
1499
+ rb_raise(eParserError, "unexpected token at '%s'", p);
1500
+ }
1501
+ }
1502
+
1503
+ static JSON_Parser *JSON_allocate()
1504
+ {
1505
+ JSON_Parser *json = ALLOC(JSON_Parser);
1506
+ MEMZERO(json, JSON_Parser, 1);
1507
+ return json;
1508
+ }
1509
+
1510
+ static void JSON_mark(JSON_Parser *json)
1511
+ {
1512
+ rb_gc_mark_maybe(json->Vsource);
1513
+ rb_gc_mark_maybe(json->create_id);
1514
+ }
1515
+
1516
+ static void JSON_free(JSON_Parser *json)
1517
+ {
1518
+ free(json);
1519
+ }
1520
+
1521
+ static VALUE cJSON_parser_s_allocate(VALUE klass)
1522
+ {
1523
+ JSON_Parser *json = JSON_allocate();
1524
+ return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
1525
+ }
1526
+
1527
+ /*
1528
+ * call-seq: source()
1529
+ *
1530
+ * Returns a copy of the current _source_ string, that was used to construct
1531
+ * this Parser.
1532
+ */
1533
+ static VALUE cParser_source(VALUE self)
1534
+ {
1535
+ GET_STRUCT;
1536
+ return rb_str_dup(json->Vsource);
1537
+ }
1538
+
1539
+ void Init_parser()
1540
+ {
1541
+ mJSON = rb_define_module("JSON");
1542
+ mExt = rb_define_module_under(mJSON, "Ext");
1543
+ cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
1544
+ eParserError = rb_path2class("JSON::ParserError");
1545
+ rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
1546
+ rb_define_method(cParser, "initialize", cParser_initialize, 1);
1547
+ rb_define_method(cParser, "parse", cParser_parse, 0);
1548
+ rb_define_method(cParser, "source", cParser_source, 0);
1549
+
1550
+ i_json_creatable_p = rb_intern("json_creatable?");
1551
+ i_json_create = rb_intern("json_create");
1552
+ i_create_id = rb_intern("create_id");
1553
+ i_chr = rb_intern("chr");
1554
+ }