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