com.ibm.commons.util.io.json.parser.Json Maven / Gradle / Ivy
The newest version!
/* Generated By:JavaCC: Do not edit this line. Json.java */
package com.ibm.commons.util.io.json.parser;
import com.ibm.commons.util.io.json.*;
import java.util.*;
/**
*
*/
public class Json implements JsonConstants {
public JsonFactory factory;
public String getStringValue(String image) throws ParseException {
int l = image.length()-1; // Leading & trailing quotes, see loop index starting at 1...
StringBuilder sb = new StringBuilder(l);
for (int i = 1; i < l; i++) {
char c = image.charAt(i);
if (c == '\u005c\u005c') {
i++;
if(i='0' && c<='7';
}
private static boolean isHexaDigit(char c) {
return (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f');
}
private static int hexval(char c) throws ParseException {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
case 'A':
return 10;
case 'b':
case 'B':
return 11;
case 'c':
case 'C':
return 12;
case 'd':
case 'D':
return 13;
case 'e':
case 'E':
return 14;
case 'f':
case 'F':
return 15;
}
throw new ParseException("Internal error when evaluating hexadecimal escape sequence");
}
private static int octval(char c) throws ParseException {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
}
throw new ParseException("Internal error when evaluating octal escape sequence");
}
final public Object nullLiteral() throws ParseException, JsonException {
jj_consume_token(NULL);
{if (true) return factory.createNull();}
throw new Error("Missing return statement in function");
}
final public Object booleanLiteral() throws ParseException, JsonException {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TRUE:
jj_consume_token(TRUE);
{if (true) return factory.createBoolean(true);}
break;
case FALSE:
jj_consume_token(FALSE);
{if (true) return factory.createBoolean(false);}
break;
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public Object numericLiteral() throws ParseException, JsonException {
Token t;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case INTEGER_LITERAL:
t = jj_consume_token(INTEGER_LITERAL);
String image=t.image;
if (image.startsWith("0x") || image.startsWith("0X") ) {
String imageWithout0x = image.substring(2);
{if (true) return factory.createNumber((Long.parseLong(imageWithout0x, 16)));}
} else if (image.startsWith("0") && !image.equals("0") && !image.startsWith("0.") ){
String imageWithout0 = image.length()>1 ? image.substring(1) : image;
{if (true) return factory.createNumber((Long.parseLong(imageWithout0, 8)));}
} else {
{if (true) return factory.createNumber((Double.parseDouble(image)));}
}
break;
case FLOATING_POINT_LITERAL:
t = jj_consume_token(FLOATING_POINT_LITERAL);
{if (true) return factory.createNumber((Double.parseDouble(t.image)));}
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public Object stringLiteral() throws ParseException, JsonException {
Token t;
t = jj_consume_token(STRING_LITERAL);
{if (true) return factory.createString(getStringValue(t.image));}
throw new Error("Missing return statement in function");
}
final public Object literal(Object parent, String property) throws ParseException, JsonException {
Object value;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NULL:
value = nullLiteral();
break;
case FALSE:
case TRUE:
value = booleanLiteral();
break;
case INTEGER_LITERAL:
case FLOATING_POINT_LITERAL:
value = numericLiteral();
break;
case STRING_LITERAL:
value = stringLiteral();
break;
case LBRACE:
value = objectLiteral(parent,property);
break;
case LBRACKET:
value = arrayLiteral(parent,property);
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return value;}
throw new Error("Missing return statement in function");
}
final public Object objectLiteral(Object parent, String property) throws ParseException, JsonException {
Object object;
jj_consume_token(LBRACE);
object = factory.createObject(parent,property);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case STRING_LITERAL:
case IDENTIFIER:
propertyNameAndValueList(object);
break;
default:
jj_la1[3] = jj_gen;
;
}
jj_consume_token(RBRACE);
{if (true) return object;}
throw new Error("Missing return statement in function");
}
final public void propertyNameAndValueList(Object parent) throws ParseException, JsonException {
String name; Object value;
name = propertyName();
jj_consume_token(COLON);
value = literal(parent,name);
factory.setProperty(parent, name, value);
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case COMMA:
;
break;
default:
jj_la1[4] = jj_gen;
break label_1;
}
jj_consume_token(COMMA);
name = propertyName();
jj_consume_token(COLON);
value = literal(parent,name);
factory.setProperty(parent, name, value);
}
}
final public String propertyName() throws ParseException {
Token t;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IDENTIFIER:
// JSON extension: we support identifier not enquoted
t = jj_consume_token(IDENTIFIER);
{if (true) return t.image;}
break;
case STRING_LITERAL:
t = jj_consume_token(STRING_LITERAL);
{if (true) return getStringValue(t.image);}
break;
default:
jj_la1[5] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public Object arrayLiteral(Object parent, String property) throws ParseException, JsonException {
List