json-maglev- 1.5.4

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