json_pure 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +6 -0
  2. data/COPYING-json-jruby +57 -0
  3. data/README-json-jruby.markdown +33 -0
  4. data/Rakefile +224 -119
  5. data/VERSION +1 -1
  6. data/benchmarks/generator2_benchmark.rb +1 -1
  7. data/benchmarks/generator_benchmark.rb +1 -1
  8. data/ext/json/ext/generator/generator.c +20 -20
  9. data/ext/json/ext/generator/generator.h +7 -7
  10. data/ext/json/ext/parser/extconf.rb +1 -0
  11. data/ext/json/ext/parser/parser.c +122 -88
  12. data/ext/json/ext/parser/parser.h +7 -0
  13. data/ext/json/ext/parser/parser.rl +54 -20
  14. data/java/lib/bytelist-1.0.6.jar +0 -0
  15. data/java/lib/jcodings.jar +0 -0
  16. data/java/src/json/ext/ByteListTranscoder.java +167 -0
  17. data/java/src/json/ext/Generator.java +441 -0
  18. data/java/src/json/ext/GeneratorMethods.java +231 -0
  19. data/java/src/json/ext/GeneratorService.java +42 -0
  20. data/java/src/json/ext/GeneratorState.java +473 -0
  21. data/java/src/json/ext/OptionsReader.java +119 -0
  22. data/java/src/json/ext/Parser.java +2295 -0
  23. data/java/src/json/ext/Parser.rl +825 -0
  24. data/java/src/json/ext/ParserService.java +34 -0
  25. data/java/src/json/ext/RuntimeInfo.java +119 -0
  26. data/java/src/json/ext/StringDecoder.java +166 -0
  27. data/java/src/json/ext/StringEncoder.java +106 -0
  28. data/java/src/json/ext/Utils.java +89 -0
  29. data/json-java.gemspec +20 -0
  30. data/lib/json/add/core.rb +1 -2
  31. data/lib/json/add/rails.rb +4 -54
  32. data/lib/json/common.rb +36 -8
  33. data/lib/json/editor.rb +1 -3
  34. data/lib/json/ext.rb +2 -2
  35. data/lib/json/pure.rb +2 -64
  36. data/lib/json/pure/generator.rb +10 -8
  37. data/lib/json/pure/parser.rb +23 -12
  38. data/lib/json/version.rb +1 -1
  39. data/tests/setup_variant.rb +11 -0
  40. data/tests/test_json.rb +1 -5
  41. data/tests/test_json_addition.rb +14 -9
  42. data/tests/test_json_encoding.rb +9 -12
  43. data/tests/test_json_fixtures.rb +9 -8
  44. data/tests/test_json_generate.rb +3 -5
  45. data/tests/test_json_string_matching.rb +40 -0
  46. data/tests/test_json_unicode.rb +1 -5
  47. metadata +51 -13
  48. data/tests/test_json_rails.rb +0 -144
@@ -0,0 +1,119 @@
1
+ /*
2
+ * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
3
+ *
4
+ * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
5
+ * for details.
6
+ */
7
+ package json.ext;
8
+
9
+ import org.jruby.Ruby;
10
+ import org.jruby.RubyClass;
11
+ import org.jruby.RubyHash;
12
+ import org.jruby.RubyNumeric;
13
+ import org.jruby.RubyString;
14
+ import org.jruby.runtime.ThreadContext;
15
+ import org.jruby.runtime.builtin.IRubyObject;
16
+ import org.jruby.util.ByteList;
17
+
18
+ final class OptionsReader {
19
+ private final ThreadContext context;
20
+ private final Ruby runtime;
21
+ private final RubyHash opts;
22
+ private RuntimeInfo info;
23
+
24
+ OptionsReader(ThreadContext context, IRubyObject vOpts) {
25
+ this.context = context;
26
+ this.runtime = context.getRuntime();
27
+
28
+ if (vOpts == null || vOpts.isNil()) {
29
+ opts = null;
30
+ } else if (vOpts.respondsTo("to_hash")) {
31
+ opts = vOpts.convertToHash();
32
+ } else {
33
+ opts = vOpts.callMethod(context, "to_h").convertToHash();
34
+ }
35
+ }
36
+
37
+ private RuntimeInfo getRuntimeInfo() {
38
+ if (info != null) return info;
39
+ info = RuntimeInfo.forRuntime(runtime);
40
+ return info;
41
+ }
42
+
43
+ /**
44
+ * Efficiently looks up items with a {@link RubySymbol Symbol} key
45
+ * @param key The Symbol name to look up for
46
+ * @return The item in the {@link RubyHash Hash}, or <code>null</code>
47
+ * if not found
48
+ */
49
+ IRubyObject get(String key) {
50
+ return opts == null ? null : opts.fastARef(runtime.newSymbol(key));
51
+ }
52
+
53
+ boolean getBool(String key, boolean defaultValue) {
54
+ IRubyObject value = get(key);
55
+ return value == null ? defaultValue : value.isTrue();
56
+ }
57
+
58
+ int getInt(String key, int defaultValue) {
59
+ IRubyObject value = get(key);
60
+ if (value == null) return defaultValue;
61
+ if (!value.isTrue()) return 0;
62
+ return RubyNumeric.fix2int(value);
63
+ }
64
+
65
+ /**
66
+ * Reads the setting from the options hash. If no entry is set for this
67
+ * key or if it evaluates to <code>false</code>, returns null; attempts to
68
+ * coerce the value to {@link RubyString String} otherwise.
69
+ * @param key The Symbol name to look up for
70
+ * @return <code>null</code> if the key is not in the Hash or if
71
+ * its value evaluates to <code>false</code>
72
+ * @throws RaiseException <code>TypeError</code> if the value does not
73
+ * evaluate to <code>false</code> and can't be
74
+ * converted to string
75
+ */
76
+ ByteList getString(String key) {
77
+ RubyString str = getString(key, null);
78
+ return str == null ? null : str.getByteList().dup();
79
+ }
80
+
81
+ RubyString getString(String key, RubyString defaultValue) {
82
+ IRubyObject value = get(key);
83
+ if (value == null || !value.isTrue()) return defaultValue;
84
+
85
+ RubyString str = value.convertToString();
86
+ RuntimeInfo info = getRuntimeInfo();
87
+ if (info.encodingsSupported() && str.encoding(context) != info.utf8) {
88
+ str = (RubyString)str.encode(context, info.utf8);
89
+ }
90
+ return str;
91
+ }
92
+
93
+ /**
94
+ * Reads the setting from the options hash. If it is <code>nil</code> or
95
+ * undefined, returns the default value given.
96
+ * If not, ensures it is a RubyClass instance and shares the same
97
+ * allocator as the default value (i.e. for the basic types which have
98
+ * their specific allocators, this ensures the passed value is
99
+ * a subclass of them).
100
+ */
101
+ RubyClass getClass(String key, RubyClass defaultValue) {
102
+ IRubyObject value = get(key);
103
+
104
+ if (value == null || value.isNil()) return defaultValue;
105
+
106
+ if (value instanceof RubyClass &&
107
+ ((RubyClass)value).getAllocator() == defaultValue.getAllocator()) {
108
+ return (RubyClass)value;
109
+ }
110
+ throw runtime.newTypeError(key + " option must be a subclass of "
111
+ + defaultValue);
112
+ }
113
+
114
+ public RubyHash getHash(String key) {
115
+ IRubyObject value = get(key);
116
+ if (value == null || value.isNil()) return new RubyHash(runtime);
117
+ return (RubyHash) value;
118
+ }
119
+ }
@@ -0,0 +1,2295 @@
1
+
2
+ // line 1 "Parser.rl"
3
+ /*
4
+ * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
5
+ *
6
+ * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
7
+ * for details.
8
+ */
9
+ package json.ext;
10
+
11
+ import org.jruby.Ruby;
12
+ import org.jruby.RubyArray;
13
+ import org.jruby.RubyClass;
14
+ import org.jruby.RubyEncoding;
15
+ import org.jruby.RubyFloat;
16
+ import org.jruby.RubyHash;
17
+ import org.jruby.RubyInteger;
18
+ import org.jruby.RubyModule;
19
+ import org.jruby.RubyNumeric;
20
+ import org.jruby.RubyObject;
21
+ import org.jruby.RubyString;
22
+ import org.jruby.anno.JRubyMethod;
23
+ import org.jruby.exceptions.JumpException;
24
+ import org.jruby.exceptions.RaiseException;
25
+ import org.jruby.runtime.Block;
26
+ import org.jruby.runtime.ObjectAllocator;
27
+ import org.jruby.runtime.ThreadContext;
28
+ import org.jruby.runtime.Visibility;
29
+ import org.jruby.runtime.builtin.IRubyObject;
30
+ import org.jruby.util.ByteList;
31
+
32
+ /**
33
+ * The <code>JSON::Ext::Parser</code> class.
34
+ *
35
+ * <p>This is the JSON parser implemented as a Java class. To use it as the
36
+ * standard parser, set
37
+ * <pre>JSON.parser = JSON::Ext::Parser</pre>
38
+ * This is performed for you when you <code>include "json/ext"</code>.
39
+ *
40
+ * <p>This class does not perform the actual parsing, just acts as an interface
41
+ * to Ruby code. When the {@link #parse()} method is invoked, a
42
+ * Parser.ParserSession object is instantiated, which handles the process.
43
+ *
44
+ * @author mernen
45
+ */
46
+ public class Parser extends RubyObject {
47
+ private final RuntimeInfo info;
48
+ private RubyString vSource;
49
+ private RubyString createId;
50
+ private boolean createAdditions;
51
+ private int maxNesting;
52
+ private boolean allowNaN;
53
+ private boolean symbolizeNames;
54
+ private RubyClass objectClass;
55
+ private RubyClass arrayClass;
56
+ private RubyHash match_string;
57
+
58
+ private static final int DEFAULT_MAX_NESTING = 19;
59
+
60
+ private static final String JSON_MINUS_INFINITY = "-Infinity";
61
+ // constant names in the JSON module containing those values
62
+ private static final String CONST_NAN = "NaN";
63
+ private static final String CONST_INFINITY = "Infinity";
64
+ private static final String CONST_MINUS_INFINITY = "MinusInfinity";
65
+
66
+ static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
67
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
68
+ return new Parser(runtime, klazz);
69
+ }
70
+ };
71
+
72
+ /**
73
+ * Multiple-value return for internal parser methods.
74
+ *
75
+ * <p>All the <code>parse<var>Stuff</var></code> methods return instances of
76
+ * <code>ParserResult</code> when successful, or <code>null</code> when
77
+ * there's a problem with the input data.
78
+ */
79
+ static final class ParserResult {
80
+ /**
81
+ * The result of the successful parsing. Should never be
82
+ * <code>null</code>.
83
+ */
84
+ final IRubyObject result;
85
+ /**
86
+ * The point where the parser returned.
87
+ */
88
+ final int p;
89
+
90
+ ParserResult(IRubyObject result, int p) {
91
+ this.result = result;
92
+ this.p = p;
93
+ }
94
+ }
95
+
96
+ public Parser(Ruby runtime, RubyClass metaClass) {
97
+ super(runtime, metaClass);
98
+ info = RuntimeInfo.forRuntime(runtime);
99
+ }
100
+
101
+ /**
102
+ * <code>Parser.new(source, opts = {})</code>
103
+ *
104
+ * <p>Creates a new <code>JSON::Ext::Parser</code> instance for the string
105
+ * <code>source</code>.
106
+ * It will be configured by the <code>opts</code> Hash.
107
+ * <code>opts</code> can have the following keys:
108
+ *
109
+ * <dl>
110
+ * <dt><code>:max_nesting</code>
111
+ * <dd>The maximum depth of nesting allowed in the parsed data
112
+ * structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>,
113
+ * it defaults to 19.
114
+ *
115
+ * <dt><code>:allow_nan</code>
116
+ * <dd>If set to <code>true</code>, allow <code>NaN</code>,
117
+ * <code>Infinity</code> and <code>-Infinity</code> in defiance of RFC 4627
118
+ * to be parsed by the Parser. This option defaults to <code>false</code>.
119
+ *
120
+ * <dt><code>:symbolize_names</code>
121
+ * <dd>If set to <code>true</code>, returns symbols for the names (keys) in
122
+ * a JSON object. Otherwise strings are returned, which is also the default.
123
+ *
124
+ * <dt><code>:create_additions</code>
125
+ * <dd>If set to <code>false</code>, the Parser doesn't create additions
126
+ * even if a matchin class and <code>create_id</code> was found. This option
127
+ * defaults to <code>true</code>.
128
+ *
129
+ * <dt><code>:object_class</code>
130
+ * <dd>Defaults to Hash.
131
+ *
132
+ * <dt><code>:array_class</code>
133
+ * <dd>Defaults to Array.
134
+ * </dl>
135
+ */
136
+ @JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
137
+ public static IRubyObject newInstance(IRubyObject clazz, IRubyObject[] args, Block block) {
138
+ Parser parser = (Parser)((RubyClass)clazz).allocate();
139
+
140
+ parser.callInit(args, block);
141
+
142
+ return parser;
143
+ }
144
+
145
+ @JRubyMethod(required = 1, optional = 1, visibility = Visibility.PRIVATE)
146
+ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
147
+ Ruby runtime = context.getRuntime();
148
+ RubyString source = convertEncoding(context, args[0].convertToString());
149
+
150
+ OptionsReader opts = new OptionsReader(context, args.length > 1 ? args[1] : null);
151
+ this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
152
+ this.allowNaN = opts.getBool("allow_nan", false);
153
+ this.symbolizeNames = opts.getBool("symbolize_names", false);
154
+ this.createId = opts.getString("create_id", getCreateId(context));
155
+ this.createAdditions = opts.getBool("create_additions", true);
156
+ this.objectClass = opts.getClass("object_class", runtime.getHash());
157
+ this.arrayClass = opts.getClass("array_class", runtime.getArray());
158
+ this.match_string = opts.getHash("match_string");
159
+
160
+ this.vSource = source;
161
+ return this;
162
+ }
163
+
164
+ /**
165
+ * Checks the given string's encoding. If a non-UTF-8 encoding is detected,
166
+ * a converted copy is returned.
167
+ * Returns the source string if no conversion is needed.
168
+ */
169
+ private RubyString convertEncoding(ThreadContext context, RubyString source) {
170
+ ByteList bl = source.getByteList();
171
+ int len = bl.length();
172
+ if (len < 2) {
173
+ throw Utils.newException(context, Utils.M_PARSER_ERROR,
174
+ "A JSON text must at least contain two octets!");
175
+ }
176
+
177
+ if (info.encodingsSupported()) {
178
+ RubyEncoding encoding = (RubyEncoding)source.encoding(context);
179
+ if (encoding != info.ascii8bit) {
180
+ return (RubyString)source.encode(context, info.utf8);
181
+ }
182
+
183
+ String sniffedEncoding = sniffByteList(bl);
184
+ if (sniffedEncoding == null) return source; // assume UTF-8
185
+ return reinterpretEncoding(context, source, sniffedEncoding);
186
+ }
187
+
188
+ String sniffedEncoding = sniffByteList(bl);
189
+ if (sniffedEncoding == null) return source; // assume UTF-8
190
+ Ruby runtime = context.getRuntime();
191
+ return (RubyString)info.jsonModule.
192
+ callMethod(context, "iconv",
193
+ new IRubyObject[] {
194
+ runtime.newString("utf-8"),
195
+ runtime.newString(sniffedEncoding),
196
+ source});
197
+ }
198
+
199
+ /**
200
+ * Checks the first four bytes of the given ByteList to infer its encoding,
201
+ * using the principle demonstrated on section 3 of RFC 4627 (JSON).
202
+ */
203
+ private static String sniffByteList(ByteList bl) {
204
+ if (bl.length() < 4) return null;
205
+ if (bl.get(0) == 0 && bl.get(2) == 0) {
206
+ return bl.get(1) == 0 ? "utf-32be" : "utf-16be";
207
+ }
208
+ if (bl.get(1) == 0 && bl.get(3) == 0) {
209
+ return bl.get(2) == 0 ? "utf-32le" : "utf-16le";
210
+ }
211
+ return null;
212
+ }
213
+
214
+ /**
215
+ * Assumes the given (binary) RubyString to be in the given encoding, then
216
+ * converts it to UTF-8.
217
+ */
218
+ private RubyString reinterpretEncoding(ThreadContext context,
219
+ RubyString str, String sniffedEncoding) {
220
+ RubyEncoding actualEncoding = info.getEncoding(context, sniffedEncoding);
221
+ RubyEncoding targetEncoding = info.utf8;
222
+ RubyString dup = (RubyString)str.dup();
223
+ dup.force_encoding(context, actualEncoding);
224
+ return (RubyString)dup.encode_bang(context, targetEncoding);
225
+ }
226
+
227
+ /**
228
+ * <code>Parser#parse()</code>
229
+ *
230
+ * <p>Parses the current JSON text <code>source</code> and returns the
231
+ * complete data structure as a result.
232
+ */
233
+ @JRubyMethod
234
+ public IRubyObject parse(ThreadContext context) {
235
+ return new ParserSession(this, context).parse();
236
+ }
237
+
238
+ /**
239
+ * <code>Parser#source()</code>
240
+ *
241
+ * <p>Returns a copy of the current <code>source</code> string, that was
242
+ * used to construct this Parser.
243
+ */
244
+ @JRubyMethod(name = "source")
245
+ public IRubyObject source_get() {
246
+ return vSource.dup();
247
+ }
248
+
249
+ /**
250
+ * Queries <code>JSON.create_id</code>. Returns <code>null</code> if it is
251
+ * set to <code>nil</code> or <code>false</code>, and a String if not.
252
+ */
253
+ private RubyString getCreateId(ThreadContext context) {
254
+ IRubyObject v = info.jsonModule.callMethod(context, "create_id");
255
+ return v.isTrue() ? v.convertToString() : null;
256
+ }
257
+
258
+ /**
259
+ * A string parsing session.
260
+ *
261
+ * <p>Once a ParserSession is instantiated, the source string should not
262
+ * change until the parsing is complete. The ParserSession object assumes
263
+ * the source {@link RubyString} is still associated to its original
264
+ * {@link ByteList}, which in turn must still be bound to the same
265
+ * <code>byte[]</code> value (and on the same offset).
266
+ */
267
+ // Ragel uses lots of fall-through
268
+ @SuppressWarnings("fallthrough")
269
+ private static class ParserSession {
270
+ private final Parser parser;
271
+ private final ThreadContext context;
272
+ private final ByteList byteList;
273
+ private final byte[] data;
274
+ private final StringDecoder decoder;
275
+ private int currentNesting = 0;
276
+
277
+ // initialization value for all state variables.
278
+ // no idea about the origins of this value, ask Flori ;)
279
+ private static final int EVIL = 0x666;
280
+
281
+ private ParserSession(Parser parser, ThreadContext context) {
282
+ this.parser = parser;
283
+ this.context = context;
284
+ this.byteList = parser.vSource.getByteList();
285
+ this.data = byteList.unsafeBytes();
286
+ this.decoder = new StringDecoder(context);
287
+ }
288
+
289
+ private RaiseException unexpectedToken(int absStart, int absEnd) {
290
+ RubyString msg = getRuntime().newString("unexpected token at '")
291
+ .cat(data, absStart, absEnd - absStart)
292
+ .cat((byte)'\'');
293
+ return newException(Utils.M_PARSER_ERROR, msg);
294
+ }
295
+
296
+ private Ruby getRuntime() {
297
+ return context.getRuntime();
298
+ }
299
+
300
+
301
+ // line 324 "Parser.rl"
302
+
303
+
304
+
305
+ // line 306 "Parser.java"
306
+ private static byte[] init__JSON_value_actions_0()
307
+ {
308
+ return new byte [] {
309
+ 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
310
+ 5, 1, 6, 1, 7, 1, 8, 1, 9
311
+ };
312
+ }
313
+
314
+ private static final byte _JSON_value_actions[] = init__JSON_value_actions_0();
315
+
316
+
317
+ private static byte[] init__JSON_value_key_offsets_0()
318
+ {
319
+ return new byte [] {
320
+ 0, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
321
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
322
+ };
323
+ }
324
+
325
+ private static final byte _JSON_value_key_offsets[] = init__JSON_value_key_offsets_0();
326
+
327
+
328
+ private static char[] init__JSON_value_trans_keys_0()
329
+ {
330
+ return new char [] {
331
+ 34, 45, 73, 78, 91, 102, 110, 116, 123, 48, 57, 110,
332
+ 102, 105, 110, 105, 116, 121, 97, 78, 97, 108, 115, 101,
333
+ 117, 108, 108, 114, 117, 101, 0
334
+ };
335
+ }
336
+
337
+ private static final char _JSON_value_trans_keys[] = init__JSON_value_trans_keys_0();
338
+
339
+
340
+ private static byte[] init__JSON_value_single_lengths_0()
341
+ {
342
+ return new byte [] {
343
+ 0, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
344
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
345
+ };
346
+ }
347
+
348
+ private static final byte _JSON_value_single_lengths[] = init__JSON_value_single_lengths_0();
349
+
350
+
351
+ private static byte[] init__JSON_value_range_lengths_0()
352
+ {
353
+ return new byte [] {
354
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
355
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
356
+ };
357
+ }
358
+
359
+ private static final byte _JSON_value_range_lengths[] = init__JSON_value_range_lengths_0();
360
+
361
+
362
+ private static byte[] init__JSON_value_index_offsets_0()
363
+ {
364
+ return new byte [] {
365
+ 0, 0, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29,
366
+ 31, 33, 35, 37, 39, 41, 43, 45, 47, 49
367
+ };
368
+ }
369
+
370
+ private static final byte _JSON_value_index_offsets[] = init__JSON_value_index_offsets_0();
371
+
372
+
373
+ private static byte[] init__JSON_value_trans_targs_0()
374
+ {
375
+ return new byte [] {
376
+ 21, 21, 2, 9, 21, 11, 15, 18, 21, 21, 0, 3,
377
+ 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 21,
378
+ 0, 10, 0, 21, 0, 12, 0, 13, 0, 14, 0, 21,
379
+ 0, 16, 0, 17, 0, 21, 0, 19, 0, 20, 0, 21,
380
+ 0, 0, 0
381
+ };
382
+ }
383
+
384
+ private static final byte _JSON_value_trans_targs[] = init__JSON_value_trans_targs_0();
385
+
386
+
387
+ private static byte[] init__JSON_value_trans_actions_0()
388
+ {
389
+ return new byte [] {
390
+ 13, 11, 0, 0, 15, 0, 0, 0, 17, 11, 0, 0,
391
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
392
+ 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 3,
393
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 5,
394
+ 0, 0, 0
395
+ };
396
+ }
397
+
398
+ private static final byte _JSON_value_trans_actions[] = init__JSON_value_trans_actions_0();
399
+
400
+
401
+ private static byte[] init__JSON_value_from_state_actions_0()
402
+ {
403
+ return new byte [] {
404
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
405
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 19
406
+ };
407
+ }
408
+
409
+ private static final byte _JSON_value_from_state_actions[] = init__JSON_value_from_state_actions_0();
410
+
411
+
412
+ static final int JSON_value_start = 1;
413
+ static final int JSON_value_first_final = 21;
414
+ static final int JSON_value_error = 0;
415
+
416
+ static final int JSON_value_en_main = 1;
417
+
418
+
419
+ // line 430 "Parser.rl"
420
+
421
+
422
+ ParserResult parseValue(int p, int pe) {
423
+ int cs = EVIL;
424
+ IRubyObject result = null;
425
+
426
+
427
+ // line 428 "Parser.java"
428
+ {
429
+ cs = JSON_value_start;
430
+ }
431
+
432
+ // line 437 "Parser.rl"
433
+
434
+ // line 435 "Parser.java"
435
+ {
436
+ int _klen;
437
+ int _trans = 0;
438
+ int _acts;
439
+ int _nacts;
440
+ int _keys;
441
+ int _goto_targ = 0;
442
+
443
+ _goto: while (true) {
444
+ switch ( _goto_targ ) {
445
+ case 0:
446
+ if ( p == pe ) {
447
+ _goto_targ = 4;
448
+ continue _goto;
449
+ }
450
+ if ( cs == 0 ) {
451
+ _goto_targ = 5;
452
+ continue _goto;
453
+ }
454
+ case 1:
455
+ _acts = _JSON_value_from_state_actions[cs];
456
+ _nacts = (int) _JSON_value_actions[_acts++];
457
+ while ( _nacts-- > 0 ) {
458
+ switch ( _JSON_value_actions[_acts++] ) {
459
+ case 9:
460
+ // line 415 "Parser.rl"
461
+ {
462
+ p--;
463
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
464
+ }
465
+ break;
466
+ // line 467 "Parser.java"
467
+ }
468
+ }
469
+
470
+ _match: do {
471
+ _keys = _JSON_value_key_offsets[cs];
472
+ _trans = _JSON_value_index_offsets[cs];
473
+ _klen = _JSON_value_single_lengths[cs];
474
+ if ( _klen > 0 ) {
475
+ int _lower = _keys;
476
+ int _mid;
477
+ int _upper = _keys + _klen - 1;
478
+ while (true) {
479
+ if ( _upper < _lower )
480
+ break;
481
+
482
+ _mid = _lower + ((_upper-_lower) >> 1);
483
+ if ( data[p] < _JSON_value_trans_keys[_mid] )
484
+ _upper = _mid - 1;
485
+ else if ( data[p] > _JSON_value_trans_keys[_mid] )
486
+ _lower = _mid + 1;
487
+ else {
488
+ _trans += (_mid - _keys);
489
+ break _match;
490
+ }
491
+ }
492
+ _keys += _klen;
493
+ _trans += _klen;
494
+ }
495
+
496
+ _klen = _JSON_value_range_lengths[cs];
497
+ if ( _klen > 0 ) {
498
+ int _lower = _keys;
499
+ int _mid;
500
+ int _upper = _keys + (_klen<<1) - 2;
501
+ while (true) {
502
+ if ( _upper < _lower )
503
+ break;
504
+
505
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
506
+ if ( data[p] < _JSON_value_trans_keys[_mid] )
507
+ _upper = _mid - 2;
508
+ else if ( data[p] > _JSON_value_trans_keys[_mid+1] )
509
+ _lower = _mid + 2;
510
+ else {
511
+ _trans += ((_mid - _keys)>>1);
512
+ break _match;
513
+ }
514
+ }
515
+ _trans += _klen;
516
+ }
517
+ } while (false);
518
+
519
+ cs = _JSON_value_trans_targs[_trans];
520
+
521
+ if ( _JSON_value_trans_actions[_trans] != 0 ) {
522
+ _acts = _JSON_value_trans_actions[_trans];
523
+ _nacts = (int) _JSON_value_actions[_acts++];
524
+ while ( _nacts-- > 0 )
525
+ {
526
+ switch ( _JSON_value_actions[_acts++] )
527
+ {
528
+ case 0:
529
+ // line 332 "Parser.rl"
530
+ {
531
+ result = getRuntime().getNil();
532
+ }
533
+ break;
534
+ case 1:
535
+ // line 335 "Parser.rl"
536
+ {
537
+ result = getRuntime().getFalse();
538
+ }
539
+ break;
540
+ case 2:
541
+ // line 338 "Parser.rl"
542
+ {
543
+ result = getRuntime().getTrue();
544
+ }
545
+ break;
546
+ case 3:
547
+ // line 341 "Parser.rl"
548
+ {
549
+ if (parser.allowNaN) {
550
+ result = getConstant(CONST_NAN);
551
+ } else {
552
+ throw unexpectedToken(p - 2, pe);
553
+ }
554
+ }
555
+ break;
556
+ case 4:
557
+ // line 348 "Parser.rl"
558
+ {
559
+ if (parser.allowNaN) {
560
+ result = getConstant(CONST_INFINITY);
561
+ } else {
562
+ throw unexpectedToken(p - 7, pe);
563
+ }
564
+ }
565
+ break;
566
+ case 5:
567
+ // line 355 "Parser.rl"
568
+ {
569
+ if (pe > p + 9 &&
570
+ absSubSequence(p, p + 9).toString().equals(JSON_MINUS_INFINITY)) {
571
+
572
+ if (parser.allowNaN) {
573
+ result = getConstant(CONST_MINUS_INFINITY);
574
+ {p = (( p + 10))-1;}
575
+ p--;
576
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
577
+ } else {
578
+ throw unexpectedToken(p, pe);
579
+ }
580
+ }
581
+ ParserResult res = parseFloat(p, pe);
582
+ if (res != null) {
583
+ result = res.result;
584
+ {p = (( res.p))-1;}
585
+ }
586
+ res = parseInteger(p, pe);
587
+ if (res != null) {
588
+ result = res.result;
589
+ {p = (( res.p))-1;}
590
+ }
591
+ p--;
592
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
593
+ }
594
+ break;
595
+ case 6:
596
+ // line 381 "Parser.rl"
597
+ {
598
+ ParserResult res = parseString(p, pe);
599
+ if (res == null) {
600
+ p--;
601
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
602
+ } else {
603
+ result = res.result;
604
+ {p = (( res.p))-1;}
605
+ }
606
+ }
607
+ break;
608
+ case 7:
609
+ // line 391 "Parser.rl"
610
+ {
611
+ currentNesting++;
612
+ ParserResult res = parseArray(p, pe);
613
+ currentNesting--;
614
+ if (res == null) {
615
+ p--;
616
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
617
+ } else {
618
+ result = res.result;
619
+ {p = (( res.p))-1;}
620
+ }
621
+ }
622
+ break;
623
+ case 8:
624
+ // line 403 "Parser.rl"
625
+ {
626
+ currentNesting++;
627
+ ParserResult res = parseObject(p, pe);
628
+ currentNesting--;
629
+ if (res == null) {
630
+ p--;
631
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
632
+ } else {
633
+ result = res.result;
634
+ {p = (( res.p))-1;}
635
+ }
636
+ }
637
+ break;
638
+ // line 639 "Parser.java"
639
+ }
640
+ }
641
+ }
642
+
643
+ case 2:
644
+ if ( cs == 0 ) {
645
+ _goto_targ = 5;
646
+ continue _goto;
647
+ }
648
+ if ( ++p != pe ) {
649
+ _goto_targ = 1;
650
+ continue _goto;
651
+ }
652
+ case 4:
653
+ case 5:
654
+ }
655
+ break; }
656
+ }
657
+
658
+ // line 438 "Parser.rl"
659
+
660
+ if (cs >= JSON_value_first_final && result != null) {
661
+ return new ParserResult(result, p);
662
+ } else {
663
+ return null;
664
+ }
665
+ }
666
+
667
+
668
+ // line 669 "Parser.java"
669
+ private static byte[] init__JSON_integer_actions_0()
670
+ {
671
+ return new byte [] {
672
+ 0, 1, 0
673
+ };
674
+ }
675
+
676
+ private static final byte _JSON_integer_actions[] = init__JSON_integer_actions_0();
677
+
678
+
679
+ private static byte[] init__JSON_integer_key_offsets_0()
680
+ {
681
+ return new byte [] {
682
+ 0, 0, 4, 7, 9, 11
683
+ };
684
+ }
685
+
686
+ private static final byte _JSON_integer_key_offsets[] = init__JSON_integer_key_offsets_0();
687
+
688
+
689
+ private static char[] init__JSON_integer_trans_keys_0()
690
+ {
691
+ return new char [] {
692
+ 45, 48, 49, 57, 48, 49, 57, 48, 57, 48, 57, 0
693
+ };
694
+ }
695
+
696
+ private static final char _JSON_integer_trans_keys[] = init__JSON_integer_trans_keys_0();
697
+
698
+
699
+ private static byte[] init__JSON_integer_single_lengths_0()
700
+ {
701
+ return new byte [] {
702
+ 0, 2, 1, 0, 0, 0
703
+ };
704
+ }
705
+
706
+ private static final byte _JSON_integer_single_lengths[] = init__JSON_integer_single_lengths_0();
707
+
708
+
709
+ private static byte[] init__JSON_integer_range_lengths_0()
710
+ {
711
+ return new byte [] {
712
+ 0, 1, 1, 1, 1, 0
713
+ };
714
+ }
715
+
716
+ private static final byte _JSON_integer_range_lengths[] = init__JSON_integer_range_lengths_0();
717
+
718
+
719
+ private static byte[] init__JSON_integer_index_offsets_0()
720
+ {
721
+ return new byte [] {
722
+ 0, 0, 4, 7, 9, 11
723
+ };
724
+ }
725
+
726
+ private static final byte _JSON_integer_index_offsets[] = init__JSON_integer_index_offsets_0();
727
+
728
+
729
+ private static byte[] init__JSON_integer_indicies_0()
730
+ {
731
+ return new byte [] {
732
+ 0, 2, 3, 1, 2, 3, 1, 1, 4, 3, 4, 1,
733
+ 0
734
+ };
735
+ }
736
+
737
+ private static final byte _JSON_integer_indicies[] = init__JSON_integer_indicies_0();
738
+
739
+
740
+ private static byte[] init__JSON_integer_trans_targs_0()
741
+ {
742
+ return new byte [] {
743
+ 2, 0, 3, 4, 5
744
+ };
745
+ }
746
+
747
+ private static final byte _JSON_integer_trans_targs[] = init__JSON_integer_trans_targs_0();
748
+
749
+
750
+ private static byte[] init__JSON_integer_trans_actions_0()
751
+ {
752
+ return new byte [] {
753
+ 0, 0, 0, 0, 1
754
+ };
755
+ }
756
+
757
+ private static final byte _JSON_integer_trans_actions[] = init__JSON_integer_trans_actions_0();
758
+
759
+
760
+ static final int JSON_integer_start = 1;
761
+ static final int JSON_integer_first_final = 5;
762
+ static final int JSON_integer_error = 0;
763
+
764
+ static final int JSON_integer_en_main = 1;
765
+
766
+
767
+ // line 457 "Parser.rl"
768
+
769
+
770
+ ParserResult parseInteger(int p, int pe) {
771
+ int cs = EVIL;
772
+
773
+
774
+ // line 775 "Parser.java"
775
+ {
776
+ cs = JSON_integer_start;
777
+ }
778
+
779
+ // line 463 "Parser.rl"
780
+ int memo = p;
781
+
782
+ // line 783 "Parser.java"
783
+ {
784
+ int _klen;
785
+ int _trans = 0;
786
+ int _acts;
787
+ int _nacts;
788
+ int _keys;
789
+ int _goto_targ = 0;
790
+
791
+ _goto: while (true) {
792
+ switch ( _goto_targ ) {
793
+ case 0:
794
+ if ( p == pe ) {
795
+ _goto_targ = 4;
796
+ continue _goto;
797
+ }
798
+ if ( cs == 0 ) {
799
+ _goto_targ = 5;
800
+ continue _goto;
801
+ }
802
+ case 1:
803
+ _match: do {
804
+ _keys = _JSON_integer_key_offsets[cs];
805
+ _trans = _JSON_integer_index_offsets[cs];
806
+ _klen = _JSON_integer_single_lengths[cs];
807
+ if ( _klen > 0 ) {
808
+ int _lower = _keys;
809
+ int _mid;
810
+ int _upper = _keys + _klen - 1;
811
+ while (true) {
812
+ if ( _upper < _lower )
813
+ break;
814
+
815
+ _mid = _lower + ((_upper-_lower) >> 1);
816
+ if ( data[p] < _JSON_integer_trans_keys[_mid] )
817
+ _upper = _mid - 1;
818
+ else if ( data[p] > _JSON_integer_trans_keys[_mid] )
819
+ _lower = _mid + 1;
820
+ else {
821
+ _trans += (_mid - _keys);
822
+ break _match;
823
+ }
824
+ }
825
+ _keys += _klen;
826
+ _trans += _klen;
827
+ }
828
+
829
+ _klen = _JSON_integer_range_lengths[cs];
830
+ if ( _klen > 0 ) {
831
+ int _lower = _keys;
832
+ int _mid;
833
+ int _upper = _keys + (_klen<<1) - 2;
834
+ while (true) {
835
+ if ( _upper < _lower )
836
+ break;
837
+
838
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
839
+ if ( data[p] < _JSON_integer_trans_keys[_mid] )
840
+ _upper = _mid - 2;
841
+ else if ( data[p] > _JSON_integer_trans_keys[_mid+1] )
842
+ _lower = _mid + 2;
843
+ else {
844
+ _trans += ((_mid - _keys)>>1);
845
+ break _match;
846
+ }
847
+ }
848
+ _trans += _klen;
849
+ }
850
+ } while (false);
851
+
852
+ _trans = _JSON_integer_indicies[_trans];
853
+ cs = _JSON_integer_trans_targs[_trans];
854
+
855
+ if ( _JSON_integer_trans_actions[_trans] != 0 ) {
856
+ _acts = _JSON_integer_trans_actions[_trans];
857
+ _nacts = (int) _JSON_integer_actions[_acts++];
858
+ while ( _nacts-- > 0 )
859
+ {
860
+ switch ( _JSON_integer_actions[_acts++] )
861
+ {
862
+ case 0:
863
+ // line 451 "Parser.rl"
864
+ {
865
+ p--;
866
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
867
+ }
868
+ break;
869
+ // line 870 "Parser.java"
870
+ }
871
+ }
872
+ }
873
+
874
+ case 2:
875
+ if ( cs == 0 ) {
876
+ _goto_targ = 5;
877
+ continue _goto;
878
+ }
879
+ if ( ++p != pe ) {
880
+ _goto_targ = 1;
881
+ continue _goto;
882
+ }
883
+ case 4:
884
+ case 5:
885
+ }
886
+ break; }
887
+ }
888
+
889
+ // line 465 "Parser.rl"
890
+
891
+ if (cs < JSON_integer_first_final) {
892
+ return null;
893
+ }
894
+
895
+ ByteList num = absSubSequence(memo, p);
896
+ // note: this is actually a shared string, but since it is temporary and
897
+ // read-only, it doesn't really matter
898
+ RubyString expr = RubyString.newStringLight(getRuntime(), num);
899
+ RubyInteger number = RubyNumeric.str2inum(getRuntime(), expr, 10, true);
900
+ return new ParserResult(number, p + 1);
901
+ }
902
+
903
+
904
+ // line 905 "Parser.java"
905
+ private static byte[] init__JSON_float_actions_0()
906
+ {
907
+ return new byte [] {
908
+ 0, 1, 0
909
+ };
910
+ }
911
+
912
+ private static final byte _JSON_float_actions[] = init__JSON_float_actions_0();
913
+
914
+
915
+ private static byte[] init__JSON_float_key_offsets_0()
916
+ {
917
+ return new byte [] {
918
+ 0, 0, 4, 7, 10, 12, 18, 22, 24, 30, 35
919
+ };
920
+ }
921
+
922
+ private static final byte _JSON_float_key_offsets[] = init__JSON_float_key_offsets_0();
923
+
924
+
925
+ private static char[] init__JSON_float_trans_keys_0()
926
+ {
927
+ return new char [] {
928
+ 45, 48, 49, 57, 48, 49, 57, 46, 69, 101, 48, 57,
929
+ 69, 101, 45, 46, 48, 57, 43, 45, 48, 57, 48, 57,
930
+ 69, 101, 45, 46, 48, 57, 46, 69, 101, 48, 57, 0
931
+ };
932
+ }
933
+
934
+ private static final char _JSON_float_trans_keys[] = init__JSON_float_trans_keys_0();
935
+
936
+
937
+ private static byte[] init__JSON_float_single_lengths_0()
938
+ {
939
+ return new byte [] {
940
+ 0, 2, 1, 3, 0, 2, 2, 0, 2, 3, 0
941
+ };
942
+ }
943
+
944
+ private static final byte _JSON_float_single_lengths[] = init__JSON_float_single_lengths_0();
945
+
946
+
947
+ private static byte[] init__JSON_float_range_lengths_0()
948
+ {
949
+ return new byte [] {
950
+ 0, 1, 1, 0, 1, 2, 1, 1, 2, 1, 0
951
+ };
952
+ }
953
+
954
+ private static final byte _JSON_float_range_lengths[] = init__JSON_float_range_lengths_0();
955
+
956
+
957
+ private static byte[] init__JSON_float_index_offsets_0()
958
+ {
959
+ return new byte [] {
960
+ 0, 0, 4, 7, 11, 13, 18, 22, 24, 29, 34
961
+ };
962
+ }
963
+
964
+ private static final byte _JSON_float_index_offsets[] = init__JSON_float_index_offsets_0();
965
+
966
+
967
+ private static byte[] init__JSON_float_indicies_0()
968
+ {
969
+ return new byte [] {
970
+ 0, 2, 3, 1, 2, 3, 1, 4, 5, 5, 1, 6,
971
+ 1, 5, 5, 1, 6, 7, 8, 8, 9, 1, 9, 1,
972
+ 1, 1, 1, 9, 7, 4, 5, 5, 3, 1, 1, 0
973
+ };
974
+ }
975
+
976
+ private static final byte _JSON_float_indicies[] = init__JSON_float_indicies_0();
977
+
978
+
979
+ private static byte[] init__JSON_float_trans_targs_0()
980
+ {
981
+ return new byte [] {
982
+ 2, 0, 3, 9, 4, 6, 5, 10, 7, 8
983
+ };
984
+ }
985
+
986
+ private static final byte _JSON_float_trans_targs[] = init__JSON_float_trans_targs_0();
987
+
988
+
989
+ private static byte[] init__JSON_float_trans_actions_0()
990
+ {
991
+ return new byte [] {
992
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0
993
+ };
994
+ }
995
+
996
+ private static final byte _JSON_float_trans_actions[] = init__JSON_float_trans_actions_0();
997
+
998
+
999
+ static final int JSON_float_start = 1;
1000
+ static final int JSON_float_first_final = 10;
1001
+ static final int JSON_float_error = 0;
1002
+
1003
+ static final int JSON_float_en_main = 1;
1004
+
1005
+
1006
+ // line 493 "Parser.rl"
1007
+
1008
+
1009
+ ParserResult parseFloat(int p, int pe) {
1010
+ int cs = EVIL;
1011
+
1012
+
1013
+ // line 1014 "Parser.java"
1014
+ {
1015
+ cs = JSON_float_start;
1016
+ }
1017
+
1018
+ // line 499 "Parser.rl"
1019
+ int memo = p;
1020
+
1021
+ // line 1022 "Parser.java"
1022
+ {
1023
+ int _klen;
1024
+ int _trans = 0;
1025
+ int _acts;
1026
+ int _nacts;
1027
+ int _keys;
1028
+ int _goto_targ = 0;
1029
+
1030
+ _goto: while (true) {
1031
+ switch ( _goto_targ ) {
1032
+ case 0:
1033
+ if ( p == pe ) {
1034
+ _goto_targ = 4;
1035
+ continue _goto;
1036
+ }
1037
+ if ( cs == 0 ) {
1038
+ _goto_targ = 5;
1039
+ continue _goto;
1040
+ }
1041
+ case 1:
1042
+ _match: do {
1043
+ _keys = _JSON_float_key_offsets[cs];
1044
+ _trans = _JSON_float_index_offsets[cs];
1045
+ _klen = _JSON_float_single_lengths[cs];
1046
+ if ( _klen > 0 ) {
1047
+ int _lower = _keys;
1048
+ int _mid;
1049
+ int _upper = _keys + _klen - 1;
1050
+ while (true) {
1051
+ if ( _upper < _lower )
1052
+ break;
1053
+
1054
+ _mid = _lower + ((_upper-_lower) >> 1);
1055
+ if ( data[p] < _JSON_float_trans_keys[_mid] )
1056
+ _upper = _mid - 1;
1057
+ else if ( data[p] > _JSON_float_trans_keys[_mid] )
1058
+ _lower = _mid + 1;
1059
+ else {
1060
+ _trans += (_mid - _keys);
1061
+ break _match;
1062
+ }
1063
+ }
1064
+ _keys += _klen;
1065
+ _trans += _klen;
1066
+ }
1067
+
1068
+ _klen = _JSON_float_range_lengths[cs];
1069
+ if ( _klen > 0 ) {
1070
+ int _lower = _keys;
1071
+ int _mid;
1072
+ int _upper = _keys + (_klen<<1) - 2;
1073
+ while (true) {
1074
+ if ( _upper < _lower )
1075
+ break;
1076
+
1077
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
1078
+ if ( data[p] < _JSON_float_trans_keys[_mid] )
1079
+ _upper = _mid - 2;
1080
+ else if ( data[p] > _JSON_float_trans_keys[_mid+1] )
1081
+ _lower = _mid + 2;
1082
+ else {
1083
+ _trans += ((_mid - _keys)>>1);
1084
+ break _match;
1085
+ }
1086
+ }
1087
+ _trans += _klen;
1088
+ }
1089
+ } while (false);
1090
+
1091
+ _trans = _JSON_float_indicies[_trans];
1092
+ cs = _JSON_float_trans_targs[_trans];
1093
+
1094
+ if ( _JSON_float_trans_actions[_trans] != 0 ) {
1095
+ _acts = _JSON_float_trans_actions[_trans];
1096
+ _nacts = (int) _JSON_float_actions[_acts++];
1097
+ while ( _nacts-- > 0 )
1098
+ {
1099
+ switch ( _JSON_float_actions[_acts++] )
1100
+ {
1101
+ case 0:
1102
+ // line 484 "Parser.rl"
1103
+ {
1104
+ p--;
1105
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1106
+ }
1107
+ break;
1108
+ // line 1109 "Parser.java"
1109
+ }
1110
+ }
1111
+ }
1112
+
1113
+ case 2:
1114
+ if ( cs == 0 ) {
1115
+ _goto_targ = 5;
1116
+ continue _goto;
1117
+ }
1118
+ if ( ++p != pe ) {
1119
+ _goto_targ = 1;
1120
+ continue _goto;
1121
+ }
1122
+ case 4:
1123
+ case 5:
1124
+ }
1125
+ break; }
1126
+ }
1127
+
1128
+ // line 501 "Parser.rl"
1129
+
1130
+ if (cs < JSON_float_first_final) {
1131
+ return null;
1132
+ }
1133
+
1134
+ ByteList num = absSubSequence(memo, p);
1135
+ // note: this is actually a shared string, but since it is temporary and
1136
+ // read-only, it doesn't really matter
1137
+ RubyString expr = RubyString.newStringLight(getRuntime(), num);
1138
+ RubyFloat number = RubyNumeric.str2fnum(getRuntime(), expr, true);
1139
+ return new ParserResult(number, p + 1);
1140
+ }
1141
+
1142
+
1143
+ // line 1144 "Parser.java"
1144
+ private static byte[] init__JSON_string_actions_0()
1145
+ {
1146
+ return new byte [] {
1147
+ 0, 2, 0, 1
1148
+ };
1149
+ }
1150
+
1151
+ private static final byte _JSON_string_actions[] = init__JSON_string_actions_0();
1152
+
1153
+
1154
+ private static byte[] init__JSON_string_key_offsets_0()
1155
+ {
1156
+ return new byte [] {
1157
+ 0, 0, 1, 5, 8, 14, 20, 26, 32
1158
+ };
1159
+ }
1160
+
1161
+ private static final byte _JSON_string_key_offsets[] = init__JSON_string_key_offsets_0();
1162
+
1163
+
1164
+ private static char[] init__JSON_string_trans_keys_0()
1165
+ {
1166
+ return new char [] {
1167
+ 34, 34, 92, 0, 31, 117, 0, 31, 48, 57, 65, 70,
1168
+ 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70,
1169
+ 97, 102, 48, 57, 65, 70, 97, 102, 0
1170
+ };
1171
+ }
1172
+
1173
+ private static final char _JSON_string_trans_keys[] = init__JSON_string_trans_keys_0();
1174
+
1175
+
1176
+ private static byte[] init__JSON_string_single_lengths_0()
1177
+ {
1178
+ return new byte [] {
1179
+ 0, 1, 2, 1, 0, 0, 0, 0, 0
1180
+ };
1181
+ }
1182
+
1183
+ private static final byte _JSON_string_single_lengths[] = init__JSON_string_single_lengths_0();
1184
+
1185
+
1186
+ private static byte[] init__JSON_string_range_lengths_0()
1187
+ {
1188
+ return new byte [] {
1189
+ 0, 0, 1, 1, 3, 3, 3, 3, 0
1190
+ };
1191
+ }
1192
+
1193
+ private static final byte _JSON_string_range_lengths[] = init__JSON_string_range_lengths_0();
1194
+
1195
+
1196
+ private static byte[] init__JSON_string_index_offsets_0()
1197
+ {
1198
+ return new byte [] {
1199
+ 0, 0, 2, 6, 9, 13, 17, 21, 25
1200
+ };
1201
+ }
1202
+
1203
+ private static final byte _JSON_string_index_offsets[] = init__JSON_string_index_offsets_0();
1204
+
1205
+
1206
+ private static byte[] init__JSON_string_indicies_0()
1207
+ {
1208
+ return new byte [] {
1209
+ 0, 1, 2, 3, 1, 0, 4, 1, 0, 5, 5, 5,
1210
+ 1, 6, 6, 6, 1, 7, 7, 7, 1, 0, 0, 0,
1211
+ 1, 1, 0
1212
+ };
1213
+ }
1214
+
1215
+ private static final byte _JSON_string_indicies[] = init__JSON_string_indicies_0();
1216
+
1217
+
1218
+ private static byte[] init__JSON_string_trans_targs_0()
1219
+ {
1220
+ return new byte [] {
1221
+ 2, 0, 8, 3, 4, 5, 6, 7
1222
+ };
1223
+ }
1224
+
1225
+ private static final byte _JSON_string_trans_targs[] = init__JSON_string_trans_targs_0();
1226
+
1227
+
1228
+ private static byte[] init__JSON_string_trans_actions_0()
1229
+ {
1230
+ return new byte [] {
1231
+ 0, 0, 1, 0, 0, 0, 0, 0
1232
+ };
1233
+ }
1234
+
1235
+ private static final byte _JSON_string_trans_actions[] = init__JSON_string_trans_actions_0();
1236
+
1237
+
1238
+ static final int JSON_string_start = 1;
1239
+ static final int JSON_string_first_final = 8;
1240
+ static final int JSON_string_error = 0;
1241
+
1242
+ static final int JSON_string_en_main = 1;
1243
+
1244
+
1245
+ // line 545 "Parser.rl"
1246
+
1247
+
1248
+ ParserResult parseString(int p, int pe) {
1249
+ int cs = EVIL;
1250
+ IRubyObject result = null;
1251
+
1252
+
1253
+ // line 1254 "Parser.java"
1254
+ {
1255
+ cs = JSON_string_start;
1256
+ }
1257
+
1258
+ // line 552 "Parser.rl"
1259
+ int memo = p;
1260
+
1261
+ // line 1262 "Parser.java"
1262
+ {
1263
+ int _klen;
1264
+ int _trans = 0;
1265
+ int _acts;
1266
+ int _nacts;
1267
+ int _keys;
1268
+ int _goto_targ = 0;
1269
+
1270
+ _goto: while (true) {
1271
+ switch ( _goto_targ ) {
1272
+ case 0:
1273
+ if ( p == pe ) {
1274
+ _goto_targ = 4;
1275
+ continue _goto;
1276
+ }
1277
+ if ( cs == 0 ) {
1278
+ _goto_targ = 5;
1279
+ continue _goto;
1280
+ }
1281
+ case 1:
1282
+ _match: do {
1283
+ _keys = _JSON_string_key_offsets[cs];
1284
+ _trans = _JSON_string_index_offsets[cs];
1285
+ _klen = _JSON_string_single_lengths[cs];
1286
+ if ( _klen > 0 ) {
1287
+ int _lower = _keys;
1288
+ int _mid;
1289
+ int _upper = _keys + _klen - 1;
1290
+ while (true) {
1291
+ if ( _upper < _lower )
1292
+ break;
1293
+
1294
+ _mid = _lower + ((_upper-_lower) >> 1);
1295
+ if ( data[p] < _JSON_string_trans_keys[_mid] )
1296
+ _upper = _mid - 1;
1297
+ else if ( data[p] > _JSON_string_trans_keys[_mid] )
1298
+ _lower = _mid + 1;
1299
+ else {
1300
+ _trans += (_mid - _keys);
1301
+ break _match;
1302
+ }
1303
+ }
1304
+ _keys += _klen;
1305
+ _trans += _klen;
1306
+ }
1307
+
1308
+ _klen = _JSON_string_range_lengths[cs];
1309
+ if ( _klen > 0 ) {
1310
+ int _lower = _keys;
1311
+ int _mid;
1312
+ int _upper = _keys + (_klen<<1) - 2;
1313
+ while (true) {
1314
+ if ( _upper < _lower )
1315
+ break;
1316
+
1317
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
1318
+ if ( data[p] < _JSON_string_trans_keys[_mid] )
1319
+ _upper = _mid - 2;
1320
+ else if ( data[p] > _JSON_string_trans_keys[_mid+1] )
1321
+ _lower = _mid + 2;
1322
+ else {
1323
+ _trans += ((_mid - _keys)>>1);
1324
+ break _match;
1325
+ }
1326
+ }
1327
+ _trans += _klen;
1328
+ }
1329
+ } while (false);
1330
+
1331
+ _trans = _JSON_string_indicies[_trans];
1332
+ cs = _JSON_string_trans_targs[_trans];
1333
+
1334
+ if ( _JSON_string_trans_actions[_trans] != 0 ) {
1335
+ _acts = _JSON_string_trans_actions[_trans];
1336
+ _nacts = (int) _JSON_string_actions[_acts++];
1337
+ while ( _nacts-- > 0 )
1338
+ {
1339
+ switch ( _JSON_string_actions[_acts++] )
1340
+ {
1341
+ case 0:
1342
+ // line 520 "Parser.rl"
1343
+ {
1344
+ int offset = byteList.begin();
1345
+ ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
1346
+ p - offset);
1347
+ result = getRuntime().newString(decoded);
1348
+ if (result == null) {
1349
+ p--;
1350
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1351
+ } else {
1352
+ {p = (( p + 1))-1;}
1353
+ }
1354
+ }
1355
+ break;
1356
+ case 1:
1357
+ // line 533 "Parser.rl"
1358
+ {
1359
+ p--;
1360
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1361
+ }
1362
+ break;
1363
+ // line 1364 "Parser.java"
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ case 2:
1369
+ if ( cs == 0 ) {
1370
+ _goto_targ = 5;
1371
+ continue _goto;
1372
+ }
1373
+ if ( ++p != pe ) {
1374
+ _goto_targ = 1;
1375
+ continue _goto;
1376
+ }
1377
+ case 4:
1378
+ case 5:
1379
+ }
1380
+ break; }
1381
+ }
1382
+
1383
+ // line 554 "Parser.rl"
1384
+
1385
+ if (parser.createAdditions) {
1386
+ RubyHash match_string = parser.match_string;
1387
+ if (match_string != null) {
1388
+ final IRubyObject[] memoArray = { result, null };
1389
+ try {
1390
+ match_string.visitAll(new RubyHash.Visitor() {
1391
+ @Override
1392
+ public void visit(IRubyObject pattern, IRubyObject klass) {
1393
+ if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
1394
+ memoArray[1] = klass;
1395
+ throw JumpException.SPECIAL_JUMP;
1396
+ }
1397
+ }
1398
+ });
1399
+ } catch (JumpException e) { }
1400
+ if (memoArray[1] != null) {
1401
+ RubyClass klass = (RubyClass) memoArray[1];
1402
+ if (klass.respondsTo("json_creatable?") &&
1403
+ klass.callMethod(context, "json_creatable?").isTrue()) {
1404
+ result = klass.callMethod(context, "json_create", result);
1405
+ }
1406
+ }
1407
+ }
1408
+ }
1409
+
1410
+ if (cs >= JSON_string_first_final && result != null) {
1411
+ return new ParserResult(result, p + 1);
1412
+ } else {
1413
+ return null;
1414
+ }
1415
+ }
1416
+
1417
+
1418
+ // line 1419 "Parser.java"
1419
+ private static byte[] init__JSON_array_actions_0()
1420
+ {
1421
+ return new byte [] {
1422
+ 0, 1, 0, 1, 1
1423
+ };
1424
+ }
1425
+
1426
+ private static final byte _JSON_array_actions[] = init__JSON_array_actions_0();
1427
+
1428
+
1429
+ private static byte[] init__JSON_array_key_offsets_0()
1430
+ {
1431
+ return new byte [] {
1432
+ 0, 0, 1, 18, 25, 41, 43, 44, 46, 47, 49, 50,
1433
+ 52, 53, 55, 56, 58, 59
1434
+ };
1435
+ }
1436
+
1437
+ private static final byte _JSON_array_key_offsets[] = init__JSON_array_key_offsets_0();
1438
+
1439
+
1440
+ private static char[] init__JSON_array_trans_keys_0()
1441
+ {
1442
+ return new char [] {
1443
+ 91, 13, 32, 34, 45, 47, 73, 78, 91, 93, 102, 110,
1444
+ 116, 123, 9, 10, 48, 57, 13, 32, 44, 47, 93, 9,
1445
+ 10, 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116,
1446
+ 123, 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42,
1447
+ 47, 42, 42, 47, 10, 42, 47, 42, 42, 47, 10, 0
1448
+ };
1449
+ }
1450
+
1451
+ private static final char _JSON_array_trans_keys[] = init__JSON_array_trans_keys_0();
1452
+
1453
+
1454
+ private static byte[] init__JSON_array_single_lengths_0()
1455
+ {
1456
+ return new byte [] {
1457
+ 0, 1, 13, 5, 12, 2, 1, 2, 1, 2, 1, 2,
1458
+ 1, 2, 1, 2, 1, 0
1459
+ };
1460
+ }
1461
+
1462
+ private static final byte _JSON_array_single_lengths[] = init__JSON_array_single_lengths_0();
1463
+
1464
+
1465
+ private static byte[] init__JSON_array_range_lengths_0()
1466
+ {
1467
+ return new byte [] {
1468
+ 0, 0, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0,
1469
+ 0, 0, 0, 0, 0, 0
1470
+ };
1471
+ }
1472
+
1473
+ private static final byte _JSON_array_range_lengths[] = init__JSON_array_range_lengths_0();
1474
+
1475
+
1476
+ private static byte[] init__JSON_array_index_offsets_0()
1477
+ {
1478
+ return new byte [] {
1479
+ 0, 0, 2, 18, 25, 40, 43, 45, 48, 50, 53, 55,
1480
+ 58, 60, 63, 65, 68, 70
1481
+ };
1482
+ }
1483
+
1484
+ private static final byte _JSON_array_index_offsets[] = init__JSON_array_index_offsets_0();
1485
+
1486
+
1487
+ private static byte[] init__JSON_array_indicies_0()
1488
+ {
1489
+ return new byte [] {
1490
+ 0, 1, 0, 0, 2, 2, 3, 2, 2, 2, 4, 2,
1491
+ 2, 2, 2, 0, 2, 1, 5, 5, 6, 7, 4, 5,
1492
+ 1, 6, 6, 2, 2, 8, 2, 2, 2, 2, 2, 2,
1493
+ 2, 6, 2, 1, 9, 10, 1, 11, 9, 11, 6, 9,
1494
+ 6, 10, 12, 13, 1, 14, 12, 14, 5, 12, 5, 13,
1495
+ 15, 16, 1, 17, 15, 17, 0, 15, 0, 16, 1, 0
1496
+ };
1497
+ }
1498
+
1499
+ private static final byte _JSON_array_indicies[] = init__JSON_array_indicies_0();
1500
+
1501
+
1502
+ private static byte[] init__JSON_array_trans_targs_0()
1503
+ {
1504
+ return new byte [] {
1505
+ 2, 0, 3, 13, 17, 3, 4, 9, 5, 6, 8, 7,
1506
+ 10, 12, 11, 14, 16, 15
1507
+ };
1508
+ }
1509
+
1510
+ private static final byte _JSON_array_trans_targs[] = init__JSON_array_trans_targs_0();
1511
+
1512
+
1513
+ private static byte[] init__JSON_array_trans_actions_0()
1514
+ {
1515
+ return new byte [] {
1516
+ 0, 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0,
1517
+ 0, 0, 0, 0, 0, 0
1518
+ };
1519
+ }
1520
+
1521
+ private static final byte _JSON_array_trans_actions[] = init__JSON_array_trans_actions_0();
1522
+
1523
+
1524
+ static final int JSON_array_start = 1;
1525
+ static final int JSON_array_first_final = 17;
1526
+ static final int JSON_array_error = 0;
1527
+
1528
+ static final int JSON_array_en_main = 1;
1529
+
1530
+
1531
+ // line 620 "Parser.rl"
1532
+
1533
+
1534
+ ParserResult parseArray(int p, int pe) {
1535
+ int cs = EVIL;
1536
+
1537
+ if (parser.maxNesting > 0 && currentNesting > parser.maxNesting) {
1538
+ throw newException(Utils.M_NESTING_ERROR,
1539
+ "nesting of " + currentNesting + " is too deep");
1540
+ }
1541
+
1542
+ // this is guaranteed to be a RubyArray due to the earlier
1543
+ // allocator test at OptionsReader#getClass
1544
+ RubyArray result =
1545
+ (RubyArray)parser.arrayClass.newInstance(context,
1546
+ IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
1547
+
1548
+
1549
+ // line 1550 "Parser.java"
1550
+ {
1551
+ cs = JSON_array_start;
1552
+ }
1553
+
1554
+ // line 637 "Parser.rl"
1555
+
1556
+ // line 1557 "Parser.java"
1557
+ {
1558
+ int _klen;
1559
+ int _trans = 0;
1560
+ int _acts;
1561
+ int _nacts;
1562
+ int _keys;
1563
+ int _goto_targ = 0;
1564
+
1565
+ _goto: while (true) {
1566
+ switch ( _goto_targ ) {
1567
+ case 0:
1568
+ if ( p == pe ) {
1569
+ _goto_targ = 4;
1570
+ continue _goto;
1571
+ }
1572
+ if ( cs == 0 ) {
1573
+ _goto_targ = 5;
1574
+ continue _goto;
1575
+ }
1576
+ case 1:
1577
+ _match: do {
1578
+ _keys = _JSON_array_key_offsets[cs];
1579
+ _trans = _JSON_array_index_offsets[cs];
1580
+ _klen = _JSON_array_single_lengths[cs];
1581
+ if ( _klen > 0 ) {
1582
+ int _lower = _keys;
1583
+ int _mid;
1584
+ int _upper = _keys + _klen - 1;
1585
+ while (true) {
1586
+ if ( _upper < _lower )
1587
+ break;
1588
+
1589
+ _mid = _lower + ((_upper-_lower) >> 1);
1590
+ if ( data[p] < _JSON_array_trans_keys[_mid] )
1591
+ _upper = _mid - 1;
1592
+ else if ( data[p] > _JSON_array_trans_keys[_mid] )
1593
+ _lower = _mid + 1;
1594
+ else {
1595
+ _trans += (_mid - _keys);
1596
+ break _match;
1597
+ }
1598
+ }
1599
+ _keys += _klen;
1600
+ _trans += _klen;
1601
+ }
1602
+
1603
+ _klen = _JSON_array_range_lengths[cs];
1604
+ if ( _klen > 0 ) {
1605
+ int _lower = _keys;
1606
+ int _mid;
1607
+ int _upper = _keys + (_klen<<1) - 2;
1608
+ while (true) {
1609
+ if ( _upper < _lower )
1610
+ break;
1611
+
1612
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
1613
+ if ( data[p] < _JSON_array_trans_keys[_mid] )
1614
+ _upper = _mid - 2;
1615
+ else if ( data[p] > _JSON_array_trans_keys[_mid+1] )
1616
+ _lower = _mid + 2;
1617
+ else {
1618
+ _trans += ((_mid - _keys)>>1);
1619
+ break _match;
1620
+ }
1621
+ }
1622
+ _trans += _klen;
1623
+ }
1624
+ } while (false);
1625
+
1626
+ _trans = _JSON_array_indicies[_trans];
1627
+ cs = _JSON_array_trans_targs[_trans];
1628
+
1629
+ if ( _JSON_array_trans_actions[_trans] != 0 ) {
1630
+ _acts = _JSON_array_trans_actions[_trans];
1631
+ _nacts = (int) _JSON_array_actions[_acts++];
1632
+ while ( _nacts-- > 0 )
1633
+ {
1634
+ switch ( _JSON_array_actions[_acts++] )
1635
+ {
1636
+ case 0:
1637
+ // line 593 "Parser.rl"
1638
+ {
1639
+ ParserResult res = parseValue(p, pe);
1640
+ if (res == null) {
1641
+ p--;
1642
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1643
+ } else {
1644
+ result.append(res.result);
1645
+ {p = (( res.p))-1;}
1646
+ }
1647
+ }
1648
+ break;
1649
+ case 1:
1650
+ // line 604 "Parser.rl"
1651
+ {
1652
+ p--;
1653
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1654
+ }
1655
+ break;
1656
+ // line 1657 "Parser.java"
1657
+ }
1658
+ }
1659
+ }
1660
+
1661
+ case 2:
1662
+ if ( cs == 0 ) {
1663
+ _goto_targ = 5;
1664
+ continue _goto;
1665
+ }
1666
+ if ( ++p != pe ) {
1667
+ _goto_targ = 1;
1668
+ continue _goto;
1669
+ }
1670
+ case 4:
1671
+ case 5:
1672
+ }
1673
+ break; }
1674
+ }
1675
+
1676
+ // line 638 "Parser.rl"
1677
+
1678
+ if (cs >= JSON_array_first_final) {
1679
+ return new ParserResult(result, p + 1);
1680
+ } else {
1681
+ throw unexpectedToken(p, pe);
1682
+ }
1683
+ }
1684
+
1685
+
1686
+ // line 1687 "Parser.java"
1687
+ private static byte[] init__JSON_object_actions_0()
1688
+ {
1689
+ return new byte [] {
1690
+ 0, 1, 0, 1, 1, 1, 2
1691
+ };
1692
+ }
1693
+
1694
+ private static final byte _JSON_object_actions[] = init__JSON_object_actions_0();
1695
+
1696
+
1697
+ private static byte[] init__JSON_object_key_offsets_0()
1698
+ {
1699
+ return new byte [] {
1700
+ 0, 0, 1, 8, 14, 16, 17, 19, 20, 36, 43, 49,
1701
+ 51, 52, 54, 55, 57, 58, 60, 61, 63, 64, 66, 67,
1702
+ 69, 70, 72, 73
1703
+ };
1704
+ }
1705
+
1706
+ private static final byte _JSON_object_key_offsets[] = init__JSON_object_key_offsets_0();
1707
+
1708
+
1709
+ private static char[] init__JSON_object_trans_keys_0()
1710
+ {
1711
+ return new char [] {
1712
+ 123, 13, 32, 34, 47, 125, 9, 10, 13, 32, 47, 58,
1713
+ 9, 10, 42, 47, 42, 42, 47, 10, 13, 32, 34, 45,
1714
+ 47, 73, 78, 91, 102, 110, 116, 123, 9, 10, 48, 57,
1715
+ 13, 32, 44, 47, 125, 9, 10, 13, 32, 34, 47, 9,
1716
+ 10, 42, 47, 42, 42, 47, 10, 42, 47, 42, 42, 47,
1717
+ 10, 42, 47, 42, 42, 47, 10, 42, 47, 42, 42, 47,
1718
+ 10, 0
1719
+ };
1720
+ }
1721
+
1722
+ private static final char _JSON_object_trans_keys[] = init__JSON_object_trans_keys_0();
1723
+
1724
+
1725
+ private static byte[] init__JSON_object_single_lengths_0()
1726
+ {
1727
+ return new byte [] {
1728
+ 0, 1, 5, 4, 2, 1, 2, 1, 12, 5, 4, 2,
1729
+ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
1730
+ 1, 2, 1, 0
1731
+ };
1732
+ }
1733
+
1734
+ private static final byte _JSON_object_single_lengths[] = init__JSON_object_single_lengths_0();
1735
+
1736
+
1737
+ private static byte[] init__JSON_object_range_lengths_0()
1738
+ {
1739
+ return new byte [] {
1740
+ 0, 0, 1, 1, 0, 0, 0, 0, 2, 1, 1, 0,
1741
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1742
+ 0, 0, 0, 0
1743
+ };
1744
+ }
1745
+
1746
+ private static final byte _JSON_object_range_lengths[] = init__JSON_object_range_lengths_0();
1747
+
1748
+
1749
+ private static byte[] init__JSON_object_index_offsets_0()
1750
+ {
1751
+ return new byte [] {
1752
+ 0, 0, 2, 9, 15, 18, 20, 23, 25, 40, 47, 53,
1753
+ 56, 58, 61, 63, 66, 68, 71, 73, 76, 78, 81, 83,
1754
+ 86, 88, 91, 93
1755
+ };
1756
+ }
1757
+
1758
+ private static final byte _JSON_object_index_offsets[] = init__JSON_object_index_offsets_0();
1759
+
1760
+
1761
+ private static byte[] init__JSON_object_indicies_0()
1762
+ {
1763
+ return new byte [] {
1764
+ 0, 1, 0, 0, 2, 3, 4, 0, 1, 5, 5, 6,
1765
+ 7, 5, 1, 8, 9, 1, 10, 8, 10, 5, 8, 5,
1766
+ 9, 7, 7, 11, 11, 12, 11, 11, 11, 11, 11, 11,
1767
+ 11, 7, 11, 1, 13, 13, 14, 15, 4, 13, 1, 14,
1768
+ 14, 2, 16, 14, 1, 17, 18, 1, 19, 17, 19, 14,
1769
+ 17, 14, 18, 20, 21, 1, 22, 20, 22, 13, 20, 13,
1770
+ 21, 23, 24, 1, 25, 23, 25, 7, 23, 7, 24, 26,
1771
+ 27, 1, 28, 26, 28, 0, 26, 0, 27, 1, 0
1772
+ };
1773
+ }
1774
+
1775
+ private static final byte _JSON_object_indicies[] = init__JSON_object_indicies_0();
1776
+
1777
+
1778
+ private static byte[] init__JSON_object_trans_targs_0()
1779
+ {
1780
+ return new byte [] {
1781
+ 2, 0, 3, 23, 27, 3, 4, 8, 5, 7, 6, 9,
1782
+ 19, 9, 10, 15, 11, 12, 14, 13, 16, 18, 17, 20,
1783
+ 22, 21, 24, 26, 25
1784
+ };
1785
+ }
1786
+
1787
+ private static final byte _JSON_object_trans_targs[] = init__JSON_object_trans_targs_0();
1788
+
1789
+
1790
+ private static byte[] init__JSON_object_trans_actions_0()
1791
+ {
1792
+ return new byte [] {
1793
+ 0, 0, 3, 0, 5, 0, 0, 0, 0, 0, 0, 1,
1794
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1795
+ 0, 0, 0, 0, 0
1796
+ };
1797
+ }
1798
+
1799
+ private static final byte _JSON_object_trans_actions[] = init__JSON_object_trans_actions_0();
1800
+
1801
+
1802
+ static final int JSON_object_start = 1;
1803
+ static final int JSON_object_first_final = 27;
1804
+ static final int JSON_object_error = 0;
1805
+
1806
+ static final int JSON_object_en_main = 1;
1807
+
1808
+
1809
+ // line 694 "Parser.rl"
1810
+
1811
+
1812
+ ParserResult parseObject(int p, int pe) {
1813
+ int cs = EVIL;
1814
+ IRubyObject lastName = null;
1815
+
1816
+ if (parser.maxNesting > 0 && currentNesting > parser.maxNesting) {
1817
+ throw newException(Utils.M_NESTING_ERROR,
1818
+ "nesting of " + currentNesting + " is too deep");
1819
+ }
1820
+
1821
+ // this is guaranteed to be a RubyHash due to the earlier
1822
+ // allocator test at OptionsReader#getClass
1823
+ RubyHash result =
1824
+ (RubyHash)parser.objectClass.newInstance(context,
1825
+ IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
1826
+
1827
+
1828
+ // line 1829 "Parser.java"
1829
+ {
1830
+ cs = JSON_object_start;
1831
+ }
1832
+
1833
+ // line 712 "Parser.rl"
1834
+
1835
+ // line 1836 "Parser.java"
1836
+ {
1837
+ int _klen;
1838
+ int _trans = 0;
1839
+ int _acts;
1840
+ int _nacts;
1841
+ int _keys;
1842
+ int _goto_targ = 0;
1843
+
1844
+ _goto: while (true) {
1845
+ switch ( _goto_targ ) {
1846
+ case 0:
1847
+ if ( p == pe ) {
1848
+ _goto_targ = 4;
1849
+ continue _goto;
1850
+ }
1851
+ if ( cs == 0 ) {
1852
+ _goto_targ = 5;
1853
+ continue _goto;
1854
+ }
1855
+ case 1:
1856
+ _match: do {
1857
+ _keys = _JSON_object_key_offsets[cs];
1858
+ _trans = _JSON_object_index_offsets[cs];
1859
+ _klen = _JSON_object_single_lengths[cs];
1860
+ if ( _klen > 0 ) {
1861
+ int _lower = _keys;
1862
+ int _mid;
1863
+ int _upper = _keys + _klen - 1;
1864
+ while (true) {
1865
+ if ( _upper < _lower )
1866
+ break;
1867
+
1868
+ _mid = _lower + ((_upper-_lower) >> 1);
1869
+ if ( data[p] < _JSON_object_trans_keys[_mid] )
1870
+ _upper = _mid - 1;
1871
+ else if ( data[p] > _JSON_object_trans_keys[_mid] )
1872
+ _lower = _mid + 1;
1873
+ else {
1874
+ _trans += (_mid - _keys);
1875
+ break _match;
1876
+ }
1877
+ }
1878
+ _keys += _klen;
1879
+ _trans += _klen;
1880
+ }
1881
+
1882
+ _klen = _JSON_object_range_lengths[cs];
1883
+ if ( _klen > 0 ) {
1884
+ int _lower = _keys;
1885
+ int _mid;
1886
+ int _upper = _keys + (_klen<<1) - 2;
1887
+ while (true) {
1888
+ if ( _upper < _lower )
1889
+ break;
1890
+
1891
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
1892
+ if ( data[p] < _JSON_object_trans_keys[_mid] )
1893
+ _upper = _mid - 2;
1894
+ else if ( data[p] > _JSON_object_trans_keys[_mid+1] )
1895
+ _lower = _mid + 2;
1896
+ else {
1897
+ _trans += ((_mid - _keys)>>1);
1898
+ break _match;
1899
+ }
1900
+ }
1901
+ _trans += _klen;
1902
+ }
1903
+ } while (false);
1904
+
1905
+ _trans = _JSON_object_indicies[_trans];
1906
+ cs = _JSON_object_trans_targs[_trans];
1907
+
1908
+ if ( _JSON_object_trans_actions[_trans] != 0 ) {
1909
+ _acts = _JSON_object_trans_actions[_trans];
1910
+ _nacts = (int) _JSON_object_actions[_acts++];
1911
+ while ( _nacts-- > 0 )
1912
+ {
1913
+ switch ( _JSON_object_actions[_acts++] )
1914
+ {
1915
+ case 0:
1916
+ // line 652 "Parser.rl"
1917
+ {
1918
+ ParserResult res = parseValue(p, pe);
1919
+ if (res == null) {
1920
+ p--;
1921
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1922
+ } else {
1923
+ result.op_aset(context, lastName, res.result);
1924
+ {p = (( res.p))-1;}
1925
+ }
1926
+ }
1927
+ break;
1928
+ case 1:
1929
+ // line 663 "Parser.rl"
1930
+ {
1931
+ ParserResult res = parseString(p, pe);
1932
+ if (res == null) {
1933
+ p--;
1934
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1935
+ } else {
1936
+ RubyString name = (RubyString)res.result;
1937
+ if (parser.symbolizeNames) {
1938
+ lastName = context.getRuntime().is1_9()
1939
+ ? name.intern19()
1940
+ : name.intern();
1941
+ } else {
1942
+ lastName = name;
1943
+ }
1944
+ {p = (( res.p))-1;}
1945
+ }
1946
+ }
1947
+ break;
1948
+ case 2:
1949
+ // line 681 "Parser.rl"
1950
+ {
1951
+ p--;
1952
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
1953
+ }
1954
+ break;
1955
+ // line 1956 "Parser.java"
1956
+ }
1957
+ }
1958
+ }
1959
+
1960
+ case 2:
1961
+ if ( cs == 0 ) {
1962
+ _goto_targ = 5;
1963
+ continue _goto;
1964
+ }
1965
+ if ( ++p != pe ) {
1966
+ _goto_targ = 1;
1967
+ continue _goto;
1968
+ }
1969
+ case 4:
1970
+ case 5:
1971
+ }
1972
+ break; }
1973
+ }
1974
+
1975
+ // line 713 "Parser.rl"
1976
+
1977
+ if (cs < JSON_object_first_final) {
1978
+ return null;
1979
+ }
1980
+
1981
+ IRubyObject returnedResult = result;
1982
+
1983
+ // attempt to de-serialize object
1984
+ if (parser.createAdditions) {
1985
+ IRubyObject vKlassName = result.op_aref(context, parser.createId);
1986
+ if (!vKlassName.isNil()) {
1987
+ // might throw ArgumentError, we let it propagate
1988
+ IRubyObject klass = parser.info.jsonModule.
1989
+ callMethod(context, "deep_const_get", vKlassName);
1990
+ if (klass.respondsTo("json_creatable?") &&
1991
+ klass.callMethod(context, "json_creatable?").isTrue()) {
1992
+
1993
+ returnedResult = klass.callMethod(context, "json_create", result);
1994
+ }
1995
+ }
1996
+ }
1997
+ return new ParserResult(returnedResult, p + 1);
1998
+ }
1999
+
2000
+
2001
+ // line 2002 "Parser.java"
2002
+ private static byte[] init__JSON_actions_0()
2003
+ {
2004
+ return new byte [] {
2005
+ 0, 1, 0, 1, 1
2006
+ };
2007
+ }
2008
+
2009
+ private static final byte _JSON_actions[] = init__JSON_actions_0();
2010
+
2011
+
2012
+ private static byte[] init__JSON_key_offsets_0()
2013
+ {
2014
+ return new byte [] {
2015
+ 0, 0, 7, 9, 10, 12, 13, 15, 16, 18, 19
2016
+ };
2017
+ }
2018
+
2019
+ private static final byte _JSON_key_offsets[] = init__JSON_key_offsets_0();
2020
+
2021
+
2022
+ private static char[] init__JSON_trans_keys_0()
2023
+ {
2024
+ return new char [] {
2025
+ 13, 32, 47, 91, 123, 9, 10, 42, 47, 42, 42, 47,
2026
+ 10, 42, 47, 42, 42, 47, 10, 13, 32, 47, 9, 10,
2027
+ 0
2028
+ };
2029
+ }
2030
+
2031
+ private static final char _JSON_trans_keys[] = init__JSON_trans_keys_0();
2032
+
2033
+
2034
+ private static byte[] init__JSON_single_lengths_0()
2035
+ {
2036
+ return new byte [] {
2037
+ 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, 3
2038
+ };
2039
+ }
2040
+
2041
+ private static final byte _JSON_single_lengths[] = init__JSON_single_lengths_0();
2042
+
2043
+
2044
+ private static byte[] init__JSON_range_lengths_0()
2045
+ {
2046
+ return new byte [] {
2047
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
2048
+ };
2049
+ }
2050
+
2051
+ private static final byte _JSON_range_lengths[] = init__JSON_range_lengths_0();
2052
+
2053
+
2054
+ private static byte[] init__JSON_index_offsets_0()
2055
+ {
2056
+ return new byte [] {
2057
+ 0, 0, 7, 10, 12, 15, 17, 20, 22, 25, 27
2058
+ };
2059
+ }
2060
+
2061
+ private static final byte _JSON_index_offsets[] = init__JSON_index_offsets_0();
2062
+
2063
+
2064
+ private static byte[] init__JSON_indicies_0()
2065
+ {
2066
+ return new byte [] {
2067
+ 0, 0, 2, 3, 4, 0, 1, 5, 6, 1, 7, 5,
2068
+ 7, 0, 5, 0, 6, 8, 9, 1, 10, 8, 10, 11,
2069
+ 8, 11, 9, 11, 11, 12, 11, 1, 0
2070
+ };
2071
+ }
2072
+
2073
+ private static final byte _JSON_indicies[] = init__JSON_indicies_0();
2074
+
2075
+
2076
+ private static byte[] init__JSON_trans_targs_0()
2077
+ {
2078
+ return new byte [] {
2079
+ 1, 0, 2, 10, 10, 3, 5, 4, 7, 9, 8, 10,
2080
+ 6
2081
+ };
2082
+ }
2083
+
2084
+ private static final byte _JSON_trans_targs[] = init__JSON_trans_targs_0();
2085
+
2086
+
2087
+ private static byte[] init__JSON_trans_actions_0()
2088
+ {
2089
+ return new byte [] {
2090
+ 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0,
2091
+ 0
2092
+ };
2093
+ }
2094
+
2095
+ private static final byte _JSON_trans_actions[] = init__JSON_trans_actions_0();
2096
+
2097
+
2098
+ static final int JSON_start = 1;
2099
+ static final int JSON_first_final = 10;
2100
+ static final int JSON_error = 0;
2101
+
2102
+ static final int JSON_en_main = 1;
2103
+
2104
+
2105
+ // line 771 "Parser.rl"
2106
+
2107
+
2108
+ public IRubyObject parse() {
2109
+ int cs = EVIL;
2110
+ int p, pe;
2111
+ IRubyObject result = null;
2112
+
2113
+
2114
+ // line 2115 "Parser.java"
2115
+ {
2116
+ cs = JSON_start;
2117
+ }
2118
+
2119
+ // line 779 "Parser.rl"
2120
+ p = byteList.begin();
2121
+ pe = p + byteList.length();
2122
+
2123
+ // line 2124 "Parser.java"
2124
+ {
2125
+ int _klen;
2126
+ int _trans = 0;
2127
+ int _acts;
2128
+ int _nacts;
2129
+ int _keys;
2130
+ int _goto_targ = 0;
2131
+
2132
+ _goto: while (true) {
2133
+ switch ( _goto_targ ) {
2134
+ case 0:
2135
+ if ( p == pe ) {
2136
+ _goto_targ = 4;
2137
+ continue _goto;
2138
+ }
2139
+ if ( cs == 0 ) {
2140
+ _goto_targ = 5;
2141
+ continue _goto;
2142
+ }
2143
+ case 1:
2144
+ _match: do {
2145
+ _keys = _JSON_key_offsets[cs];
2146
+ _trans = _JSON_index_offsets[cs];
2147
+ _klen = _JSON_single_lengths[cs];
2148
+ if ( _klen > 0 ) {
2149
+ int _lower = _keys;
2150
+ int _mid;
2151
+ int _upper = _keys + _klen - 1;
2152
+ while (true) {
2153
+ if ( _upper < _lower )
2154
+ break;
2155
+
2156
+ _mid = _lower + ((_upper-_lower) >> 1);
2157
+ if ( data[p] < _JSON_trans_keys[_mid] )
2158
+ _upper = _mid - 1;
2159
+ else if ( data[p] > _JSON_trans_keys[_mid] )
2160
+ _lower = _mid + 1;
2161
+ else {
2162
+ _trans += (_mid - _keys);
2163
+ break _match;
2164
+ }
2165
+ }
2166
+ _keys += _klen;
2167
+ _trans += _klen;
2168
+ }
2169
+
2170
+ _klen = _JSON_range_lengths[cs];
2171
+ if ( _klen > 0 ) {
2172
+ int _lower = _keys;
2173
+ int _mid;
2174
+ int _upper = _keys + (_klen<<1) - 2;
2175
+ while (true) {
2176
+ if ( _upper < _lower )
2177
+ break;
2178
+
2179
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
2180
+ if ( data[p] < _JSON_trans_keys[_mid] )
2181
+ _upper = _mid - 2;
2182
+ else if ( data[p] > _JSON_trans_keys[_mid+1] )
2183
+ _lower = _mid + 2;
2184
+ else {
2185
+ _trans += ((_mid - _keys)>>1);
2186
+ break _match;
2187
+ }
2188
+ }
2189
+ _trans += _klen;
2190
+ }
2191
+ } while (false);
2192
+
2193
+ _trans = _JSON_indicies[_trans];
2194
+ cs = _JSON_trans_targs[_trans];
2195
+
2196
+ if ( _JSON_trans_actions[_trans] != 0 ) {
2197
+ _acts = _JSON_trans_actions[_trans];
2198
+ _nacts = (int) _JSON_actions[_acts++];
2199
+ while ( _nacts-- > 0 )
2200
+ {
2201
+ switch ( _JSON_actions[_acts++] )
2202
+ {
2203
+ case 0:
2204
+ // line 743 "Parser.rl"
2205
+ {
2206
+ currentNesting = 1;
2207
+ ParserResult res = parseObject(p, pe);
2208
+ if (res == null) {
2209
+ p--;
2210
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
2211
+ } else {
2212
+ result = res.result;
2213
+ {p = (( res.p))-1;}
2214
+ }
2215
+ }
2216
+ break;
2217
+ case 1:
2218
+ // line 755 "Parser.rl"
2219
+ {
2220
+ currentNesting = 1;
2221
+ ParserResult res = parseArray(p, pe);
2222
+ if (res == null) {
2223
+ p--;
2224
+ { p += 1; _goto_targ = 5; if (true) continue _goto;}
2225
+ } else {
2226
+ result = res.result;
2227
+ {p = (( res.p))-1;}
2228
+ }
2229
+ }
2230
+ break;
2231
+ // line 2232 "Parser.java"
2232
+ }
2233
+ }
2234
+ }
2235
+
2236
+ case 2:
2237
+ if ( cs == 0 ) {
2238
+ _goto_targ = 5;
2239
+ continue _goto;
2240
+ }
2241
+ if ( ++p != pe ) {
2242
+ _goto_targ = 1;
2243
+ continue _goto;
2244
+ }
2245
+ case 4:
2246
+ case 5:
2247
+ }
2248
+ break; }
2249
+ }
2250
+
2251
+ // line 782 "Parser.rl"
2252
+
2253
+ if (cs >= JSON_first_final && p == pe) {
2254
+ return result;
2255
+ } else {
2256
+ throw unexpectedToken(p, pe);
2257
+ }
2258
+ }
2259
+
2260
+ /**
2261
+ * Returns a subsequence of the source ByteList, based on source
2262
+ * array byte offsets (i.e., the ByteList's own begin offset is not
2263
+ * automatically added).
2264
+ * @param start
2265
+ * @param end
2266
+ */
2267
+ private ByteList absSubSequence(int absStart, int absEnd) {
2268
+ int offset = byteList.begin();
2269
+ return (ByteList)byteList.subSequence(absStart - offset,
2270
+ absEnd - offset);
2271
+ }
2272
+
2273
+ /**
2274
+ * Retrieves a constant directly descended from the <code>JSON</code> module.
2275
+ * @param name The constant name
2276
+ */
2277
+ private IRubyObject getConstant(String name) {
2278
+ return parser.info.jsonModule.getConstant(name);
2279
+ }
2280
+
2281
+ private RaiseException newException(String className, String message) {
2282
+ return Utils.newException(context, className, message);
2283
+ }
2284
+
2285
+ private RaiseException newException(String className, RubyString message) {
2286
+ return Utils.newException(context, className, message);
2287
+ }
2288
+
2289
+ private RaiseException newException(String className,
2290
+ String messageBegin, ByteList messageEnd) {
2291
+ return newException(className,
2292
+ getRuntime().newString(messageBegin).cat(messageEnd));
2293
+ }
2294
+ }
2295
+ }