@Override protected Object doCall(Context cx, Scriptable scope) throws RuntimeException { try { Object obj = new JsonParser(cx, scope).parseValue(json); scope.put(varName, scope, obj); return null; } catch (ParseException e) { throw Throwables.propagate(e); } } });
private Object readValue() throws ParseException { consumeWhitespace(); while (pos < length) { char c = src.charAt(pos++); switch (c) { case '{': return readObject(); case '[': return readArray(); case 't': return readTrue(); case 'f': return readFalse(); case '"': return readString(); case 'n': return readNull(); case '1': case '2': case '0': case '-': return readNumber(c); default: throw new ParseException("Unexpected token: " + c);
final int numberStart = pos - 1; if (c == '-') { c = nextOrNumberError(numberStart); if (!(c >= '0' && c <= '9')) { throw numberError(numberStart, pos); readDigits(); if (c == '.') { pos += 1; c = nextOrNumberError(numberStart); if (!(c >= '0' && c <= '9')) { throw numberError(numberStart, pos); readDigits(); if (c == 'e' || c == 'E') { pos += 1; c = nextOrNumberError(numberStart); if (c == '-' || c == '+') { c = nextOrNumberError(numberStart); throw numberError(numberStart, pos); readDigits();
private Object readObject() throws ParseException { consumeWhitespace(); Scriptable object = cx.newObject(scope); throw new ParseException("Missing comma in object literal"); id = readString(); consume(':'); value = readValue(); throw new ParseException("Unexpected token in object literal"); consumeWhitespace();
public synchronized Object parseValue(String json) throws ParseException { if (json == null) { throw new ParseException("Input string may not be null"); } pos = 0; length = json.length(); src = json; Object value = readValue(); consumeWhitespace(); if (pos < length) { throw new ParseException("Expected end of stream at char " + pos); } return value; }
private char nextOrNumberError(int numberStart) throws ParseException { if (pos >= length) { throw numberError(numberStart, length); } return src.charAt(pos++); }
private void consume(char token) throws ParseException { consumeWhitespace(); if (pos >= length) { throw new ParseException("Expected " + token + " but reached end of stream"); } char c = src.charAt(pos++); if (c == token) { return; } else { throw new ParseException("Expected " + token + " found " + c); } }
throw new ParseException("Invalid character code: \\u" + src.substring(pos)); int code = fromHex(src.charAt(pos + 0)) << 12 | fromHex(src.charAt(pos + 1)) << 8 | fromHex(src.charAt(pos + 2)) << 4 | fromHex(src.charAt(pos + 3)); if (code < 0) { throw new ParseException("Invalid character code: " + src.substring(pos, pos + 4));
private Object readObject() throws ParseException { consumeWhitespace(); Scriptable object = cx.newObject(scope); throw new ParseException("Missing comma in object literal"); id = readString(); consume(':'); value = readValue(); throw new ParseException("Unexpected token in object literal"); consumeWhitespace();
public synchronized Object parseValue(String json) throws ParseException { if (json == null) { throw new ParseException("Input string may not be null"); } pos = 0; length = json.length(); src = json; Object value = readValue(); consumeWhitespace(); if (pos < length) { throw new ParseException("Expected end of stream at char " + pos); } return value; }
private char nextOrNumberError(int numberStart) throws ParseException { if (pos >= length) { throw numberError(numberStart, length); } return src.charAt(pos++); }
private void consume(char token) throws ParseException { consumeWhitespace(); if (pos >= length) { throw new ParseException("Expected " + token + " but reached end of stream"); } char c = src.charAt(pos++); if (c == token) { return; } else { throw new ParseException("Expected " + token + " found " + c); } }
throw new ParseException("Invalid character code: \\u" + src.substring(pos)); int code = fromHex(src.charAt(pos + 0)) << 12 | fromHex(src.charAt(pos + 1)) << 8 | fromHex(src.charAt(pos + 2)) << 4 | fromHex(src.charAt(pos + 3)); if (code < 0) { throw new ParseException("Invalid character code: " + src.substring(pos, pos + 4));
private Object readValue() throws ParseException { consumeWhitespace(); while (pos < length) { char c = src.charAt(pos++); switch (c) { case '{': return readObject(); case '[': return readArray(); case 't': return readTrue(); case 'f': return readFalse(); case '"': return readString(); case 'n': return readNull(); case '1': case '2': case '0': case '-': return readNumber(c); default: throw new ParseException("Unexpected token: " + c);
private Object readObject() throws ParseException { consumeWhitespace(); Scriptable object = cx.newObject(scope); throw new ParseException("Missing comma in object literal"); id = readString(); consume(':'); value = readValue(); throw new ParseException("Unexpected token in object literal"); consumeWhitespace();
private static Object parse(Context cx, Scriptable scope, String jtext) { try { return new JsonParser(cx, scope).parseValue(jtext); } catch (JsonParser.ParseException ex) { throw ScriptRuntime.constructError("SyntaxError", ex.getMessage()); } }
final int numberStart = pos - 1; if (c == '-') { c = nextOrNumberError(numberStart); if (!(c >= '0' && c <= '9')) { throw numberError(numberStart, pos); readDigits(); if (c == '.') { pos += 1; c = nextOrNumberError(numberStart); if (!(c >= '0' && c <= '9')) { throw numberError(numberStart, pos); readDigits(); if (c == 'e' || c == 'E') { pos += 1; c = nextOrNumberError(numberStart); if (c == '-' || c == '+') { c = nextOrNumberError(numberStart); throw numberError(numberStart, pos); readDigits();
public synchronized Object parseValue(String json) throws ParseException { if (json == null) { throw new ParseException("Input string may not be null"); } pos = 0; length = json.length(); src = json; Object value = readValue(); consumeWhitespace(); if (pos < length) { throw new ParseException("Expected end of stream at char " + pos); } return value; }
private char nextOrNumberError(int numberStart) throws ParseException { if (pos >= length) { throw numberError(numberStart, length); } return src.charAt(pos++); }
private void consume(char token) throws ParseException { consumeWhitespace(); if (pos >= length) { throw new ParseException("Expected " + token + " but reached end of stream"); } char c = src.charAt(pos++); if (c == token) { return; } else { throw new ParseException("Expected " + token + " found " + c); } }