question: protected boolean error_recovery ( boolean debug ) throws java . lang . Exception { if ( debug ) debug_message ( "# Attempting error recovery" ) ; if ( ! find_recovery_config ( debug ) ) { if ( debug ) debug_message ( "# Error recovery fails" ) ; return false ; } read_lookahead ( ) ; for ( ; ; ) { if ( debug ) debug_message ( "# Trying to parse ahead" ) ; if ( try_parse_ahead ( debug ) ) { break ; } if ( lookahead [ 0 ] . sym == EOF_sym ( ) ) { if ( debug ) debug_message ( "# Error recovery fails at EOF" ) ; return false ; } if ( debug ) debug_message ( "# Consuming Symbol #" + lookahead [ 0 ] . sym ) ; restart_lookahead ( ) ; } if ( debug ) debug_message ( "# Parse-ahead ok, going back to normal parse" ) ; parse_lookahead ( debug ) ; return true ; }
target:  Attempt to recover from a syntax error.  This returns false if recovery  fails, true if it succeeds.  Recovery happens in 4 steps.  First we pop the parse stack down to a point at which we have a shift out of the top-most state on the error Symbol.  This represents the initial error recovery configuration.  If no such configuration is found, then we fail.  Next a small number of "lookahead" or "parse ahead" Symbols are read into a buffer.  The size of this buffer is  determined by error_sync_size() and determines how many Symbols beyond the error must be matched to consider the recovery a success.  Next,  we begin to discard Symbols in attempt to get past the point of error to a point where we can continue parsing.  After each Symbol, we attempt  to "parse ahead" though the buffered lookahead Symbols.  The "parse ahead" process simulates that actual parse, but does not modify the real  parser's configuration, nor execute any actions. If we can  parse all  the stored Symbols without error, then the recovery is considered a  success.  Once a successful recovery point is determined, we do an actual parse over the stored input -- modifying the real parse  configuration and executing all actions.  Finally, we return the the  normal parser to continue with the overall parse.