@Override public Token nextToken() { while (true) { this.state.token = null; this.state.channel = Token.DEFAULT_CHANNEL; this.state.tokenStartCharIndex = input.index(); this.state.tokenStartCharPositionInLine = input.getCharPositionInLine(); this.state.tokenStartLine = input.getLine(); this.state.text = null; if (input.LA(1) == CharStream.EOF) { return Token.EOF_TOKEN; } try { mTokens(); if (this.state.token == null) { emit(); } else if (this.state.token == Token.SKIP_TOKEN) { continue; } return this.state.token; } catch (RecognitionException re) { reportError(re); if (re instanceof NoViableAltException || re instanceof FailedPredicateException) { recover(re); } // create token that holds mismatched char Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL, this.state.tokenStartCharIndex, getCharIndex() - 1); t.setLine(this.state.tokenStartLine); t.setCharPositionInLine(this.state.tokenStartCharPositionInLine); tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames())); emit(t); return this.state.token; } } }
@Override public void recover(IntStream stream, RecognitionException ex) { if (recoveryListener != null) recoveryListener.beginErrorRecovery(); removeUnexpectedElements(); if (ex instanceof FailedPredicateException && ex.token.getType() == Token.EOF) { failedPredicateAtEOF = true; } super.recover(stream, ex); if (recoveryListener != null) recoveryListener.endErrorRecovery(); }
/** * Simplify error message text for end users. * @param e exception that occurred * @param msg as formatted by ANTLR * @return a more readable error message */ public static String makeUserMsg(final RecognitionException e, final String msg) { if (e instanceof NoViableAltException) { return msg.replace("no viable alternative at", "unrecognized"); } else if (e instanceof UnwantedTokenException) { return msg.replace("extraneous input", "unexpected token"); } else if (e instanceof MismatchedTokenException) { if (msg.contains("mismatched input '<EOF>'")) { return msg.replace("mismatched input '<EOF>' expecting", "reached end of file looking for"); } else { return msg.replace("mismatched input", "unexpected token"); } } else if (e instanceof EarlyExitException) { return msg.replace("required (...)+ loop did not match anything", "required tokens not found"); } else if (e instanceof FailedPredicateException) { if (msg.contains("picture_string failed predicate: {Unbalanced parentheses}")) { return "Unbalanced parentheses in picture string"; } if (msg.contains("PICTURE_PART failed predicate: {Contains invalid picture symbols}")) { return "Picture string contains invalid symbols"; } if (msg.contains("PICTURE_PART failed predicate: {Syntax error in last picture clause}")) { return "Syntax error in last picture clause"; } if (msg.contains("DATA_NAME failed predicate: {Syntax error in last clause}")) { return "Syntax error in last COBOL clause"; } } return msg; }
public final void streetAddressStart() throws RecognitionException { try { // /Users/jeffrey/Documents/workspace/matchmaker/src/ca/sqlpower/matchmaker/address/parse/Address.g:187:2: ({...}? streetAddress ) // /Users/jeffrey/Documents/workspace/matchmaker/src/ca/sqlpower/matchmaker/address/parse/Address.g:187:4: {...}? streetAddress { if ( !((setStartsUrbanNotRural(true))) ) { throw new FailedPredicateException(input, "streetAddressStart", "setStartsUrbanNotRural(true)"); } pushFollow(FOLLOW_streetAddress_in_streetAddressStart132); streetAddress(); state._fsp--; address.setType(PostalCode.RecordType.STREET); if (address.isUrbanBeforeRural() != null) { address.setType(PostalCode.RecordType.STREET_AND_ROUTE); } } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; }
public final void ruralRouteAddress() throws RecognitionException { try { // /Users/jeffrey/Documents/workspace/matchmaker/src/ca/sqlpower/matchmaker/address/parse/Address.g:308:2: ({...}? ruralRoute ) // /Users/jeffrey/Documents/workspace/matchmaker/src/ca/sqlpower/matchmaker/address/parse/Address.g:308:4: {...}? ruralRoute { if ( !((setStartsUrbanNotRural(false))) ) { throw new FailedPredicateException(input, "ruralRouteAddress", "setStartsUrbanNotRural(false)"); } pushFollow(FOLLOW_ruralRoute_in_ruralRouteAddress474); ruralRoute(); state._fsp--; address.setType(PostalCode.RecordType.ROUTE); if (address.isUrbanBeforeRural() != null) { address.setType(PostalCode.RecordType.STREET_AND_ROUTE); } } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; }
protected UnorderedGroupErrorContext(FailedPredicateException exception) { super(exception); }
@Override public FailedPredicateException getRecognitionException() { return (FailedPredicateException) super.getRecognitionException(); }
protected IParserErrorContext createErrorContext(RecognitionException e) { if (e instanceof FailedPredicateException) return new UnorderedGroupErrorContext((FailedPredicateException) e); return new ParserErrorContext(e); }
/** * Returns the failed predicate exception caused by a specific unordered group. * @return the failed predicate exception caused by a specific unordered group. Never <code>null</code>. */ @Override FailedPredicateException getRecognitionException();