pub struct BaseParser<'input, 'arena, Ext, Node, Input, TF>where
Ext: ParserRecog<'input, 'arena, Self, TF::Tok>,
TF: TokenFactory<'input, 'arena> + 'arena,
Input: TokenStream<'input, 'arena, TF>,
Node: NodeKindType<'arena, TF::Tok>,
'input: 'arena,{
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§
§build_parse_trees: boolTrack 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: booltrue if parser reached EOF
input: InputToken stream that is currently used by this parser
arena: &'arena ArenaImplementations§
Source§impl<'input, 'arena, Ext, Node, Input, TF> BaseParser<'input, 'arena, Ext, Node, Input, TF>where
Ext: ParserRecog<'input, 'arena, Self, TF::Tok>,
TF: TokenFactory<'input, 'arena> + 'arena,
Input: TokenStream<'input, 'arena, TF>,
Node: NodeKindType<'arena, TF::Tok>,
'input: 'arena,
impl<'input, 'arena, Ext, Node, Input, TF> BaseParser<'input, 'arena, Ext, Node, Input, TF>where
Ext: ParserRecog<'input, 'arena, Self, TF::Tok>,
TF: TokenFactory<'input, 'arena> + 'arena,
Input: TokenStream<'input, 'arena, TF>,
Node: NodeKindType<'arena, TF::Tok>,
'input: 'arena,
pub fn new_base_parser(arena: &'arena Arena, input: Input, ext: Ext) -> Self
pub fn set_global_cache_threshold(&mut self, threshold: usize)
pub fn get_interpreter_mut(&mut self) -> &mut ParserATNSimulator<'arena>
Sourcepub fn ctx_is(
&self,
other: Option<&'arena TreeNode<'input, 'arena, Node, TF::Tok>>,
) -> bool
pub fn ctx_is( &self, other: Option<&'arena TreeNode<'input, 'arena, Node, TF::Tok>>, ) -> bool
If current context is same as the given one by pointer comparison
Sourcepub fn ctx(&self) -> Option<&'arena TreeNode<'input, 'arena, Node, TF::Tok>>
pub fn ctx(&self) -> Option<&'arena TreeNode<'input, 'arena, Node, TF::Tok>>
Gets a reference to current context.
Sourcepub unsafe fn ctx_mut(
&mut self,
) -> Option<&'arena mut TreeNode<'input, 'arena, Node, TF::Tok>>
pub unsafe fn ctx_mut( &mut self, ) -> Option<&'arena mut TreeNode<'input, 'arena, Node, TF::Tok>>
Gets a mutable reference to current context.
§Safety
Follows the same safety rules as dereferencing *mut to &mut
pub fn take_ctx( &mut self, ) -> Option<&'arena TreeNode<'input, 'arena, Node, TF::Tok>>
pub fn with_mut_ctx<F, R>(&mut self, f: F) -> R
pub fn match_token( &mut self, ttype: i32, err_handler: &mut impl ErrorStrategy<'input, 'arena, TF, Self>, ) -> Result<&'arena TF::Tok, ANTLRError>
pub fn match_wildcard( &mut self, err_handler: &mut impl ErrorStrategy<'input, 'arena, TF, Self>, ) -> Result<&'arena TF::Tok, ANTLRError>
Sourcepub fn add_dyn_parse_listener(&mut self, listener: Box<Node::Listener>)
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
Sourcepub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>where
L: ParseTreeListener<'arena, Node, TF::Tok>,
pub fn remove_parse_listener<L>(&mut self, listener_id: ListenerId<L>) -> Box<L>where
L: ParseTreeListener<'arena, Node, TF::Tok>,
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