Skip to main content

BaseParser

Struct BaseParser 

Source
pub struct BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Ext: ParserRecog<'input, 'arena, Self>, TF: TokenFactory<'input, 'arena> + 'arena, Input: TokenStream<'input, 'arena, TF>, Node: RuleNode<'input, 'arena>,
{ pub interp: Arc<ParserATNSimulator>, pub build_parse_trees: bool, pub matched_eof: bool, pub input: Input, pub arena: &'arena Arena, /* private fields */ }
Expand description

Abstract base parser implementation

Only meant to be instantiated by generated parsers

Fields§

§interp: Arc<ParserATNSimulator>§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: Input

Token stream that is currently used by this parser

§arena: &'arena Arena

Implementations§

Source§

impl<'input, 'arena, Ext, Node, Input, TF> BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Ext: ParserRecog<'input, 'arena, Self>, TF: TokenFactory<'input, 'arena> + 'arena, Input: TokenStream<'input, 'arena, TF>, Node: RuleNode<'input, 'arena>,

Source

pub fn new_base_parser( arena: &'arena Arena, input: Input, interpreter: Arc<ParserATNSimulator>, ext: Ext, ) -> Self

Source

pub fn ctx_is(&self, other: Option<&'arena Node>) -> bool

If current context is same as the given one by pointer comparison

Source

pub fn ctx(&self) -> Option<&'arena Node>

Gets a reference to current context.

Source

pub unsafe fn ctx_mut(&mut self) -> Option<&'arena mut Node>

Gets a mutable reference to current context.

§Safety

Follows the same safety rules as dereferencing *mut to &mut

Source

pub fn take_ctx(&mut self) -> Option<&'arena Node>

Source

pub fn with_mut_ctx<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Node) -> R,

Source

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

Source

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

Source

pub fn add_dyn_parse_listener(&mut self, listener: Box<Node::Listener>)

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

§Example for listener usage:

todo

Source

pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>
where L: ParseTreeListener<'input, 'arena, Node>,

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) -> Result<(), ANTLRError>

Source

pub fn trigger_exit_rule_event(&mut self) -> Result<(), ANTLRError>

Source

pub fn enter_rule( &mut self, localctx: Node, state: i32, _rule_index: usize, ) -> Result<(), ANTLRError>

Source

pub fn exit_rule(&mut self) -> Result<&'arena Node, ANTLRError>

Source

pub fn enter_recursion_rule( &mut self, localctx: Node, state: i32, _rule_index: usize, precedence: i32, ) -> Result<(), ANTLRError>

Source

pub fn push_new_recursion_context( &mut self, localctx: Node, state: i32, _rule_index: usize, ) -> Result<&'arena Node, ANTLRError>

Source

pub fn unroll_recursion_context( &mut self, parent_ctx: Option<&'arena Node>, ) -> Result<&'arena Node, ANTLRError>

Source

pub fn dump_dfa(&self)

Text representation of generated DFA for debugging purposes

Trait Implementations§

Source§

impl<'input, 'arena, Ext, Node, Input, TF> Deref for BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Ext: ParserRecog<'input, 'arena, Self>, TF: TokenFactory<'input, 'arena> + 'arena, Input: TokenStream<'input, 'arena, TF>, Node: RuleNode<'input, 'arena>,

Source§

type Target = Ext

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'input, 'arena, Ext, Node, Input, TF> DerefMut for BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Ext: ParserRecog<'input, 'arena, Self>, TF: TokenFactory<'input, 'arena> + 'arena, Input: TokenStream<'input, 'arena, TF>, Node: RuleNode<'input, 'arena>,

Source§

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

Mutably dereferences the value.
Source§

impl<'input, 'arena, Ext, Node, Input, TF> Parser<'input, 'arena, TF> for BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Ext: ParserRecog<'input, 'arena, Self>, TF: TokenFactory<'input, 'arena> + 'arena, Input: TokenStream<'input, 'arena, TF>, Node: RuleNode<'input, 'arena>, 'input: 'arena,

Source§

fn get_arena(&self) -> &'arena Arena

Source§

fn get_interpreter(&self) -> &ParserATNSimulator

Source§

fn get_token_factory(&self) -> &TF

Source§

fn get_current_context(&self) -> &'arena Node

Source§

fn consume( &mut self, err_handler: &mut impl ErrorStrategy<'input, 'arena, TF, Self>, ) -> Result<(), ANTLRError>

Source§

fn precpred(&self, _localctx: Option<&Node>, precedence: i32) -> bool

Source§

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

Source§

fn get_input_stream(&self) -> &dyn TokenStream<'input, 'arena, TF>

Source§

fn get_current_token(&self) -> &'arena TF::Tok

Source§

fn get_expected_tokens(&self) -> IntervalSet

Source§

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

Source§

fn remove_error_listeners(&mut 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, 'arena, Self> + 'a>

Source§

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

Source§

fn get_precedence(&self) -> i32

Source§

fn get_state(&self) -> i32

Source§

fn set_state(&mut self, v: i32)

Source§

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

Auto Trait Implementations§

§

impl<'input, 'arena, Ext, Node, Input, TF> !Freeze for BaseParser<'input, 'arena, Ext, Node, Input, TF>

§

impl<'input, 'arena, Ext, Node, Input, TF> !RefUnwindSafe for BaseParser<'input, 'arena, Ext, Node, Input, TF>

§

impl<'input, 'arena, Ext, Node, Input, TF> !Send for BaseParser<'input, 'arena, Ext, Node, Input, TF>

§

impl<'input, 'arena, Ext, Node, Input, TF> !Sync for BaseParser<'input, 'arena, Ext, Node, Input, TF>

§

impl<'input, 'arena, Ext, Node, Input, TF> Unpin for BaseParser<'input, 'arena, Ext, Node, Input, TF>
where Input: Unpin, Ext: Unpin,

§

impl<'input, 'arena, Ext, Node, Input, TF> !UnwindSafe for BaseParser<'input, 'arena, Ext, Node, Input, TF>

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