Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AST pattern matching with relaxed constraints
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