Struct BailErrorStrategy

Source
pub struct BailErrorStrategy<'input, Ctx: ParserNodeType<'input>>(/* private fields */);
Expand description

This implementation of ANTLRErrorStrategy responds to syntax errors by immediately canceling the parse operation with a ParseCancellationException. The implementation ensures that the ParserRuleContext.exception field is set for all parse tree nodes that were not completed prior to encountering the error.

This error strategy is useful in the following scenarios.

  • Two-stage parsing: This error strategy allows the first stage of two-stage parsing to immediately terminate if an error is encountered, and immediately fall back to the second stage. In addition to avoiding wasted work by attempting to recover from errors here, the empty implementation of sync improves the performance of the first stage.
  • Silent validation: When syntax errors are not being reported or logged, and the parse result is simply ignored if errors occur, the BailErrorStrategy avoids wasting work on recovering from errors when the result will be ignored either way.

§Usage

use antlr_rust::error_strategy::BailErrorStrategy;
myparser.err_handler = BailErrorStrategy::new();

*/

Implementations§

Source§

impl<'input, Ctx: ParserNodeType<'input>> BailErrorStrategy<'input, Ctx>

Source

pub fn new() -> Self

Creates new instance of BailErrorStrategy

Trait Implementations§

Source§

impl<'input, Ctx: Debug + ParserNodeType<'input>> Debug for BailErrorStrategy<'input, Ctx>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'input, Ctx: Default + ParserNodeType<'input>> Default for BailErrorStrategy<'input, Ctx>

Source§

fn default() -> BailErrorStrategy<'input, Ctx>

Returns the “default value” for a type. Read more
Source§

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

Source§

fn reset(&mut self, recognizer: &mut T)

Reset the error handler state for the specified recognizer.
Source§

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. Read more
Source§

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.
Source§

fn sync(&mut self, _recognizer: &mut T) -> Result<(), ANTLRError>

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. Read more
Source§

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
Source§

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.
Source§

fn report_match(&mut self, _recognizer: &mut T)

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

impl<'i, Ctx> TidAble<'i> for BailErrorStrategy<'i, Ctx>
where Ctx: ParserNodeType<'i> + TidAble<'i>,

Auto Trait Implementations§

§

impl<'input, Ctx> Freeze for BailErrorStrategy<'input, Ctx>

§

impl<'input, Ctx> RefUnwindSafe for BailErrorStrategy<'input, Ctx>
where <Ctx as ParserNodeType<'input>>::Type: RefUnwindSafe,

§

impl<'input, Ctx> !Send for BailErrorStrategy<'input, Ctx>

§

impl<'input, Ctx> !Sync for BailErrorStrategy<'input, Ctx>

§

impl<'input, Ctx> Unpin for BailErrorStrategy<'input, Ctx>

§

impl<'input, Ctx> UnwindSafe for BailErrorStrategy<'input, Ctx>
where <Ctx as ParserNodeType<'input>>::Type: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyExt for T
where T: Any + ?Sized,

Source§

fn downcast_ref<T>(this: &Self) -> Option<&T>
where T: Any,

Attempts to downcast this to T behind reference
Source§

fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>
where T: Any,

Attempts to downcast this to T behind mutable reference
Source§

fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Any,

Attempts to downcast this to T behind Rc pointer
Source§

fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Any,

Attempts to downcast this to T behind Arc pointer
Source§

fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Any,

Attempts to downcast this to T behind Box pointer
Source§

fn downcast_move<T>(this: Self) -> Option<T>
where T: Any, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

Source§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

Source§

fn coerce_box_to(self: Box<X>) -> Box<T>

Source§

fn coerce_ref_to(&self) -> &T

Source§

fn coerce_mut_to(&mut self) -> &mut T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T> Tid<'a> for T
where T: TidAble<'a> + ?Sized,

Source§

fn self_id(&self) -> TypeId

Returns type id of the type of self Read more
Source§

fn id() -> TypeId

Returns type id of this type
Source§

impl<'a, X> TidExt<'a> for X
where X: Tid<'a> + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: Tid<'a>,

Returns true if type behind self is equal to the type of T.
Source§

fn downcast_ref<'b, T>(&'b self) -> Option<&'b T>
where T: Tid<'a>,

Attempts to downcast self to T behind reference
Source§

fn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>
where T: Tid<'a>,

Attempts to downcast self to T behind mutable reference
Source§

fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Tid<'a>,

Attempts to downcast self to T behind Rc pointer
Source§

fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Tid<'a>,

Attempts to downcast self to T behind Arc pointer
Source§

fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Tid<'a>,

Attempts to downcast self to T behind Box pointer
Source§

fn downcast_move<T>(self) -> Option<T>
where T: Tid<'a>, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.