Skip to main content

ParseTreePatternMatcher

Struct ParseTreePatternMatcher 

Source
pub struct ParseTreePatternMatcher<'a> { /* private fields */ }
Expand description

Compiles tree patterns for one grammar.

Holds the grammar’s rule-bypass ATN and recognizer metadata; each Self::compile call lexes the pattern’s literal chunks (via the supplied PatternLexer), converts tags into synthetic tokens, and interprets the hybrid stream to build a reusable ParseTreePattern.

Most callers reach this through the compile_parse_tree_pattern method on generated parsers; construct one directly to reuse the bypass ATN across many patterns or to customize delimiters.

Implementations§

Source§

impl<'a> ParseTreePatternMatcher<'a>

Source

pub fn new( atn: &ParserAtn, data: &'a RecognizerData, ) -> Result<Self, ParseTreePatternError>

Creates a matcher for a grammar’s parser ATN and recognizer metadata.

The bypass ATN is derived from atn once here and reused by every compile. data supplies rule and token names for resolving tags.

§Errors

Returns ParseTreePatternError::BypassAtn if the rule-bypass transform of atn fails (e.g. an unrecognizable left-recursive precedence prefix).

Source

pub fn set_delimiters( &mut self, start: impl Into<String>, stop: impl Into<String>, escape: impl Into<String>, ) -> Result<(), ParseTreePatternError>

Overrides the tag delimiters and escape string (defaults <, >, \).

Useful for grammars whose concrete syntax already uses <...>. Unlike upstream, an empty escape is accepted and simply disables escaping (Java’s indexOf-based scan misbehaves on an empty escape string).

§Errors

Returns ParseTreePatternError::EmptyDelimiter when start or stop is empty, mirroring upstream’s IllegalArgumentException — an empty delimiter would silently collapse every pattern into one text chunk.

Source

pub fn compile( &self, pattern: &str, rule_index: usize, lexer: impl PatternLexer, ) -> Result<ParseTreePattern, ParseTreePatternError>

Compiles pattern, rooted at parser rule rule_index, into a reusable ParseTreePattern.

lexer tokenizes the pattern’s literal chunks; tags become synthetic rule/token tokens, and the hybrid stream is interpreted over the bypass ATN starting at rule_index.

§Errors

Returns a ParseTreePatternError for a malformed pattern, an unknown rule/token tag, a lexer failure, an interpretation failure, or a pattern the start rule does not fully consume.

Trait Implementations§

Source§

impl<'a> Debug for ParseTreePatternMatcher<'a>

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.