[][src]Trait antlr_rust::error_strategy::ErrorStrategy

pub trait ErrorStrategy<'a, T: Parser<'a>>: Tid<'a> {
    pub fn reset(&mut self, recognizer: &mut T);
pub fn recover_inline(
        &mut self,
        recognizer: &mut T
    ) -> Result<<T::TF as TokenFactory<'a>>::Tok, ANTLRError>;
pub fn recover(
        &mut self,
        recognizer: &mut T,
        e: &ANTLRError
    ) -> Result<(), ANTLRError>;
pub fn sync(&mut self, recognizer: &mut T) -> Result<(), ANTLRError>;
pub fn in_error_recovery_mode(&mut self, recognizer: &mut T) -> bool;
pub fn report_error(&mut self, recognizer: &mut T, e: &ANTLRError);
pub fn report_match(&mut self, recognizer: &mut T); }

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

pub fn reset(&mut self, recognizer: &mut T)[src]

Reset the error handler state for the specified recognizer.

pub fn recover_inline(
    &mut self,
    recognizer: &mut T
) -> Result<<T::TF as TokenFactory<'a>>::Tok, ANTLRError>
[src]

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

pub fn recover(
    &mut self,
    recognizer: &mut T,
    e: &ANTLRError
) -> Result<(), ANTLRError>
[src]

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.

pub fn sync(&mut self, recognizer: &mut T) -> Result<(), ANTLRError>[src]

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 (...)+}).

pub fn in_error_recovery_mode(&mut self, recognizer: &mut T) -> bool[src]

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

pub fn report_error(&mut self, recognizer: &mut T, e: &ANTLRError)[src]

Report any kind of ANTLRError. This method is called by the default exception handler generated for a rule method.

pub fn report_match(&mut self, recognizer: &mut T)[src]

This method is called when the parser successfully matches an input symbol.

Loading content...

Implementations on Foreign Types

impl<'a, T: Parser<'a> + TidAble<'a>> ErrorStrategy<'a, T> for Box<dyn ErrorStrategy<'a, T> + 'a>[src]

Loading content...

Implementors

impl<'a, T: Parser<'a>> ErrorStrategy<'a, T> for BailErrorStrategy<'a, T::Node>[src]

impl<'a, T: Parser<'a>> ErrorStrategy<'a, T> for DefaultErrorStrategy<'a, T::Node>[src]

Loading content...