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>
impl<'a> ParseTreePatternMatcher<'a>
Sourcepub fn new(
atn: &ParserAtn,
data: &'a RecognizerData,
) -> Result<Self, ParseTreePatternError>
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).
Sourcepub fn set_delimiters(
&mut self,
start: impl Into<String>,
stop: impl Into<String>,
escape: impl Into<String>,
) -> Result<(), ParseTreePatternError>
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.
Sourcepub fn compile(
&self,
pattern: &str,
rule_index: usize,
lexer: impl PatternLexer,
) -> Result<ParseTreePattern, ParseTreePatternError>
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.