protected Token recoverFromMismatchedToken ( TokenStream input , int ttype , String text , int [ ] follow ) throws RecognitionException { RecognitionException e = null ; // if next token is what we are looking for then "delete" this token if ( mismatchIsUnwantedToken ( input , ttype , text ) ) { e = new UnwantedTokenException ( ttype , input ) ; input . consume ( ) ; // simply delete extra token reportError ( e ) ; // report after consuming so AW sees the token in the exception // we want to return the token we're actually matching Token matchedSymbol = input . LT ( 1 ) ; input . consume ( ) ; // move past ttype token as if all were ok return matchedSymbol ; } // can't recover with single token deletion, try insertion if ( mismatchIsMissingToken ( input , follow ) ) { e = new MissingTokenException ( ttype , input , null ) ; reportError ( e ) ; // report after inserting so AW sees the token in the exception return null ; } // even that didn't work; must throw the exception if ( text != null ) { e = new DroolsMismatchedTokenException ( ttype , text , input ) ; } else { e = new MismatchedTokenException ( ttype , input ) ; } throw e ; }
Attempt to recover from a single missing or extra token .