pub enum ParseTree {
Rule(RuleNode),
Terminal(TerminalNode),
Error(ErrorNode),
}Variants§
Implementations§
Source§impl ParseTree
impl ParseTree
Sourcepub fn children(&self) -> &[Self]
pub fn children(&self) -> &[Self]
Returns this node’s direct children.
Rule nodes return their context children; terminal and error nodes
return an empty slice, so generic recursive walks can start from a
&ParseTree without matching on every variant first.
Sourcepub fn descendants(&self) -> ParseTreeDescendants<'_> ⓘ
pub fn descendants(&self) -> ParseTreeDescendants<'_> ⓘ
Iterates this tree in pre-order, starting with self.
Sourcepub fn pre_order(&self) -> ParseTreeDescendants<'_> ⓘ
pub fn pre_order(&self) -> ParseTreeDescendants<'_> ⓘ
Iterates this tree in pre-order, starting with self.
This is an alias for Self::descendants for callers that prefer to
name the traversal order explicitly.
pub fn text(&self) -> String
pub fn to_string_tree_with_names<S: AsRef<str>>( &self, rule_names: &[S], ) -> String
Sourcepub fn to_string_tree<R: Recognizer>(&self, recognizer: Option<&R>) -> String
pub fn to_string_tree<R: Recognizer>(&self, recognizer: Option<&R>) -> String
Renders the LISP-style tree using rule names resolved through a
recognizer, matching ANTLR’s toStringTree(parser) shape used by
generated test actions (<tree>.to_string_tree(Some(self))).
Sourcepub fn first_rule(&self, rule_index: usize) -> Option<&Self>
pub fn first_rule(&self, rule_index: usize) -> Option<&Self>
Finds the first rule node with rule_index in a depth-first walk.
Sourcepub fn first_rule_stop(&self, rule_index: usize) -> Option<&CommonToken>
pub fn first_rule_stop(&self, rule_index: usize) -> Option<&CommonToken>
Finds the stop token for the first rule node with rule_index.
Sourcepub fn first_rule_int_return(
&self,
rule_index: usize,
name: &str,
) -> Option<i64>
pub fn first_rule_int_return( &self, rule_index: usize, name: &str, ) -> Option<i64>
Reads an integer return value from the first rule node with
rule_index, matching ANTLR’s $label.value resolution for labeled
rule references in the runtime testsuite.
Sourcepub fn rule_attrs<T: Any>(&self) -> Option<&T>
pub fn rule_attrs<T: Any>(&self) -> Option<&T>
Reads the typed attribute snapshot from this tree’s root rule node.
Generated parsers use this for $label.attr / $rule.attr reads on a
child subtree returned by a rule call.
Sourcepub fn first_error_token(&self) -> Option<&CommonToken>
pub fn first_error_token(&self) -> Option<&CommonToken>
Finds the first recovery error token in a depth-first walk.