Struct antlr_rust::parser::BaseParser [−][src]
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,
// some fields omitted
}
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
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>,
Rc<TerminalNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
Rc<ErrorNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
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>,
Rc<TerminalNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
Rc<ErrorNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
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>
pub fn add_parse_listener<L>(&mut self, listener: Box<L>) -> ListenerId<L> where
Box<L>: CoerceUnsized<Box<T>>,
pub fn add_parse_listener<L>(&mut self, listener: Box<L>) -> ListenerId<L> where
Box<L>: CoerceUnsized<Box<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
pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L> where
Box<L>: CoerceUnsized<Box<T>>,
pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L> where
Box<L>: CoerceUnsized<Box<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
Removes all added parse listeners without returning them
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
)
Trait Implementations
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, 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,
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>,
Rc<TerminalNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
Rc<ErrorNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
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>,
Rc<TerminalNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
Rc<ErrorNode<'input, Ctx>>: CoerceUnsized<Rc<Ctx::Type>>,
fn notify_error_listeners(
&self,
msg: String,
offending_token: Option<isize>,
err: Option<&ANTLRError>
)
impl<'input, Ext: 'static, I: TokenStream<'input>, Ctx: ParserNodeType<'input, TF = I::TF>, T: ParseTreeListener<'input, Ctx> + ?Sized> TidAble<'input> for BaseParser<'input, Ext, I, Ctx, T> where
I: TidAble<'input>,
Ctx: TidAble<'input>,
T: TidAble<'input>,
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
Mutably borrows from an owned value. Read more
Returns true if type behind self is equal to the type of T.
Attempts to downcast self to T
behind reference
Attempts to downcast self to T
behind mutable reference
Attempts to downcast self to T
behind Rc
pointer
Attempts to downcast self to T
behind Arc
pointer