pub struct ParseTreePattern { /* private fields */ }Expand description
A pattern like <ID> = <expr>; compiled to a reusable tree.
Created by ParseTreePatternMatcher::compile or
a generated parser’s compile_parse_tree_pattern. Match a subject tree with
Self::match_tree (full result) or Self::matches (boolean).
Implementations§
Source§impl ParseTreePattern
impl ParseTreePattern
Sourcepub const fn pattern_rule_index(&self) -> usize
pub const fn pattern_rule_index(&self) -> usize
The parser rule index that roots the pattern.
Sourcepub fn pattern_tree(&self) -> Node<'_>
pub fn pattern_tree(&self) -> Node<'_>
The compiled pattern as a parse tree, with tags present as terminal leaves (a rule tag is a rule node whose single child carries the imaginary bypass token).
Mirrors ANTLR’s ParseTreePattern.getPatternTree; useful for inspecting
why a pattern that compiled does not match a subject —
pattern_tree().text() renders the tag placeholders inline.
Sourcepub fn match_tree<'subject>(
&self,
tree: Node<'subject>,
) -> ParseTreeMatch<'subject>
pub fn match_tree<'subject>( &self, tree: Node<'subject>, ) -> ParseTreeMatch<'subject>
Matches tree against this pattern, returning the full result including
bound labels and the first mismatched node (if any).
Sourcepub fn find_all<'subject, R>(
&self,
tree: Node<'subject>,
xpath: &str,
recognizer: &R,
) -> Result<Vec<ParseTreeMatch<'subject>>, XPathError>where
R: Recognizer + ?Sized,
pub fn find_all<'subject, R>(
&self,
tree: Node<'subject>,
xpath: &str,
recognizer: &R,
) -> Result<Vec<ParseTreeMatch<'subject>>, XPathError>where
R: Recognizer + ?Sized,
Finds nodes under tree with an XPath expression, then returns the
successful matches of this pattern against those subtrees.
Mirrors ANTLR’s ParseTreePattern.findAll: unsuccessful matches are
omitted, whatever the reason for the failure. recognizer resolves the
rule and token names in xpath, exactly as in
XPath::find_all.
§Errors
Returns XPathError when xpath is not a valid
parse-tree path expression.