Skip to content

Instantly share code, notes, and snippets.

@melix
Created November 12, 2014 07:27
Show Gist options
  • Save melix/7b8fb3413b52e17cbd35 to your computer and use it in GitHub Desktop.
Save melix/7b8fb3413b52e17cbd35 to your computer and use it in GitHub Desktop.
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