Skip to content

Instantly share code, notes, and snippets.

@melix
Created November 12, 2014 07:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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