Local AST transformations

When discussing AST transformations in Groovy, we refer to local and global AST transformations. A local transformation is one that is targeted at a specific "local" piece of code. Currently, the only way to tell the Groovy compiler to implement a local transformation is to use an annotation. The annotation gives the compiler the clue as to what part of the compiled code should be transformed. Annotations can be placed next to any part of the Groovy source code, but are typically bound to a class, field, or method.

Let's start out by implementing a very simple annotation based on an AST transformation. Ultimately, we will evolve this example into an AST that implements the pretty printing functionality we built back in ...

Get Groovy for Domain-specific Languages - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.