pub enum ParseTree {
Rule(RuleNode),
Terminal(TerminalNode),
Error(ErrorNode),
}Variants§
Implementations§
Source§impl ParseTree
impl ParseTree
Sourcepub fn children(&self) -> &[ParseTree]
pub fn children(&self) -> &[ParseTree]
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>(&self, rule_names: &[S]) -> String
Sourcepub fn to_string_tree<R>(&self, recognizer: Option<&R>) -> Stringwhere
R: Recognizer,
pub fn to_string_tree<R>(&self, recognizer: Option<&R>) -> Stringwhere
R: Recognizer,
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<&ParseTree>
pub fn first_rule(&self, rule_index: usize) -> Option<&ParseTree>
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>(&self) -> Option<&T>where
T: Any,
pub fn rule_attrs<T>(&self) -> Option<&T>where
T: Any,
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.