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>>,
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>>,
pub fn new_base_parser( input: I, interpreter: Arc<ParserATNSimulator>, ext: Ext, ) -> Self
pub fn match_token( &mut self, ttype: isize, err_handler: &mut impl ErrorStrategy<'input, Self>, ) -> Result<<I::TF as TokenFactory<'input>>::Tok, ANTLRError>
pub fn match_wildcard( &mut self, err_handler: &mut impl ErrorStrategy<'input, Self>, ) -> Result<<I::TF as TokenFactory<'input>>::Tok, ANTLRError>
Sourcepub fn add_parse_listener<L>(&mut self, listener: Box<L>) -> ListenerId<L>where
L: CoerceTo<T>,
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
Sourcepub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>where
L: CoerceTo<T>,
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
Sourcepub fn remove_parse_listeners(&mut self)
pub fn remove_parse_listeners(&mut self)
Removes all added parse listeners without returning them
pub fn trigger_enter_rule_event(&mut self)
pub fn trigger_exit_rule_event(&mut self)
pub fn enter_rule( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, )
pub fn exit_rule(&mut self)
pub fn enter_outer_alt( &mut self, new_ctx: Option<Rc<Ctx::Type>>, alt_num: isize, )
pub fn enter_recursion_rule( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, precedence: isize, )
pub fn push_new_recursion_context( &mut self, localctx: Rc<Ctx::Type>, state: isize, _rule_index: usize, )
pub fn unroll_recursion_context(&mut self, parent_ctx: Option<Rc<Ctx::Type>>)
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,
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§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>>,
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>>,
fn get_interpreter(&self) -> &ParserATNSimulator
fn get_token_factory(&self) -> &'input Self::TF
fn get_parser_rule_context(&self) -> &Rc<Ctx::Type>
fn consume(&mut self, err_handler: &mut impl ErrorStrategy<'input, Self>)
fn precpred(&self, _localctx: Option<&Ctx::Type>, precedence: isize) -> bool
fn get_input_stream_mut( &mut self, ) -> &mut dyn TokenStream<'input, TF = Self::TF>
fn get_input_stream(&self) -> &dyn TokenStream<'input, TF = Self::TF>
fn get_current_token(&self) -> &<Self::TF as TokenFactory<'input>>::Tok
fn get_expected_tokens(&self) -> IntervalSet
fn add_error_listener(&mut self, listener: Box<dyn ErrorListener<'input, Self>>)
fn notify_error_listeners( &self, msg: String, offending_token: Option<isize>, err: Option<&ANTLRError>, )
fn get_error_lister_dispatch<'a>( &'a self, ) -> Box<dyn ErrorListener<'input, Self> + 'a>
fn is_expected_token(&self, _symbol: isize) -> bool
fn get_precedence(&self) -> isize
fn get_state(&self) -> isize
fn set_state(&mut self, v: isize)
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,
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,
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>
impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx>> !UnwindSafe for BaseParser<'input, Ext, I, Ctx, T>
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T
behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T
behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T
behind Rc
pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T
behind Arc
pointerSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
Source§impl<'a, X> TidExt<'a> for X
impl<'a, X> TidExt<'a> for X
Source§fn is<T>(&self) -> boolwhere
T: Tid<'a>,
fn is<T>(&self) -> boolwhere
T: Tid<'a>,
Source§fn downcast_ref<'b, T>(&'b self) -> Option<&'b T>where
T: Tid<'a>,
fn downcast_ref<'b, T>(&'b self) -> Option<&'b T>where
T: Tid<'a>,
T
behind referenceSource§fn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>where
T: Tid<'a>,
fn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>where
T: Tid<'a>,
T
behind mutable referenceSource§fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Tid<'a>,
fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Tid<'a>,
T
behind Rc
pointerSource§fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Tid<'a>,
fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Tid<'a>,
T
behind Arc
pointer