Created
November 12, 2014 10:01
-
-
Save melix/6875e12077908129f400 to your computer and use it in GitHub Desktop.
AST pattern matching with relaxed constraints 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void testInlineMacroCombinationWithConstraints() { | |
use(ASTMatcher) { | |
def ast1 = macro { a + b } | |
def ast2 = macro { b + b } | |
def ast3 = macro { b + c } | |
def ast4 = macro { b - b } | |
def pattern = macro { | |
$v { macro { a }.withConstraints { placeholder a } } + b | |
}.withConstraints { | |
anyToken() | |
} | |
assert pattern instanceof BinaryExpression | |
assert ast1.matches(pattern) | |
assert ast2.matches(pattern) | |
assert !ast3.matches(pattern) | |
assert ast4.matches(pattern) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same pattern can be written:
The idea of the previous example is more to highlight the ability to put constraints on specific parts of the pattern and combine ASTs.