AST pattern matching with relaxed constraints
This file contains 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 testRelaxedBinaryExpressionWithConstrainedToken() { | |
use(ASTMatcher) { | |
def ast1 = macro { a + b } | |
def ast2 = macro { a - b } | |
def ast3 = macro { a * b } | |
def ast4 = macro { a + c } | |
def pattern = macro { | |
a + b | |
}.withConstraints { | |
token { | |
type in [Types.PLUS, Types.MINUS] | |
} | |
} | |
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