BaseParser

Struct BaseParser 

Source
pub struct BaseParser<'input, Ext: 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized = dyn ParseTreeListener<'input, Ctx>> {
    pub ctx: Option<Rc<Ctx::Type>>,
    pub build_parse_trees: bool,
    pub matched_eof: bool,
    pub input: I,
    /* private fields */
}
Expand description

§Main underlying Parser struct

It is a member of generated parser struct, so almost always you don’t need to create it yourself. Generated parser hides complexity of this struct and expose required flexibility via generic parameters

Fields§

§ctx: Option<Rc<Ctx::Type>>

Rule context parser is currently processing

§build_parse_trees: bool

Track the {@link ParserRuleContext} objects during the parse and hook them up using the {@link ParserRuleContext#children} list so that it forms a parse tree. The {@link ParserRuleContext} returned from the start rule represents the root of the parse tree.

Note that if we are not building parse trees, rule contexts only point upwards. When a rule exits, it returns the context bute that gets garbage collected if nobody holds a reference. It points upwards but nobody points at it.

When we build parse trees, we are adding all of these contexts to {@link ParserRuleContext#children} list. Contexts are then not candidates for garbage collection.

Returns {@code true} if a complete parse tree will be constructed while parsing, otherwise {@code false}

§matched_eof: bool

true if parser reached EOF

§input: I

Token stream that is currently used by this parser

Implementations§

Source§

impl<'input, Ext, I, Ctx, T> BaseParser<'input, Ext, I, Ctx, T>
where Ext: ParserRecog<'input, Self> + 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized, Ctx::Type: Listenable<T> + CoerceFrom<TerminalNode<'input, Ctx>> + CoerceFrom<ErrorNode<'input, Ctx>>,

Source

pub fn new_base_parser( input: I, interpreter: Arc<ParserATNSimulator>, ext: Ext, ) -> Self

Source

pub fn match_token( &mut self, ttype: isize, err_handler: &mut impl ErrorStrategy<'input, Self>, ) -> Result<<I::TF as TokenFactory<'input>>::Tok, ANTLRError>

Source

pub fn match_wildcard( &mut self, err_handler: &mut impl ErrorStrategy<'input, Self>, ) -> Result<<I::TF as TokenFactory<'input>>::Tok, ANTLRError>

Source

pub fn add_parse_listener<L>(&mut self, listener: Box<L>) -> ListenerId<L>
where L: CoerceTo<T>,

Adds parse listener for this parser returns listener_id that can be used later to get listener back

Embedded listener currently must outlive 'input. If you need to have arbitrary listener use ParseTreeWalker.

§Example for listener usage:

todo

Source

pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>
where L: CoerceTo<T>,

Removes parse listener with corresponding listener_id, casts it back to user type and returns it to the caller. listener_id is returned when listener is added via add_parse_listener

Source

pub fn remove_parse_listeners(&mut self)

Removes all added parse listeners without returning them

Source

pub fn trigger_enter_rule_event(&mut self)

Source

pub fn trigger_exit_rule_event(&mut self)

Source

pub fn enter_rule( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, )

Source

pub fn exit_rule(&mut self)

Source

pub fn enter_outer_alt( &mut self, new_ctx: Option<Rc<Ctx::Type>>, alt_num: isize, )

Source

pub fn enter_recursion_rule( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, precedence: isize, )

Source

pub fn push_new_recursion_context( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, )

Source

pub fn unroll_recursion_context(&mut self, parent_ctx: Option<Rc<Ctx::Type>>)

Source

pub fn dump_dfa(&self)

Text representation of generated DFA for debugging purposes

Trait Implementations§

Source§

impl<'input, Ext, I, Ctx, T> DerefMut for BaseParser<'input, Ext, I, Ctx, T>
where Ext: ParserRecog<'input, Self> + 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'input, Ext, I, Ctx, T> Parser<'input> for BaseParser<'input, Ext, I, Ctx, T>
where Ext: ParserRecog<'input, Self> + 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized, Ctx::Type: Listenable<T> + CoerceFrom<TerminalNode<'input, Ctx>> + CoerceFrom<ErrorNode<'input, Ctx>>,

Source§

fn get_interpreter(&self) -> &ParserATNSimulator

Source§

fn get_token_factory(&self) -> &'input Self::TF

Source§

fn get_parser_rule_context(&self) -> &Rc<Ctx::Type>

Source§

fn consume(&mut self, err_handler: &mut impl ErrorStrategy<'input, Self>)

Source§

fn precpred(&self, _localctx: Option<&Ctx::Type>, precedence: isize) -> bool

Source§

fn get_input_stream_mut( &mut self, ) -> &mut dyn TokenStream<'input, TF = Self::TF>

Source§

fn get_input_stream(&self) -> &dyn TokenStream<'input, TF = Self::TF>

Source§

fn get_current_token(&self) -> &<Self::TF as TokenFactory<'input>>::Tok

Source§

fn get_expected_tokens(&self) -> IntervalSet

Source§

fn add_error_listener(&mut self, listener: Box<dyn ErrorListener<'input, Self>>)

Source§

fn notify_error_listeners( &self, msg: String, offending_token: Option<isize>, err: Option<&ANTLRError>, )

Source§

fn get_error_lister_dispatch<'a>( &'a self, ) -> Box<dyn ErrorListener<'input, Self> + 'a>

Source§

fn is_expected_token(&self, _symbol: isize) -> bool

Source§

fn get_precedence(&self) -> isize

Source§

fn get_state(&self) -> isize

Source§

fn set_state(&mut self, v: isize)

Source§

fn get_rule_invocation_stack(&self) -> Vec<String>

Source§

impl<'input, Ext, I, Ctx, T> Deref for BaseParser<'input, Ext, I, Ctx, T>
where Ext: ParserRecog<'input, Self> + 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized,

Source§

type Target = Ext

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'input, I, Ctx, T, Ext: 'static> TidAble<'input> for BaseParser<'input, Ext, I, Ctx, T>
where I: TokenStream<'input> + TidAble<'input>, Ctx: ParserNodeType<'input, TF = I::TF> + TidAble<'input>, T: ParseTreeListener<'input, Ctx> + ?Sized + TidAble<'input>,

Auto Trait Implementations§

§

impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !Freeze for BaseParser<'input, Ext, I, Ctx, T>

§

impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !RefUnwindSafe for BaseParser<'input, Ext, I, Ctx, T>

§

impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !Send for BaseParser<'input, Ext, I, Ctx, T>

§

impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !Sync for BaseParser<'input, Ext, I, Ctx, T>

§

impl<'input, Ext, I, Ctx, T> Unpin for BaseParser<'input, Ext, I, Ctx, T>
where I: Unpin, Ext: Unpin, T: ?Sized,

§

impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !UnwindSafe for BaseParser<'input, Ext, I, Ctx, T>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.