Refine search
String getMessage() { return br.getErrorHeader(re) + " " + br.getErrorMessage(re, tokenNames); }
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) { if ( follow==null ) { // we have no information about the follow; we can only consume // a single token and hope for the best return false; } // compute what can follow this grammar element reference if ( follow.member(Token.EOR_TOKEN_TYPE) ) { BitSet viableTokensFollowingThisRule = computeContextSensitiveRuleFOLLOW(); follow = follow.or(viableTokensFollowingThisRule); if ( state._fsp>=0 ) { // remove EOR if we're not the start symbol follow.remove(Token.EOR_TOKEN_TYPE); } } // if current token is consistent with what could come after set // then we know we're missing a token; error recovery is free to // "insert" the missing token //System.out.println("viable tokens="+follow.toString(getTokenNames())); //System.out.println("LT(1)="+((TokenStream)input).LT(1)); // BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR // in follow set to indicate that the fall of the start symbol is // in the set (EOF can follow). if ( follow.member(input.LA(1)) || follow.member(Token.EOR_TOKEN_TYPE) ) { //System.out.println("LT(1)=="+((TokenStream)input).LT(1)+" is consistent with what follows; inserting..."); return true; } return false; }
/** Recover from an error found on the input stream. This is * for NoViableAlt and mismatched symbol exceptions. If you enable * single token insertion and deletion, this will usually not * handle mismatched symbol exceptions but there could be a mismatched * token that the match() routine could not recover from. */ public void recover(IntStream input, RecognitionException re) { if ( state.lastErrorIndex==input.index() ) { // uh oh, another error at same token index; must be a case // where LT(1) is in the recovery token set so nothing is // consumed; consume a single token so at least to prevent // an infinite loop; this is a failsafe. input.consume(); } state.lastErrorIndex = input.index(); BitSet followSet = computeErrorRecoverySet(); beginResync(); consumeUntil(input, followSet); endResync(); }
if ( mismatchIsUnwantedToken(input, ttype) ) { e = new UnwantedTokenException(ttype, input); beginResync(); input.consume(); // simply delete extra token endResync(); reportError(e); // report after consuming so AW sees the token in the exception Object matchedSymbol = getCurrentInputSymbol(input); input.consume(); // move past ttype token as if all were ok return matchedSymbol; if ( mismatchIsMissingToken(input, follow) ) { Object inserted = getMissingSymbol(input, e, ttype, follow); e = new MissingTokenException(ttype, input, inserted); reportError(e); // report after inserting so AW sees the token in the exception return inserted;
public void displayRecognitionError(String[] tokenNames, RecognitionException e) { String hdr = getErrorHeader(e); String msg = getErrorMessage(e, tokenNames); emitErrorMessage(hdr+" "+msg); }
/** * Create a {@code CSSParserProblem} from ANTLR's * {@link BaseRecognizer#displayRecognitionError}. * * @param baseRecognizer Lexer, parser or tree walker. * @param tokenNames token names * @param e exception * @return {@code CSSParserProblem} */ public static CSSParserProblem create(BaseRecognizer baseRecognizer, String[] tokenNames, RecognitionException e) { final String messageHeader = baseRecognizer.getErrorHeader(e); final String messageBody = baseRecognizer.getErrorMessage(e, tokenNames); final String reason = String.format("%s %s", messageHeader, messageBody); final ISourceLocation location = new SourceLocation( e.input.getSourceName(), UNKNOWN, UNKNOWN, // TODO Need start and end info from CSS e.line, e.charPositionInLine); return new CSSParserProblem(location, reason, baseRecognizer.getClass()); } }
/** Tree parsers parse nodes they usually have a token object as * payload. Set the exception token and do the default behavior. */ public String getErrorMessage(RecognitionException e, String[] tokenNames) { if ( this instanceof TreeParser ) { TreeAdaptor adaptor = ((TreeNodeStream)e.input).getTreeAdaptor(); e.token = adaptor.getToken(e.node); if ( e.token==null ) { // could be an UP/DOWN node e.token = new CommonToken(adaptor.getType(e.node), adaptor.getText(e.node)); } } return super.getErrorMessage(e, tokenNames); }
private static String getErrorMessage(BaseRecognizer recognizer, RecognitionException e) { String[] tokenNames = recognizer.getTokenNames(); String hdr = "Line " + e.line + ":" + e.charPositionInLine; String msg = recognizer.getErrorMessage(e, tokenNames); return hdr + " " + msg; }
/** Report a recognition problem. * * This method sets errorRecovery to indicate the parser is recovering * not parsing. Once in recovery mode, no errors are generated. * To get out of recovery mode, the parser must successfully match * a token (after a resync). So it will go: * * 1. error occurs * 2. enter recovery mode, report error * 3. consume until token found in resynch set * 4. try to resume parsing * 5. next match() will reset errorRecovery mode * * If you override, make sure to update syntaxErrors if you care about that. */ public void reportError(RecognitionException e) { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. if ( state.errorRecovery ) { //System.err.print("[SPURIOUS] "); return; } state.syntaxErrors++; // don't count spurious state.errorRecovery = true; displayRecognitionError(this.getTokenNames(), e); }
protected BitSet computeErrorRecoverySet() { return combineFollows(false); }
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) { if ( follow==null ) { // we have no information about the follow; we can only consume // a single token and hope for the best return false; } // compute what can follow this grammar element reference if ( follow.member(Token.EOR_TOKEN_TYPE) ) { BitSet viableTokensFollowingThisRule = computeContextSensitiveRuleFOLLOW(); follow = follow.or(viableTokensFollowingThisRule); if ( state._fsp>=0 ) { // remove EOR if we're not the start symbol follow.remove(Token.EOR_TOKEN_TYPE); } } // if current token is consistent with what could come after set // then we know we're missing a token; error recovery is free to // "insert" the missing token //System.out.println("viable tokens="+follow.toString(getTokenNames())); //System.out.println("LT(1)="+((TokenStream)input).LT(1)); // BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR // in follow set to indicate that the fall of the start symbol is // in the set (EOF can follow). if ( follow.member(input.LA(1)) || follow.member(Token.EOR_TOKEN_TYPE) ) { //System.out.println("LT(1)=="+((TokenStream)input).LT(1)+" is consistent with what follows; inserting..."); return true; } return false; }
/** Recover from an error found on the input stream. This is * for NoViableAlt and mismatched symbol exceptions. If you enable * single token insertion and deletion, this will usually not * handle mismatched symbol exceptions but there could be a mismatched * token that the match() routine could not recover from. */ public void recover(IntStream input, RecognitionException re) { if ( state.lastErrorIndex==input.index() ) { // uh oh, another error at same token index; must be a case // where LT(1) is in the recovery token set so nothing is // consumed; consume a single token so at least to prevent // an infinite loop; this is a failsafe. input.consume(); } state.lastErrorIndex = input.index(); BitSet followSet = computeErrorRecoverySet(); beginResync(); consumeUntil(input, followSet); endResync(); }
if ( mismatchIsUnwantedToken(input, ttype) ) { e = new UnwantedTokenException(ttype, input); beginResync(); input.consume(); // simply delete extra token endResync(); reportError(e); // report after consuming so AW sees the token in the exception Object matchedSymbol = getCurrentInputSymbol(input); input.consume(); // move past ttype token as if all were ok return matchedSymbol; if ( mismatchIsMissingToken(input, follow) ) { Object inserted = getMissingSymbol(input, e, ttype, follow); e = new MissingTokenException(ttype, input, inserted); reportError(e); // report after inserting so AW sees the token in the exception return inserted;
public void displayRecognitionError(String[] tokenNames, RecognitionException e) { String hdr = getErrorHeader(e); String msg = getErrorMessage(e, tokenNames); emitErrorMessage(hdr+" "+msg); }
/** * Create a {@code CSSParserProblem} from ANTLR's * {@link BaseRecognizer#displayRecognitionError}. * * @param baseRecognizer Lexer, parser or tree walker. * @param tokenNames token names * @param e exception * @return {@code CSSParserProblem} */ public static CSSParserProblem create(BaseRecognizer baseRecognizer, String[] tokenNames, RecognitionException e) { final String messageHeader = baseRecognizer.getErrorHeader(e); final String messageBody = baseRecognizer.getErrorMessage(e, tokenNames); final String reason = String.format("%s %s", messageHeader, makeNice(messageBody)); final ISourceLocation location = new SourceLocation( e.input.getSourceName(), UNKNOWN, UNKNOWN, // TODO Need start and end info from CSS e.line, e.charPositionInLine); return new CSSParserProblem(location, reason, baseRecognizer.getClass()); }
/** Tree parsers parse nodes they usually have a token object as * payload. Set the exception token and do the default behavior. */ @Override public String getErrorMessage(RecognitionException e, String[] tokenNames) { if ( this instanceof TreeParser ) { TreeAdaptor adaptor = ((TreeNodeStream)e.input).getTreeAdaptor(); e.token = adaptor.getToken(e.node); if ( e.token==null ) { // could be an UP/DOWN node e.token = new CommonToken(adaptor.getType(e.node), adaptor.getText(e.node)); } } return super.getErrorMessage(e, tokenNames); }
/** Report a recognition problem. * * This method sets errorRecovery to indicate the parser is recovering * not parsing. Once in recovery mode, no errors are generated. * To get out of recovery mode, the parser must successfully match * a token (after a resync). So it will go: * * 1. error occurs * 2. enter recovery mode, report error * 3. consume until token found in resynch set * 4. try to resume parsing * 5. next match() will reset errorRecovery mode * * If you override, make sure to update syntaxErrors if you care about that. */ public void reportError(RecognitionException e) { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. if ( state.errorRecovery ) { //System.err.print("[SPURIOUS] "); return; } state.syntaxErrors++; // don't count spurious state.errorRecovery = true; displayRecognitionError(this.getTokenNames(), e); }
protected BitSet computeErrorRecoverySet() { return combineFollows(false); }
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) { if ( follow==null ) { // we have no information about the follow; we can only consume // a single token and hope for the best return false; } // compute what can follow this grammar element reference if ( follow.member(Token.EOR_TOKEN_TYPE) ) { BitSet viableTokensFollowingThisRule = computeContextSensitiveRuleFOLLOW(); follow = follow.or(viableTokensFollowingThisRule); if ( state._fsp>=0 ) { // remove EOR if we're not the start symbol follow.remove(Token.EOR_TOKEN_TYPE); } } // if current token is consistent with what could come after set // then we know we're missing a token; error recovery is free to // "insert" the missing token //System.out.println("viable tokens="+follow.toString(getTokenNames())); //System.out.println("LT(1)="+((TokenStream)input).LT(1)); // BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR // in follow set to indicate that the fall of the start symbol is // in the set (EOF can follow). if ( follow.member(input.LA(1)) || follow.member(Token.EOR_TOKEN_TYPE) ) { //System.out.println("LT(1)=="+((TokenStream)input).LT(1)+" is consistent with what follows; inserting..."); return true; } return false; }
/** Recover from an error found on the input stream. This is * for NoViableAlt and mismatched symbol exceptions. If you enable * single token insertion and deletion, this will usually not * handle mismatched symbol exceptions but there could be a mismatched * token that the match() routine could not recover from. */ public void recover(IntStream input, RecognitionException re) { if ( state.lastErrorIndex==input.index() ) { // uh oh, another error at same token index; must be a case // where LT(1) is in the recovery token set so nothing is // consumed; consume a single token so at least to prevent // an infinite loop; this is a failsafe. input.consume(); } state.lastErrorIndex = input.index(); BitSet followSet = computeErrorRecoverySet(); beginResync(); consumeUntil(input, followSet); endResync(); }