Struct antlr_rust::parser::BaseParser
source · [−]pub struct BaseParser<'input, Ext, 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
sourceimpl<'input, Ext, I, Ctx, T> BaseParser<'input, Ext, I, Ctx, T> where
Ext: ParserRecog<'input, Self>,
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>,
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>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
where
L: CoerceTo<T>,
pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
where
L: CoerceTo<T>,
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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
sourceimpl<'input, Ext, I, Ctx, T> Deref for BaseParser<'input, Ext, I, Ctx, T> where
Ext: ParserRecog<'input, Self>,
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>,
I: TokenStream<'input>,
Ctx: ParserNodeType<'input, TF = I::TF>,
T: ParseTreeListener<'input, Ctx> + ?Sized,
sourceimpl<'input, Ext, I, Ctx, T> DerefMut for BaseParser<'input, Ext, I, Ctx, T> where
Ext: ParserRecog<'input, Self>,
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>,
I: TokenStream<'input>,
Ctx: ParserNodeType<'input, TF = I::TF>,
T: ParseTreeListener<'input, Ctx> + ?Sized,
sourceimpl<'input, Ext, I, Ctx, T> Parser<'input> for BaseParser<'input, Ext, I, Ctx, T> where
Ext: ParserRecog<'input, Self>,
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>,
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 remove_error_listeners(&mut 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>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
impl<'input, Ext: TidAble<'input>, I: TidAble<'input>, Ctx: TidAble<'input>, T: TidAble<'input>> TidAble<'input> for BaseParser<'input, Ext, I, Ctx, T> where
I: TokenStream<'input>,
Ctx: ParserNodeType<'input, TF = I::TF>,
T: ParseTreeListener<'input, Ctx> + ?Sized,
Auto Trait Implementations
impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx> + 'static> !RefUnwindSafe for BaseParser<'input, Ext, I, Ctx, T>
impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx> + 'static> !Send for BaseParser<'input, Ext, I, Ctx, T>
impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx> + 'static> !Sync for BaseParser<'input, Ext, I, Ctx, T>
impl<'input, Ext, I, Ctx, T: ?Sized> Unpin for BaseParser<'input, Ext, I, Ctx, T> where
Ext: Unpin,
I: Unpin,
impl<'input, Ext, I, Ctx, T = dyn ParseTreeListener<'input, Ctx> + 'static> !UnwindSafe for BaseParser<'input, Ext, I, Ctx, T>
Blanket Implementations
sourceimpl<T> AnyExt for T where
T: Any + ?Sized,
impl<T> AnyExt for T where
T: Any + ?Sized,
sourcefn downcast_ref<T>(this: &Self) -> Option<&T> where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T> where
T: Any,
Attempts to downcast this to T
behind reference
sourcefn 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,
Attempts to downcast this to T
behind mutable reference
sourcefn 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,
Attempts to downcast this to T
behind Rc
pointer
sourcefn 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,
Attempts to downcast this to T
behind Arc
pointer
sourcefn downcast_box<T>(
this: Box<Self, Global>
) -> Result<Box<T, Global>, Box<Self, Global>> where
T: Any,
fn downcast_box<T>(
this: Box<Self, Global>
) -> Result<Box<T, Global>, Box<Self, Global>> where
T: Any,
Attempts to downcast this to T
behind Box
pointer
sourcefn downcast_move<T>(this: Self) -> Option<T> where
T: Any,
fn downcast_move<T>(this: Self) -> Option<T> where
T: Any,
Attempts to downcast owned Self
to T
,
useful only in generic context as a workaround for specialization Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, X> CoerceTo<T> for X where
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for X where
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X, Global>) -> Box<T, Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
sourceimpl<'a, X> TidExt<'a> for X where
X: Tid<'a> + ?Sized,
impl<'a, X> TidExt<'a> for X where
X: Tid<'a> + ?Sized,
sourcefn is<T>(&self) -> bool where
T: Tid<'a>,
fn is<T>(&self) -> bool where
T: Tid<'a>,
Returns true if type behind self is equal to the type of T.
sourcefn downcast_ref<T>(&'b self) -> Option<&'b T> where
T: Tid<'a>,
fn downcast_ref<T>(&'b self) -> Option<&'b T> where
T: Tid<'a>,
Attempts to downcast self to T
behind reference
sourcefn downcast_mut<T>(&'b mut self) -> Option<&'b mut T> where
T: Tid<'a>,
fn downcast_mut<T>(&'b mut self) -> Option<&'b mut T> where
T: Tid<'a>,
Attempts to downcast self to T
behind mutable reference
sourcefn 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>,
Attempts to downcast self to T
behind Rc
pointer
sourcefn 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>,
Attempts to downcast self to T
behind Arc
pointer
sourcefn downcast_box<T>(
self: Box<Self, Global>
) -> Result<Box<T, Global>, Box<Self, Global>> where
T: Tid<'a>,
fn downcast_box<T>(
self: Box<Self, Global>
) -> Result<Box<T, Global>, Box<Self, Global>> where
T: Tid<'a>,
Attempts to downcast self to T
behind Box
pointer
sourcefn downcast_move<T>(self) -> Option<T> where
T: Tid<'a>,
fn downcast_move<T>(self) -> Option<T> where
T: Tid<'a>,
Attempts to downcast owned Self
to T
,
useful only in generic context as a workaround for specialization Read more