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