/** * Report an error. * * @param errorType The error type * @param message Error message. * @return ParserException upon failure. Caller should throw and not ignore */ protected final ParserException error(final JSErrorType errorType, final String message) { // TODO - column needs to account for tabs. final int position = Token.descPosition(token); final int column = position - linePosition; final String formatted = ErrorManager.format(message, source, line, column, token); return new ParserException(errorType, formatted, source, line, column, token); }
private RuntimeNode referenceError(final Expression lhs, final Expression rhs, final boolean earlyError) { if (earlyError) { throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); } final ArrayList<Expression> args = new ArrayList<>(); args.add(lhs); if (rhs == null) { args.add(LiteralNode.newInstance(lhs.getToken(), lhs.getFinish())); } else { args.add(rhs); } args.add(LiteralNode.newInstance(lhs.getToken(), lhs.getFinish(), lhs.toString())); return new RuntimeNode(lhs.getToken(), lhs.getFinish(), RuntimeNode.Request.REFERENCE_ERROR, args); }
private void throwParserException(final String message, final Node origin) { if (origin == null) { throw new ParserException(message); } final Source source = compiler.getSource(); final long token = origin.getToken(); final int line = source.getLine(origin.getStart()); final int column = source.getColumn(origin.getStart()); final String formatted = ErrorManager.format(message, source, line, column, token); throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token); }
ParserException error(final String message, final int start, final int length) throws ParserException { final long token = Token.toDesc(STRING, start, length); final int pos = Token.descPosition(token); final Source src = Source.sourceFor("<json>", source); final int lineNum = src.getLine(pos); final int columnNum = src.getColumn(pos); final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token); return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token); }
private RuntimeNode referenceError(final Expression lhs, final Expression rhs, final boolean earlyError) { if (env._parse_only || earlyError) { throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); } final ArrayList<Expression> args = new ArrayList<>(); args.add(lhs); if (rhs == null) { args.add(LiteralNode.newInstance(lhs.getToken(), lhs.getFinish())); } else { args.add(rhs); } args.add(LiteralNode.newInstance(lhs.getToken(), lhs.getFinish(), lhs.toString())); return new RuntimeNode(lhs.getToken(), lhs.getFinish(), RuntimeNode.Request.REFERENCE_ERROR, args); }
/** * Report an error. * * @param errorType The error type * @param message Error message. * @param errorToken Offending token. * @return ParserException upon failure. Caller should throw and not ignore */ protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) { final int position = Token.descPosition(errorToken); final int lineNum = source.getLine(position); final int columnNum = source.getColumn(position); final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken); return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken); }
/** * Generate a runtime exception * * @param message error message * @param type token type * @param start start position of lexed error * @param length length of lexed error * @throws ParserException unconditionally */ protected void error(final String message, final TokenType type, final int start, final int length) throws ParserException { final long token = Token.toDesc(type, start, length); final int pos = Token.descPosition(token); final int lineNum = source.getLine(pos); final int columnNum = source.getColumn(pos); final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token); throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token); }