Skip to main content

ParseTreePattern

Struct ParseTreePattern 

Source
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

Source

pub fn pattern(&self) -> &str

The tree-pattern source string this was compiled from.

Source

pub const fn pattern_rule_index(&self) -> usize

The parser rule index that roots the pattern.

Source

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.

Source

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).

Source

pub fn matches(&self, tree: Node<'_>) -> bool

Returns whether tree matches this pattern.

Source

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.

Trait Implementations§

Source§

impl Debug for ParseTreePattern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.