Trait antlr_rust::error_strategy::ErrorStrategy [−][src]
pub trait ErrorStrategy<'a, T: Parser<'a>>: Tid<'a> {
fn reset(&mut self, recognizer: &mut T);
fn recover_inline(
&mut self,
recognizer: &mut T
) -> Result<<T::TF as TokenFactory<'a>>::Tok, ANTLRError>;
fn recover(
&mut self,
recognizer: &mut T,
e: &ANTLRError
) -> Result<(), ANTLRError>;
fn sync(&mut self, recognizer: &mut T) -> Result<(), ANTLRError>;
fn in_error_recovery_mode(&mut self, recognizer: &mut T) -> bool;
fn report_error(&mut self, recognizer: &mut T, e: &ANTLRError);
fn report_match(&mut self, recognizer: &mut T);
}
Expand description
The interface for defining strategies to deal with syntax errors encountered during a parse by ANTLR-generated parsers. We distinguish between three different kinds of errors:
- The parser could not figure out which path to take in the ATN (none of the available alternatives could possibly match)
- The current input does not match what we were looking for
- A predicate evaluated to false
Implementations of this interface should report syntax errors by calling Parser::notifyErrorListeners
Required methods
Reset the error handler state for the specified recognizer
.
fn recover_inline(
&mut self,
recognizer: &mut T
) -> Result<<T::TF as TokenFactory<'a>>::Tok, ANTLRError>
fn recover_inline(
&mut self,
recognizer: &mut T
) -> Result<<T::TF as TokenFactory<'a>>::Tok, ANTLRError>
This method is called when an unexpected symbol is encountered during an
inline match operation, such as Parser::match
. If the error
strategy successfully recovers from the match failure, this method
returns the Token
instance which should be treated as the
successful result of the match.
This method handles the consumption of any tokens - the caller should
not call Parser::consume
after a successful recovery.
Note that the calling code will not report an error if this method
returns successfully. The error strategy implementation is responsible
for calling Parser::notifyErrorListeners
as appropriate.
Returns ANTLRError
if can’t recover from unexpected input symbol
fn recover(
&mut self,
recognizer: &mut T,
e: &ANTLRError
) -> Result<(), ANTLRError>
fn recover(
&mut self,
recognizer: &mut T,
e: &ANTLRError
) -> Result<(), ANTLRError>
This method is called to recover from error e
. This method is
called after ErrorStrategy::reportError
by the default error handler
generated for a rule method.
This method provides the error handler with an opportunity to handle syntactic or semantic errors in the input stream before they result in a error.
The generated code currently contains calls to ErrorStrategy::sync
after
entering the decision state of a closure block ({@code (…)*} or
{@code (…)+}).
fn in_error_recovery_mode(&mut self, recognizer: &mut T) -> bool
fn in_error_recovery_mode(&mut self, recognizer: &mut T) -> bool
Tests whether or not {@code recognizer} is in the process of recovering
from an error. In error recovery mode, Parser::consume
will create
ErrorNode
leaf instead of TerminalNode
one
fn report_error(&mut self, recognizer: &mut T, e: &ANTLRError)
fn report_error(&mut self, recognizer: &mut T, e: &ANTLRError)
Report any kind of ANTLRError
. This method is called by
the default exception handler generated for a rule method.
fn report_match(&mut self, recognizer: &mut T)
fn report_match(&mut self, recognizer: &mut T)
This method is called when the parser successfully matches an input symbol.