private void unQuoteToken(Token token) { if (token instanceof CommonToken) { CommonToken commonToken = (CommonToken) token; commonToken.setStartIndex(commonToken.getStartIndex() + 1); commonToken.setStopIndex(commonToken.getStopIndex() - 1); } }
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { int start = recognizer.getInputStream().index(); int stop = start; if (offendingSymbol != null) { CommonToken token = (CommonToken) offendingSymbol; start = token.getStartIndex(); stop = token.getStopIndex(); } InputStreamPosition pos; try { pos = (this.source == null) ? null : new InputStreamPosition(line, charPositionInLine, start, stop, this.source.getCanonicalPath()); } catch (IOException exc) { pos = null; // TODO } if (recognizer instanceof Lexer) { // lexer error handleLexerError(recognizer, offendingSymbol, pos, msg, e); } else { handleParserError(recognizer, offendingSymbol, pos, msg, e); } }
if(((CommonToken)token).getStartIndex() < 0) token = nextToken();
if(((CommonToken)token).getStartIndex() < 0) token = nextToken();
/*************** Implements {@link ANTLRErrorListener} *******************/ @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { int start = recognizer.getInputStream().index(); int stop = start; if (offendingSymbol != null) { CommonToken token = (CommonToken) offendingSymbol; start = token.getStartIndex(); stop = token.getStopIndex(); } SourceInfoObject pos = new SourceInfoObject(this.sourceInfo.getSource(), line, charPositionInLine, this.sourceInfo.getStartIndex() + start + 1, this.sourceInfo.getStartIndex() + stop + 1); if (recognizer instanceof Lexer) { handleLexerError(recognizer, offendingSymbol, pos, msg, e); } else { handleParserError(recognizer, offendingSymbol, pos, msg, e); } }