Patterns are strings of source input text with special tags representing token or rule references such as:
{@code
Given a pattern start rule such as {@code statement}, this object constructs a {@link ParseTree} with placeholders for the {@code ID} and {@code expr}subtree. Then the {@link #match} routines can compare an actual{@link ParseTree} from a parse with this pattern. Tag {@code
Pattern {@code x = 0;} is a similar pattern that matches the same patternexcept that it requires the identifier to be {@code x} and the expression tobe {@code 0}.
The {@link #matches} routines return {@code true} or {@code false} basedupon a match for the tree rooted at the parameter sent in. The {@link #match} routines return a {@link ParseTreeMatch} object thatcontains the parse tree, the parse tree pattern, and a map from tag name to matched nodes (more below). A subtree that fails to match, returns with {@link ParseTreeMatch#mismatchedNode} set to the first tree node that did notmatch.
For efficiency, you can compile a tree pattern in string form to a {@link ParseTreePattern} object.
See {@code TestParseTreeMatcher} for lots of examples.{@link ParseTreePattern} has two static helper methods:{@link ParseTreePattern#findAll} and {@link ParseTreePattern#match} thatare easy to use but not super efficient because they create new {@link ParseTreePatternMatcher} objects each time and have to compile thepattern in string form before using it.
The lexer and parser that you pass into the {@link ParseTreePatternMatcher}constructor are used to parse the pattern in string form. The lexer converts the {@code
Normally a parser does not accept token {@code
Delimiters are {@code <} and {@code>}, with {@code \} as the escape stringby default, but you can set them to whatever you want using {@link #setDelimiters}. You must escape both start and stop strings {@code \<} and {@code \>}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|