Expand description
ANTLR parse-tree pattern matching.
A tree pattern is a string of ordinary grammar input with embedded
<tag> placeholders — for example <ID> = <expr>; matched as the rule
stat. Literals must match exactly; a <rule> tag matches any subtree of
that parser rule and a <TOKEN> tag matches any token of that type. Tags
may carry a label, <lhs:ID>, so matched nodes can be looked up by name.
This mirrors ANTLR’s org.antlr.v4.runtime.tree.pattern package. Compiling
a pattern lexes its literal chunks with the real lexer, converts each tag
into a synthetic rule/token tag token (ANTLR’s RuleTagToken /
TokenTagToken), and interprets that hybrid token stream over a rule-bypass
ATN (see crate::atn::parser_atn::ParserAtn::with_bypass_alternatives) to
build a pattern tree. ParseTreePattern::match_tree then walks a
subject tree and the pattern tree in lockstep, binding tag labels.
The ergonomic entry point is the compile_parse_tree_pattern method every
generated parser exposes; ParseTreePatternMatcher is the lower-level,
reusable compiler behind it.
Structs§
- Parse
Tree Match - The result of matching a subject tree against a
ParseTreePattern. - Parse
Tree Pattern - A pattern like
<ID> = <expr>;compiled to a reusable tree. - Parse
Tree Pattern Matcher - Compiles tree patterns for one grammar.
Enums§
- Parse
Tree Pattern Error - An invalid tree pattern or a failure while compiling one.
Traits§
- Pattern
Lexer - Lexes one literal pattern chunk into the token specs it produces.
Functions§
- lex_
pattern_ chunk - Runs a lexer over one chunk of pattern text and returns its token specs
(every non-EOF token, on its original channel), suitable for a
PatternLexer.