Exposed API for JsonParser and added methods to Gson to deserialize from a parse tree.
This commit is contained in:
parent
f4c21abda6
commit
2c7cc620d4
|
@ -118,7 +118,7 @@
|
||||||
</workspaceCodeStylesURL>
|
</workspaceCodeStylesURL>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>javacc-maven-plugin</artifactId>
|
<artifactId>javacc-maven-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
<version>4.0</version>
|
<version>4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin -->
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jxr-plugin</artifactId>
|
<artifactId>maven-jxr-plugin</artifactId>
|
||||||
|
|
|
@ -363,16 +363,65 @@ public final class Gson {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonParseException {
|
public <T> T fromJson(Reader json, Type typeOfT) throws JsonParseException {
|
||||||
try {
|
try {
|
||||||
JsonParser parser = new JsonParser(json);
|
JsonElement root = JsonParser.parse(json);
|
||||||
JsonElement root = parser.parse();
|
|
||||||
JsonDeserializationContext context = new JsonDeserializationContextDefault(
|
JsonDeserializationContext context = new JsonDeserializationContextDefault(
|
||||||
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
|
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
|
||||||
T target = (T) context.deserialize(root, typeOfT);
|
T target = (T) context.deserialize(root, typeOfT);
|
||||||
return target;
|
return target;
|
||||||
} catch (TokenMgrError e) {
|
} catch (StackOverflowError e) {
|
||||||
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
} catch (ParseException e) {
|
} catch (OutOfMemoryError e) {
|
||||||
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method deserializes the Json read from the specified parse tree into an object of the
|
||||||
|
* specified type. It is not suitable to use if the specified class is a generic type since it
|
||||||
|
* will not have the generic type information because of the Type Erasure feature of Java.
|
||||||
|
* Therefore, this method should not be used if the desired type is a generic type. Note that
|
||||||
|
* this method works fine if the any of the fields of the specified object are generics, just the
|
||||||
|
* object itself should not be a generic type. For the cases when the object is of generic type,
|
||||||
|
* invoke {@link #fromJson(JsonElement, Type)}.
|
||||||
|
* @param <T> the type of the desired object
|
||||||
|
* @param json the root of the parse tree of {@link JsonElement}s from which the object is to
|
||||||
|
* be deserialized
|
||||||
|
* @param classOfT The class of T
|
||||||
|
* @return an object of type T from the json
|
||||||
|
* @throws JsonParseException if json is not a valid representation for an object of type typeOfT
|
||||||
|
* @since 1.3
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T fromJson(JsonElement json, Class<T> classOfT) throws JsonParseException {
|
||||||
|
T target = classOfT.cast(fromJson(json, (Type) classOfT));
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method deserializes the Json read from the specified parse tree into an object of the
|
||||||
|
* specified type. This method is useful if the specified object is a generic type. For
|
||||||
|
* non-generic objects, use {@link #fromJson(JsonElement, Class)} instead.
|
||||||
|
*
|
||||||
|
* @param <T> the type of the desired object
|
||||||
|
* @param json the root of the parse tree of {@link JsonElement}s from which the object is to
|
||||||
|
* be deserialized
|
||||||
|
* @param typeOfT The specific genericized type of src. You can obtain this type by using the
|
||||||
|
* {@link com.google.gson.reflect.TypeToken} class. For example, to get the type for
|
||||||
|
* {@code Collection<Foo>}, you should use:
|
||||||
|
* <pre>
|
||||||
|
* Type typeOfT = new TypeToken<Collection<Foo>>(){}.getType();
|
||||||
|
* </pre>
|
||||||
|
* @return an object of type T from the json
|
||||||
|
* @throws JsonParseException if json is not a valid representation for an object of type typeOfT
|
||||||
|
* @since 1.3
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonParseException {
|
||||||
|
try {
|
||||||
|
JsonDeserializationContext context = new JsonDeserializationContextDefault(
|
||||||
|
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
|
||||||
|
T target = (T) context.deserialize(json, typeOfT);
|
||||||
|
return target;
|
||||||
} catch (StackOverflowError e) {
|
} catch (StackOverflowError e) {
|
||||||
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
|
|
|
@ -1,668 +1,64 @@
|
||||||
/* Generated By:JavaCC: Do not edit this line. JsonParser.java */
|
/*
|
||||||
|
* Copyright (C) 2009 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
import java.io.Reader;
|
||||||
final class JsonParser implements JsonParserConstants {
|
import java.io.StringReader;
|
||||||
|
|
||||||
final public JsonElement parse() throws ParseException {
|
/**
|
||||||
JsonElement json = null;
|
* A parser to parse Json into a parse tree of {@link JsonElement}s
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
*
|
||||||
case 25:
|
* @author Inderjeet Singh
|
||||||
json = JsonObject();
|
* @author Joel Leitch
|
||||||
break;
|
* @since 1.3
|
||||||
case 29:
|
*/
|
||||||
json = JsonArray();
|
public final class JsonParser {
|
||||||
break;
|
|
||||||
case DIGITS:
|
/**
|
||||||
case NAN:
|
* Parses the specified JSON string into a parse tree
|
||||||
case INFINITY:
|
*
|
||||||
case BOOLEAN:
|
* @param json JSON text
|
||||||
case SINGLE_QUOTE_LITERAL:
|
* @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
* @throws JsonParseException if the specified text is not valid JSON
|
||||||
case 31:
|
* @since 1.3
|
||||||
json = JsonPrimitive();
|
*/
|
||||||
break;
|
public static JsonElement parse(String json) throws JsonParseException {
|
||||||
case NULL:
|
return parse(new StringReader(json));
|
||||||
json = JsonNull();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[0] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
{if (true) return json;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final private JsonObject JsonObject() throws ParseException {
|
/**
|
||||||
JsonObject o = new JsonObject();
|
* Parses the specified JSON string into a parse tree
|
||||||
jj_consume_token(25);
|
*
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
* @param json JSON text
|
||||||
case IDENTIFIER:
|
* @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
|
||||||
case SINGLE_QUOTE_LITERAL:
|
* @throws JsonParseException if the specified text is not valid JSON
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
* @since 1.3
|
||||||
Members(o);
|
*/
|
||||||
break;
|
public static JsonElement parse(Reader json) throws JsonParseException {
|
||||||
default:
|
|
||||||
jj_la1[1] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
jj_consume_token(26);
|
|
||||||
{if (true) return o;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonNull JsonNull() throws ParseException {
|
|
||||||
Token t;
|
|
||||||
t = jj_consume_token(NULL);
|
|
||||||
{if (true) return JsonNull.createJsonNull();}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private void Members(JsonObject o) throws ParseException {
|
|
||||||
Pair(o);
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case 27:
|
|
||||||
jj_consume_token(27);
|
|
||||||
Members(o);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[2] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final private void Pair(JsonObject o) throws ParseException {
|
|
||||||
JsonPrimitive property;
|
|
||||||
JsonElement value;
|
|
||||||
property = JsonMemberName();
|
|
||||||
jj_consume_token(28);
|
|
||||||
value = JsonValue();
|
|
||||||
o.add(property.getAsString(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonMemberName() throws ParseException {
|
|
||||||
Token t; JsonPrimitive value;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case IDENTIFIER:
|
|
||||||
t = jj_consume_token(IDENTIFIER);
|
|
||||||
{if (true) return new JsonPrimitive(t.image);}
|
|
||||||
break;
|
|
||||||
case SINGLE_QUOTE_LITERAL:
|
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
|
||||||
value = JsonString();
|
|
||||||
{if (true) return value;}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[3] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonArray JsonArray() throws ParseException {
|
|
||||||
JsonArray array = new JsonArray();
|
|
||||||
jj_consume_token(29);
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case DIGITS:
|
|
||||||
case NULL:
|
|
||||||
case NAN:
|
|
||||||
case INFINITY:
|
|
||||||
case BOOLEAN:
|
|
||||||
case SINGLE_QUOTE_LITERAL:
|
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
|
||||||
case 25:
|
|
||||||
case 29:
|
|
||||||
case 31:
|
|
||||||
Elements(array);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[4] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
jj_consume_token(30);
|
|
||||||
array.reverse();
|
|
||||||
{if (true) return array;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private void Elements(JsonArray array) throws ParseException {
|
|
||||||
JsonElement element;
|
|
||||||
element = JsonValue();
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case 27:
|
|
||||||
jj_consume_token(27);
|
|
||||||
Elements(array);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[5] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
array.add(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonElement JsonValue() throws ParseException {
|
|
||||||
JsonElement o = null;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case SINGLE_QUOTE_LITERAL:
|
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
|
||||||
o = JsonString();
|
|
||||||
break;
|
|
||||||
case DIGITS:
|
|
||||||
case NAN:
|
|
||||||
case INFINITY:
|
|
||||||
case 31:
|
|
||||||
o = JsonNumber();
|
|
||||||
break;
|
|
||||||
case 25:
|
|
||||||
o = JsonObject();
|
|
||||||
break;
|
|
||||||
case 29:
|
|
||||||
o = JsonArray();
|
|
||||||
break;
|
|
||||||
case BOOLEAN:
|
|
||||||
o = JsonBoolean();
|
|
||||||
break;
|
|
||||||
case NULL:
|
|
||||||
o = JsonNull();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[6] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
{if (true) return o;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonBoolean() throws ParseException {
|
|
||||||
Token t;
|
|
||||||
t = jj_consume_token(BOOLEAN);
|
|
||||||
boolean value = Boolean.valueOf(t.image);
|
|
||||||
{if (true) return new JsonPrimitive(value);}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonPrimitive() throws ParseException {
|
|
||||||
JsonPrimitive value;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case SINGLE_QUOTE_LITERAL:
|
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
|
||||||
value = JsonString();
|
|
||||||
{if (true) return value;}
|
|
||||||
break;
|
|
||||||
case DIGITS:
|
|
||||||
case NAN:
|
|
||||||
case INFINITY:
|
|
||||||
case 31:
|
|
||||||
value = JsonNumber();
|
|
||||||
{if (true) return value;}
|
|
||||||
break;
|
|
||||||
case BOOLEAN:
|
|
||||||
value = JsonBoolean();
|
|
||||||
{if (true) return value;}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[7] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonNumber() throws ParseException {
|
|
||||||
String intpart = null,
|
|
||||||
fracpart = null,
|
|
||||||
exppart = null;
|
|
||||||
JsonPrimitive value;
|
|
||||||
if (jj_2_1(2)) {
|
|
||||||
value = JsonSpecialNumbers();
|
|
||||||
{if (true) return value;}
|
|
||||||
} else {
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case DIGITS:
|
|
||||||
case 31:
|
|
||||||
intpart = JsonInt();
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case 32:
|
|
||||||
fracpart = JsonFrac();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[8] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case E:
|
|
||||||
exppart = JsonExp();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[9] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
Number n;
|
|
||||||
if (exppart != null || fracpart != null) {
|
|
||||||
fracpart = (fracpart == null) ? "" : fracpart;
|
|
||||||
exppart = (exppart == null) ? "" : exppart;
|
|
||||||
n = new java.math.BigDecimal(intpart + fracpart + exppart);
|
|
||||||
} else {
|
|
||||||
n = new java.math.BigInteger(intpart);
|
|
||||||
}
|
|
||||||
{if (true) return new JsonPrimitive(n);}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[10] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonSpecialNumbers() throws ParseException {
|
|
||||||
boolean negative = false;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case NAN:
|
|
||||||
jj_consume_token(NAN);
|
|
||||||
{if (true) return new JsonPrimitive(Double.NaN);}
|
|
||||||
break;
|
|
||||||
case INFINITY:
|
|
||||||
case 31:
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case 31:
|
|
||||||
jj_consume_token(31);
|
|
||||||
negative = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[11] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
jj_consume_token(INFINITY);
|
|
||||||
{if (true) return new JsonPrimitive(negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[12] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private String JsonInt() throws ParseException {
|
|
||||||
String digits;
|
|
||||||
boolean negative = false;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case 31:
|
|
||||||
jj_consume_token(31);
|
|
||||||
negative = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[13] = jj_gen;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
digits = Digits();
|
|
||||||
if(negative)
|
|
||||||
{if (true) return "-" + digits;}
|
|
||||||
{if (true) return digits;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private String JsonFrac() throws ParseException {
|
|
||||||
String digits;
|
|
||||||
jj_consume_token(32);
|
|
||||||
digits = Digits();
|
|
||||||
{if (true) return "." + digits;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private String JsonExp() throws ParseException {
|
|
||||||
Token t;
|
|
||||||
String digits;
|
|
||||||
t = jj_consume_token(E);
|
|
||||||
digits = Digits();
|
|
||||||
{if (true) return t.image + digits;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private String Digits() throws ParseException {
|
|
||||||
Token t;
|
|
||||||
t = jj_consume_token(DIGITS);
|
|
||||||
{if (true) return t.image;}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private JsonPrimitive JsonString() throws ParseException {
|
|
||||||
Token t;
|
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
|
||||||
case SINGLE_QUOTE_LITERAL:
|
|
||||||
t = jj_consume_token(SINGLE_QUOTE_LITERAL);
|
|
||||||
break;
|
|
||||||
case DOUBLE_QUOTE_LITERAL:
|
|
||||||
t = jj_consume_token(DOUBLE_QUOTE_LITERAL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
jj_la1[14] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
String value = StringUnmarshaller.unmarshall(t.image);
|
|
||||||
{if (true) return new JsonPrimitive(value);}
|
|
||||||
throw new Error("Missing return statement in function");
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_2_1(int xla) {
|
|
||||||
jj_la = xla; jj_lastpos = jj_scanpos = token;
|
|
||||||
try { return !jj_3_1(); }
|
|
||||||
catch(LookaheadSuccess ls) { return true; }
|
|
||||||
finally { jj_save(0, xla); }
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_3R_4() {
|
|
||||||
if (jj_scan_token(31)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_3R_3() {
|
|
||||||
Token xsp;
|
|
||||||
xsp = jj_scanpos;
|
|
||||||
if (jj_3R_4()) jj_scanpos = xsp;
|
|
||||||
if (jj_scan_token(INFINITY)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_3_1() {
|
|
||||||
if (jj_3R_1()) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_3R_2() {
|
|
||||||
if (jj_scan_token(NAN)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final private boolean jj_3R_1() {
|
|
||||||
Token xsp;
|
|
||||||
xsp = jj_scanpos;
|
|
||||||
if (jj_3R_2()) {
|
|
||||||
jj_scanpos = xsp;
|
|
||||||
if (jj_3R_3()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonParserTokenManager token_source;
|
|
||||||
SimpleCharStream jj_input_stream;
|
|
||||||
public Token token, jj_nt;
|
|
||||||
private int jj_ntk;
|
|
||||||
private Token jj_scanpos, jj_lastpos;
|
|
||||||
private int jj_la;
|
|
||||||
public boolean lookingAhead = false;
|
|
||||||
private boolean jj_semLA;
|
|
||||||
private int jj_gen;
|
|
||||||
final private int[] jj_la1 = new int[15];
|
|
||||||
static private int[] jj_la1_0;
|
|
||||||
static private int[] jj_la1_1;
|
|
||||||
static {
|
|
||||||
jj_la1_0();
|
|
||||||
jj_la1_1();
|
|
||||||
}
|
|
||||||
private static void jj_la1_0() {
|
|
||||||
jj_la1_0 = new int[] {0xa20187c0,0x18800,0x8000000,0x18800,0xa20187c0,0x8000000,0xa20187c0,0x80018740,0x0,0x20,0x80000040,0x80000000,0x80000300,0x80000000,0x18000,};
|
|
||||||
}
|
|
||||||
private static void jj_la1_1() {
|
|
||||||
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,};
|
|
||||||
}
|
|
||||||
final private JJCalls[] jj_2_rtns = new JJCalls[1];
|
|
||||||
private boolean jj_rescan = false;
|
|
||||||
private int jj_gc = 0;
|
|
||||||
|
|
||||||
public JsonParser(java.io.InputStream stream) {
|
|
||||||
this(stream, null);
|
|
||||||
}
|
|
||||||
public JsonParser(java.io.InputStream stream, String encoding) {
|
|
||||||
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
|
||||||
token_source = new JsonParserTokenManager(jj_input_stream);
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReInit(java.io.InputStream stream) {
|
|
||||||
ReInit(stream, null);
|
|
||||||
}
|
|
||||||
public void ReInit(java.io.InputStream stream, String encoding) {
|
|
||||||
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
|
||||||
token_source.ReInit(jj_input_stream);
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonParser(java.io.Reader stream) {
|
|
||||||
jj_input_stream = new SimpleCharStream(stream, 1, 1);
|
|
||||||
token_source = new JsonParserTokenManager(jj_input_stream);
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReInit(java.io.Reader stream) {
|
|
||||||
jj_input_stream.ReInit(stream, 1, 1);
|
|
||||||
token_source.ReInit(jj_input_stream);
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonParser(JsonParserTokenManager tm) {
|
|
||||||
token_source = tm;
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReInit(JsonParserTokenManager tm) {
|
|
||||||
token_source = tm;
|
|
||||||
token = new Token();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen = 0;
|
|
||||||
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
final private Token jj_consume_token(int kind) throws ParseException {
|
|
||||||
Token oldToken;
|
|
||||||
if ((oldToken = token).next != null) token = token.next;
|
|
||||||
else token = token.next = token_source.getNextToken();
|
|
||||||
jj_ntk = -1;
|
|
||||||
if (token.kind == kind) {
|
|
||||||
jj_gen++;
|
|
||||||
if (++jj_gc > 100) {
|
|
||||||
jj_gc = 0;
|
|
||||||
for (int i = 0; i < jj_2_rtns.length; i++) {
|
|
||||||
JJCalls c = jj_2_rtns[i];
|
|
||||||
while (c != null) {
|
|
||||||
if (c.gen < jj_gen) c.first = null;
|
|
||||||
c = c.next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
token = oldToken;
|
|
||||||
jj_kind = kind;
|
|
||||||
throw generateParseException();
|
|
||||||
}
|
|
||||||
|
|
||||||
static private final class LookaheadSuccess extends java.lang.Error { }
|
|
||||||
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
|
|
||||||
final private boolean jj_scan_token(int kind) {
|
|
||||||
if (jj_scanpos == jj_lastpos) {
|
|
||||||
jj_la--;
|
|
||||||
if (jj_scanpos.next == null) {
|
|
||||||
jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
|
|
||||||
} else {
|
|
||||||
jj_lastpos = jj_scanpos = jj_scanpos.next;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
jj_scanpos = jj_scanpos.next;
|
|
||||||
}
|
|
||||||
if (jj_rescan) {
|
|
||||||
int i = 0; Token tok = token;
|
|
||||||
while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
|
|
||||||
if (tok != null) jj_add_error_token(kind, i);
|
|
||||||
}
|
|
||||||
if (jj_scanpos.kind != kind) return true;
|
|
||||||
if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final public Token getNextToken() {
|
|
||||||
if (token.next != null) token = token.next;
|
|
||||||
else token = token.next = token_source.getNextToken();
|
|
||||||
jj_ntk = -1;
|
|
||||||
jj_gen++;
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
final public Token getToken(int index) {
|
|
||||||
Token t = lookingAhead ? jj_scanpos : token;
|
|
||||||
for (int i = 0; i < index; i++) {
|
|
||||||
if (t.next != null) t = t.next;
|
|
||||||
else t = t.next = token_source.getNextToken();
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
final private int jj_ntk() {
|
|
||||||
if ((jj_nt=token.next) == null)
|
|
||||||
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
|
|
||||||
else
|
|
||||||
return (jj_ntk = jj_nt.kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
private java.util.Vector jj_expentries = new java.util.Vector();
|
|
||||||
private int[] jj_expentry;
|
|
||||||
private int jj_kind = -1;
|
|
||||||
private int[] jj_lasttokens = new int[100];
|
|
||||||
private int jj_endpos;
|
|
||||||
|
|
||||||
private void jj_add_error_token(int kind, int pos) {
|
|
||||||
if (pos >= 100) return;
|
|
||||||
if (pos == jj_endpos + 1) {
|
|
||||||
jj_lasttokens[jj_endpos++] = kind;
|
|
||||||
} else if (jj_endpos != 0) {
|
|
||||||
jj_expentry = new int[jj_endpos];
|
|
||||||
for (int i = 0; i < jj_endpos; i++) {
|
|
||||||
jj_expentry[i] = jj_lasttokens[i];
|
|
||||||
}
|
|
||||||
boolean exists = false;
|
|
||||||
for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) {
|
|
||||||
int[] oldentry = (int[])(e.nextElement());
|
|
||||||
if (oldentry.length == jj_expentry.length) {
|
|
||||||
exists = true;
|
|
||||||
for (int i = 0; i < jj_expentry.length; i++) {
|
|
||||||
if (oldentry[i] != jj_expentry[i]) {
|
|
||||||
exists = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (exists) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!exists) jj_expentries.addElement(jj_expentry);
|
|
||||||
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParseException generateParseException() {
|
|
||||||
jj_expentries.removeAllElements();
|
|
||||||
boolean[] la1tokens = new boolean[33];
|
|
||||||
for (int i = 0; i < 33; i++) {
|
|
||||||
la1tokens[i] = false;
|
|
||||||
}
|
|
||||||
if (jj_kind >= 0) {
|
|
||||||
la1tokens[jj_kind] = true;
|
|
||||||
jj_kind = -1;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 15; i++) {
|
|
||||||
if (jj_la1[i] == jj_gen) {
|
|
||||||
for (int j = 0; j < 32; j++) {
|
|
||||||
if ((jj_la1_0[i] & (1<<j)) != 0) {
|
|
||||||
la1tokens[j] = true;
|
|
||||||
}
|
|
||||||
if ((jj_la1_1[i] & (1<<j)) != 0) {
|
|
||||||
la1tokens[32+j] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 33; i++) {
|
|
||||||
if (la1tokens[i]) {
|
|
||||||
jj_expentry = new int[1];
|
|
||||||
jj_expentry[0] = i;
|
|
||||||
jj_expentries.addElement(jj_expentry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jj_endpos = 0;
|
|
||||||
jj_rescan_token();
|
|
||||||
jj_add_error_token(0, 0);
|
|
||||||
int[][] exptokseq = new int[jj_expentries.size()][];
|
|
||||||
for (int i = 0; i < jj_expentries.size(); i++) {
|
|
||||||
exptokseq[i] = (int[])jj_expentries.elementAt(i);
|
|
||||||
}
|
|
||||||
return new ParseException(token, exptokseq, tokenImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
final public void enable_tracing() {
|
|
||||||
}
|
|
||||||
|
|
||||||
final public void disable_tracing() {
|
|
||||||
}
|
|
||||||
|
|
||||||
final private void jj_rescan_token() {
|
|
||||||
jj_rescan = true;
|
|
||||||
for (int i = 0; i < 1; i++) {
|
|
||||||
try {
|
try {
|
||||||
JJCalls p = jj_2_rtns[i];
|
JsonParserImpl parser = new JsonParserImpl(json);
|
||||||
do {
|
return parser.parse();
|
||||||
if (p.gen > jj_gen) {
|
} catch (TokenMgrError e) {
|
||||||
jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
switch (i) {
|
} catch (ParseException e) {
|
||||||
case 0: jj_3_1(); break;
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
}
|
} catch (StackOverflowError e) {
|
||||||
}
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
p = p.next;
|
} catch (OutOfMemoryError e) {
|
||||||
} while (p != null);
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
} catch(LookaheadSuccess ls) { }
|
|
||||||
}
|
}
|
||||||
jj_rescan = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final private void jj_save(int index, int xla) {
|
|
||||||
JJCalls p = jj_2_rtns[index];
|
|
||||||
while (p.gen > jj_gen) {
|
|
||||||
if (p.next == null) { p = p.next = new JJCalls(); break; }
|
|
||||||
p = p.next;
|
|
||||||
}
|
|
||||||
p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class JJCalls {
|
|
||||||
int gen;
|
|
||||||
Token first;
|
|
||||||
int arg;
|
|
||||||
JJCalls next;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
668
gson/src/main/java/com/google/gson/JsonParserImpl.java
Normal file
668
gson/src/main/java/com/google/gson/JsonParserImpl.java
Normal file
|
@ -0,0 +1,668 @@
|
||||||
|
/* Generated By:JavaCC: Do not edit this line. JsonParserImpl.java */
|
||||||
|
package com.google.gson;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
final class JsonParserImpl implements JsonParserImplConstants {
|
||||||
|
|
||||||
|
final public JsonElement parse() throws ParseException {
|
||||||
|
JsonElement json = null;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 25:
|
||||||
|
json = JsonObject();
|
||||||
|
break;
|
||||||
|
case 29:
|
||||||
|
json = JsonArray();
|
||||||
|
break;
|
||||||
|
case DIGITS:
|
||||||
|
case NAN:
|
||||||
|
case INFINITY:
|
||||||
|
case BOOLEAN:
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
case 31:
|
||||||
|
json = JsonPrimitive();
|
||||||
|
break;
|
||||||
|
case NULL:
|
||||||
|
json = JsonNull();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[0] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
{if (true) return json;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonObject JsonObject() throws ParseException {
|
||||||
|
JsonObject o = new JsonObject();
|
||||||
|
jj_consume_token(25);
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case IDENTIFIER:
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
Members(o);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[1] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
jj_consume_token(26);
|
||||||
|
{if (true) return o;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonNull JsonNull() throws ParseException {
|
||||||
|
Token t;
|
||||||
|
t = jj_consume_token(NULL);
|
||||||
|
{if (true) return JsonNull.createJsonNull();}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private void Members(JsonObject o) throws ParseException {
|
||||||
|
Pair(o);
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 27:
|
||||||
|
jj_consume_token(27);
|
||||||
|
Members(o);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[2] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final private void Pair(JsonObject o) throws ParseException {
|
||||||
|
JsonPrimitive property;
|
||||||
|
JsonElement value;
|
||||||
|
property = JsonMemberName();
|
||||||
|
jj_consume_token(28);
|
||||||
|
value = JsonValue();
|
||||||
|
o.add(property.getAsString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonMemberName() throws ParseException {
|
||||||
|
Token t; JsonPrimitive value;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case IDENTIFIER:
|
||||||
|
t = jj_consume_token(IDENTIFIER);
|
||||||
|
{if (true) return new JsonPrimitive(t.image);}
|
||||||
|
break;
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
value = JsonString();
|
||||||
|
{if (true) return value;}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[3] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonArray JsonArray() throws ParseException {
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
jj_consume_token(29);
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case DIGITS:
|
||||||
|
case NULL:
|
||||||
|
case NAN:
|
||||||
|
case INFINITY:
|
||||||
|
case BOOLEAN:
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
case 25:
|
||||||
|
case 29:
|
||||||
|
case 31:
|
||||||
|
Elements(array);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[4] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
jj_consume_token(30);
|
||||||
|
array.reverse();
|
||||||
|
{if (true) return array;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private void Elements(JsonArray array) throws ParseException {
|
||||||
|
JsonElement element;
|
||||||
|
element = JsonValue();
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 27:
|
||||||
|
jj_consume_token(27);
|
||||||
|
Elements(array);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[5] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
array.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonElement JsonValue() throws ParseException {
|
||||||
|
JsonElement o = null;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
o = JsonString();
|
||||||
|
break;
|
||||||
|
case DIGITS:
|
||||||
|
case NAN:
|
||||||
|
case INFINITY:
|
||||||
|
case 31:
|
||||||
|
o = JsonNumber();
|
||||||
|
break;
|
||||||
|
case 25:
|
||||||
|
o = JsonObject();
|
||||||
|
break;
|
||||||
|
case 29:
|
||||||
|
o = JsonArray();
|
||||||
|
break;
|
||||||
|
case BOOLEAN:
|
||||||
|
o = JsonBoolean();
|
||||||
|
break;
|
||||||
|
case NULL:
|
||||||
|
o = JsonNull();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[6] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
{if (true) return o;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonBoolean() throws ParseException {
|
||||||
|
Token t;
|
||||||
|
t = jj_consume_token(BOOLEAN);
|
||||||
|
boolean value = Boolean.valueOf(t.image);
|
||||||
|
{if (true) return new JsonPrimitive(value);}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonPrimitive() throws ParseException {
|
||||||
|
JsonPrimitive value;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
value = JsonString();
|
||||||
|
{if (true) return value;}
|
||||||
|
break;
|
||||||
|
case DIGITS:
|
||||||
|
case NAN:
|
||||||
|
case INFINITY:
|
||||||
|
case 31:
|
||||||
|
value = JsonNumber();
|
||||||
|
{if (true) return value;}
|
||||||
|
break;
|
||||||
|
case BOOLEAN:
|
||||||
|
value = JsonBoolean();
|
||||||
|
{if (true) return value;}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[7] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonNumber() throws ParseException {
|
||||||
|
String intpart = null,
|
||||||
|
fracpart = null,
|
||||||
|
exppart = null;
|
||||||
|
JsonPrimitive value;
|
||||||
|
if (jj_2_1(2)) {
|
||||||
|
value = JsonSpecialNumbers();
|
||||||
|
{if (true) return value;}
|
||||||
|
} else {
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case DIGITS:
|
||||||
|
case 31:
|
||||||
|
intpart = JsonInt();
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 32:
|
||||||
|
fracpart = JsonFrac();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[8] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case E:
|
||||||
|
exppart = JsonExp();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[9] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
Number n;
|
||||||
|
if (exppart != null || fracpart != null) {
|
||||||
|
fracpart = (fracpart == null) ? "" : fracpart;
|
||||||
|
exppart = (exppart == null) ? "" : exppart;
|
||||||
|
n = new java.math.BigDecimal(intpart + fracpart + exppart);
|
||||||
|
} else {
|
||||||
|
n = new java.math.BigInteger(intpart);
|
||||||
|
}
|
||||||
|
{if (true) return new JsonPrimitive(n);}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[10] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonSpecialNumbers() throws ParseException {
|
||||||
|
boolean negative = false;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case NAN:
|
||||||
|
jj_consume_token(NAN);
|
||||||
|
{if (true) return new JsonPrimitive(Double.NaN);}
|
||||||
|
break;
|
||||||
|
case INFINITY:
|
||||||
|
case 31:
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 31:
|
||||||
|
jj_consume_token(31);
|
||||||
|
negative = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[11] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
jj_consume_token(INFINITY);
|
||||||
|
{if (true) return new JsonPrimitive(negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[12] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private String JsonInt() throws ParseException {
|
||||||
|
String digits;
|
||||||
|
boolean negative = false;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case 31:
|
||||||
|
jj_consume_token(31);
|
||||||
|
negative = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[13] = jj_gen;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
digits = Digits();
|
||||||
|
if(negative)
|
||||||
|
{if (true) return "-" + digits;}
|
||||||
|
{if (true) return digits;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private String JsonFrac() throws ParseException {
|
||||||
|
String digits;
|
||||||
|
jj_consume_token(32);
|
||||||
|
digits = Digits();
|
||||||
|
{if (true) return "." + digits;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private String JsonExp() throws ParseException {
|
||||||
|
Token t;
|
||||||
|
String digits;
|
||||||
|
t = jj_consume_token(E);
|
||||||
|
digits = Digits();
|
||||||
|
{if (true) return t.image + digits;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private String Digits() throws ParseException {
|
||||||
|
Token t;
|
||||||
|
t = jj_consume_token(DIGITS);
|
||||||
|
{if (true) return t.image;}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private JsonPrimitive JsonString() throws ParseException {
|
||||||
|
Token t;
|
||||||
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
|
case SINGLE_QUOTE_LITERAL:
|
||||||
|
t = jj_consume_token(SINGLE_QUOTE_LITERAL);
|
||||||
|
break;
|
||||||
|
case DOUBLE_QUOTE_LITERAL:
|
||||||
|
t = jj_consume_token(DOUBLE_QUOTE_LITERAL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
jj_la1[14] = jj_gen;
|
||||||
|
jj_consume_token(-1);
|
||||||
|
throw new ParseException();
|
||||||
|
}
|
||||||
|
String value = StringUnmarshaller.unmarshall(t.image);
|
||||||
|
{if (true) return new JsonPrimitive(value);}
|
||||||
|
throw new Error("Missing return statement in function");
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_2_1(int xla) {
|
||||||
|
jj_la = xla; jj_lastpos = jj_scanpos = token;
|
||||||
|
try { return !jj_3_1(); }
|
||||||
|
catch(LookaheadSuccess ls) { return true; }
|
||||||
|
finally { jj_save(0, xla); }
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_3R_4() {
|
||||||
|
if (jj_scan_token(31)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_3R_3() {
|
||||||
|
Token xsp;
|
||||||
|
xsp = jj_scanpos;
|
||||||
|
if (jj_3R_4()) jj_scanpos = xsp;
|
||||||
|
if (jj_scan_token(INFINITY)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_3_1() {
|
||||||
|
if (jj_3R_1()) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_3R_2() {
|
||||||
|
if (jj_scan_token(NAN)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private boolean jj_3R_1() {
|
||||||
|
Token xsp;
|
||||||
|
xsp = jj_scanpos;
|
||||||
|
if (jj_3R_2()) {
|
||||||
|
jj_scanpos = xsp;
|
||||||
|
if (jj_3R_3()) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonParserImplTokenManager token_source;
|
||||||
|
SimpleCharStream jj_input_stream;
|
||||||
|
public Token token, jj_nt;
|
||||||
|
private int jj_ntk;
|
||||||
|
private Token jj_scanpos, jj_lastpos;
|
||||||
|
private int jj_la;
|
||||||
|
public boolean lookingAhead = false;
|
||||||
|
private boolean jj_semLA;
|
||||||
|
private int jj_gen;
|
||||||
|
final private int[] jj_la1 = new int[15];
|
||||||
|
static private int[] jj_la1_0;
|
||||||
|
static private int[] jj_la1_1;
|
||||||
|
static {
|
||||||
|
jj_la1_0();
|
||||||
|
jj_la1_1();
|
||||||
|
}
|
||||||
|
private static void jj_la1_0() {
|
||||||
|
jj_la1_0 = new int[] {0xa20187c0,0x18800,0x8000000,0x18800,0xa20187c0,0x8000000,0xa20187c0,0x80018740,0x0,0x20,0x80000040,0x80000000,0x80000300,0x80000000,0x18000,};
|
||||||
|
}
|
||||||
|
private static void jj_la1_1() {
|
||||||
|
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,};
|
||||||
|
}
|
||||||
|
final private JJCalls[] jj_2_rtns = new JJCalls[1];
|
||||||
|
private boolean jj_rescan = false;
|
||||||
|
private int jj_gc = 0;
|
||||||
|
|
||||||
|
public JsonParserImpl(java.io.InputStream stream) {
|
||||||
|
this(stream, null);
|
||||||
|
}
|
||||||
|
public JsonParserImpl(java.io.InputStream stream, String encoding) {
|
||||||
|
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
||||||
|
token_source = new JsonParserImplTokenManager(jj_input_stream);
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReInit(java.io.InputStream stream) {
|
||||||
|
ReInit(stream, null);
|
||||||
|
}
|
||||||
|
public void ReInit(java.io.InputStream stream, String encoding) {
|
||||||
|
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
|
||||||
|
token_source.ReInit(jj_input_stream);
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonParserImpl(java.io.Reader stream) {
|
||||||
|
jj_input_stream = new SimpleCharStream(stream, 1, 1);
|
||||||
|
token_source = new JsonParserImplTokenManager(jj_input_stream);
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReInit(java.io.Reader stream) {
|
||||||
|
jj_input_stream.ReInit(stream, 1, 1);
|
||||||
|
token_source.ReInit(jj_input_stream);
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonParserImpl(JsonParserImplTokenManager tm) {
|
||||||
|
token_source = tm;
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReInit(JsonParserImplTokenManager tm) {
|
||||||
|
token_source = tm;
|
||||||
|
token = new Token();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen = 0;
|
||||||
|
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
final private Token jj_consume_token(int kind) throws ParseException {
|
||||||
|
Token oldToken;
|
||||||
|
if ((oldToken = token).next != null) token = token.next;
|
||||||
|
else token = token.next = token_source.getNextToken();
|
||||||
|
jj_ntk = -1;
|
||||||
|
if (token.kind == kind) {
|
||||||
|
jj_gen++;
|
||||||
|
if (++jj_gc > 100) {
|
||||||
|
jj_gc = 0;
|
||||||
|
for (int i = 0; i < jj_2_rtns.length; i++) {
|
||||||
|
JJCalls c = jj_2_rtns[i];
|
||||||
|
while (c != null) {
|
||||||
|
if (c.gen < jj_gen) c.first = null;
|
||||||
|
c = c.next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
token = oldToken;
|
||||||
|
jj_kind = kind;
|
||||||
|
throw generateParseException();
|
||||||
|
}
|
||||||
|
|
||||||
|
static private final class LookaheadSuccess extends java.lang.Error { }
|
||||||
|
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
|
||||||
|
final private boolean jj_scan_token(int kind) {
|
||||||
|
if (jj_scanpos == jj_lastpos) {
|
||||||
|
jj_la--;
|
||||||
|
if (jj_scanpos.next == null) {
|
||||||
|
jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
|
||||||
|
} else {
|
||||||
|
jj_lastpos = jj_scanpos = jj_scanpos.next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jj_scanpos = jj_scanpos.next;
|
||||||
|
}
|
||||||
|
if (jj_rescan) {
|
||||||
|
int i = 0; Token tok = token;
|
||||||
|
while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
|
||||||
|
if (tok != null) jj_add_error_token(kind, i);
|
||||||
|
}
|
||||||
|
if (jj_scanpos.kind != kind) return true;
|
||||||
|
if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public Token getNextToken() {
|
||||||
|
if (token.next != null) token = token.next;
|
||||||
|
else token = token.next = token_source.getNextToken();
|
||||||
|
jj_ntk = -1;
|
||||||
|
jj_gen++;
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public Token getToken(int index) {
|
||||||
|
Token t = lookingAhead ? jj_scanpos : token;
|
||||||
|
for (int i = 0; i < index; i++) {
|
||||||
|
if (t.next != null) t = t.next;
|
||||||
|
else t = t.next = token_source.getNextToken();
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private int jj_ntk() {
|
||||||
|
if ((jj_nt=token.next) == null)
|
||||||
|
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
|
||||||
|
else
|
||||||
|
return (jj_ntk = jj_nt.kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
private java.util.Vector jj_expentries = new java.util.Vector();
|
||||||
|
private int[] jj_expentry;
|
||||||
|
private int jj_kind = -1;
|
||||||
|
private int[] jj_lasttokens = new int[100];
|
||||||
|
private int jj_endpos;
|
||||||
|
|
||||||
|
private void jj_add_error_token(int kind, int pos) {
|
||||||
|
if (pos >= 100) return;
|
||||||
|
if (pos == jj_endpos + 1) {
|
||||||
|
jj_lasttokens[jj_endpos++] = kind;
|
||||||
|
} else if (jj_endpos != 0) {
|
||||||
|
jj_expentry = new int[jj_endpos];
|
||||||
|
for (int i = 0; i < jj_endpos; i++) {
|
||||||
|
jj_expentry[i] = jj_lasttokens[i];
|
||||||
|
}
|
||||||
|
boolean exists = false;
|
||||||
|
for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) {
|
||||||
|
int[] oldentry = (int[])(e.nextElement());
|
||||||
|
if (oldentry.length == jj_expentry.length) {
|
||||||
|
exists = true;
|
||||||
|
for (int i = 0; i < jj_expentry.length; i++) {
|
||||||
|
if (oldentry[i] != jj_expentry[i]) {
|
||||||
|
exists = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exists) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!exists) jj_expentries.addElement(jj_expentry);
|
||||||
|
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParseException generateParseException() {
|
||||||
|
jj_expentries.removeAllElements();
|
||||||
|
boolean[] la1tokens = new boolean[33];
|
||||||
|
for (int i = 0; i < 33; i++) {
|
||||||
|
la1tokens[i] = false;
|
||||||
|
}
|
||||||
|
if (jj_kind >= 0) {
|
||||||
|
la1tokens[jj_kind] = true;
|
||||||
|
jj_kind = -1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
if (jj_la1[i] == jj_gen) {
|
||||||
|
for (int j = 0; j < 32; j++) {
|
||||||
|
if ((jj_la1_0[i] & (1<<j)) != 0) {
|
||||||
|
la1tokens[j] = true;
|
||||||
|
}
|
||||||
|
if ((jj_la1_1[i] & (1<<j)) != 0) {
|
||||||
|
la1tokens[32+j] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 33; i++) {
|
||||||
|
if (la1tokens[i]) {
|
||||||
|
jj_expentry = new int[1];
|
||||||
|
jj_expentry[0] = i;
|
||||||
|
jj_expentries.addElement(jj_expentry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jj_endpos = 0;
|
||||||
|
jj_rescan_token();
|
||||||
|
jj_add_error_token(0, 0);
|
||||||
|
int[][] exptokseq = new int[jj_expentries.size()][];
|
||||||
|
for (int i = 0; i < jj_expentries.size(); i++) {
|
||||||
|
exptokseq[i] = (int[])jj_expentries.elementAt(i);
|
||||||
|
}
|
||||||
|
return new ParseException(token, exptokseq, tokenImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
final public void enable_tracing() {
|
||||||
|
}
|
||||||
|
|
||||||
|
final public void disable_tracing() {
|
||||||
|
}
|
||||||
|
|
||||||
|
final private void jj_rescan_token() {
|
||||||
|
jj_rescan = true;
|
||||||
|
for (int i = 0; i < 1; i++) {
|
||||||
|
try {
|
||||||
|
JJCalls p = jj_2_rtns[i];
|
||||||
|
do {
|
||||||
|
if (p.gen > jj_gen) {
|
||||||
|
jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
|
||||||
|
switch (i) {
|
||||||
|
case 0: jj_3_1(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p = p.next;
|
||||||
|
} while (p != null);
|
||||||
|
} catch(LookaheadSuccess ls) { }
|
||||||
|
}
|
||||||
|
jj_rescan = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private void jj_save(int index, int xla) {
|
||||||
|
JJCalls p = jj_2_rtns[index];
|
||||||
|
while (p.gen > jj_gen) {
|
||||||
|
if (p.next == null) { p = p.next = new JJCalls(); break; }
|
||||||
|
p = p.next;
|
||||||
|
}
|
||||||
|
p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class JJCalls {
|
||||||
|
int gen;
|
||||||
|
Token first;
|
||||||
|
int arg;
|
||||||
|
JJCalls next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
136
gson/src/main/java/com/google/gson/JsonParserConstants.java → gson/src/main/java/com/google/gson/JsonParserImplConstants.java
Executable file → Normal file
136
gson/src/main/java/com/google/gson/JsonParserConstants.java → gson/src/main/java/com/google/gson/JsonParserImplConstants.java
Executable file → Normal file
|
@ -1,68 +1,68 @@
|
||||||
/* Generated By:JavaCC: Do not edit this line. JsonParserConstants.java */
|
/* Generated By:JavaCC: Do not edit this line. JsonParserImplConstants.java */
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
interface JsonParserConstants {
|
interface JsonParserImplConstants {
|
||||||
|
|
||||||
int EOF = 0;
|
int EOF = 0;
|
||||||
int E = 5;
|
int E = 5;
|
||||||
int DIGITS = 6;
|
int DIGITS = 6;
|
||||||
int NULL = 7;
|
int NULL = 7;
|
||||||
int NAN = 8;
|
int NAN = 8;
|
||||||
int INFINITY = 9;
|
int INFINITY = 9;
|
||||||
int BOOLEAN = 10;
|
int BOOLEAN = 10;
|
||||||
int IDENTIFIER = 11;
|
int IDENTIFIER = 11;
|
||||||
int HEX_CHAR = 12;
|
int HEX_CHAR = 12;
|
||||||
int UNICODE_CHAR = 13;
|
int UNICODE_CHAR = 13;
|
||||||
int ESCAPE_CHAR = 14;
|
int ESCAPE_CHAR = 14;
|
||||||
int SINGLE_QUOTE_LITERAL = 15;
|
int SINGLE_QUOTE_LITERAL = 15;
|
||||||
int DOUBLE_QUOTE_LITERAL = 16;
|
int DOUBLE_QUOTE_LITERAL = 16;
|
||||||
int QUOTE = 17;
|
int QUOTE = 17;
|
||||||
int ENDQUOTE = 19;
|
int ENDQUOTE = 19;
|
||||||
int CHAR = 20;
|
int CHAR = 20;
|
||||||
int CNTRL_ESC = 21;
|
int CNTRL_ESC = 21;
|
||||||
int HEX = 23;
|
int HEX = 23;
|
||||||
int HEX_ESC = 24;
|
int HEX_ESC = 24;
|
||||||
|
|
||||||
int DEFAULT = 0;
|
int DEFAULT = 0;
|
||||||
int STRING_STATE = 1;
|
int STRING_STATE = 1;
|
||||||
int ESC_STATE = 2;
|
int ESC_STATE = 2;
|
||||||
int HEX_STATE = 3;
|
int HEX_STATE = 3;
|
||||||
|
|
||||||
String[] tokenImage = {
|
String[] tokenImage = {
|
||||||
"<EOF>",
|
"<EOF>",
|
||||||
"\" \"",
|
"\" \"",
|
||||||
"\"\\t\"",
|
"\"\\t\"",
|
||||||
"\"\\n\"",
|
"\"\\n\"",
|
||||||
"\"\\r\"",
|
"\"\\r\"",
|
||||||
"<E>",
|
"<E>",
|
||||||
"<DIGITS>",
|
"<DIGITS>",
|
||||||
"\"null\"",
|
"\"null\"",
|
||||||
"\"NaN\"",
|
"\"NaN\"",
|
||||||
"\"Infinity\"",
|
"\"Infinity\"",
|
||||||
"<BOOLEAN>",
|
"<BOOLEAN>",
|
||||||
"<IDENTIFIER>",
|
"<IDENTIFIER>",
|
||||||
"<HEX_CHAR>",
|
"<HEX_CHAR>",
|
||||||
"<UNICODE_CHAR>",
|
"<UNICODE_CHAR>",
|
||||||
"<ESCAPE_CHAR>",
|
"<ESCAPE_CHAR>",
|
||||||
"<SINGLE_QUOTE_LITERAL>",
|
"<SINGLE_QUOTE_LITERAL>",
|
||||||
"<DOUBLE_QUOTE_LITERAL>",
|
"<DOUBLE_QUOTE_LITERAL>",
|
||||||
"\"\\\"\"",
|
"\"\\\"\"",
|
||||||
"\"\\\\\"",
|
"\"\\\\\"",
|
||||||
"<ENDQUOTE>",
|
"<ENDQUOTE>",
|
||||||
"<CHAR>",
|
"<CHAR>",
|
||||||
"<CNTRL_ESC>",
|
"<CNTRL_ESC>",
|
||||||
"\"u\"",
|
"\"u\"",
|
||||||
"<HEX>",
|
"<HEX>",
|
||||||
"<HEX_ESC>",
|
"<HEX_ESC>",
|
||||||
"\"{\"",
|
"\"{\"",
|
||||||
"\"}\"",
|
"\"}\"",
|
||||||
"\",\"",
|
"\",\"",
|
||||||
"\":\"",
|
"\":\"",
|
||||||
"\"[\"",
|
"\"[\"",
|
||||||
"\"]\"",
|
"\"]\"",
|
||||||
"\"-\"",
|
"\"-\"",
|
||||||
"\".\"",
|
"\".\"",
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
2294
gson/src/main/java/com/google/gson/JsonParserTokenManager.java → gson/src/main/java/com/google/gson/JsonParserImplTokenManager.java
Executable file → Normal file
2294
gson/src/main/java/com/google/gson/JsonParserTokenManager.java → gson/src/main/java/com/google/gson/JsonParserImplTokenManager.java
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
|
@ -9,16 +9,16 @@ options {
|
||||||
UNICODE_INPUT = true;
|
UNICODE_INPUT = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PARSER_BEGIN(JsonParser)
|
PARSER_BEGIN(JsonParserImpl)
|
||||||
|
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
final class JsonParser {
|
final class JsonParserImpl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PARSER_END(JsonParser)
|
PARSER_END(JsonParserImpl)
|
||||||
|
|
||||||
SKIP : { " " | "\t" | "\n" | "\r" }
|
SKIP : { " " | "\t" | "\n" | "\r" }
|
||||||
/*
|
/*
|
||||||
|
|
29
gson/src/test/java/com/google/gson/JsonParserTest.java
Normal file
29
gson/src/test/java/com/google/gson/JsonParserTest.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package com.google.gson;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for {@link JsonParser}
|
||||||
|
*
|
||||||
|
* @author Inderjeet Singh
|
||||||
|
*/
|
||||||
|
public class JsonParserTest extends TestCase {
|
||||||
|
|
||||||
|
public void testParseString() {
|
||||||
|
String json = "{a:10,b:'c'}";
|
||||||
|
JsonElement e = JsonParser.parse(json);
|
||||||
|
assertTrue(e.isJsonObject());
|
||||||
|
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
||||||
|
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testParseReader() {
|
||||||
|
StringReader reader = new StringReader("{a:10,b:'c'}");
|
||||||
|
JsonElement e = JsonParser.parse(reader);
|
||||||
|
assertTrue(e.isJsonObject());
|
||||||
|
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
||||||
|
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user