O'Reilly logo

Groovy for Domain-specific Languages - Second Edition by Fergal Dearle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Global AST transformations

Next, we will look at a global AST transformation. Unlike the local transformations we have just encountered, which are targeted at a specific part of the Groovy code, a global transformation is invoked for all AST nodes in the compiled code. Let's take a look at a fully worked global AST transformation example.

A finite state machine DSL

We will be a bit brave with this transformation. In fact, the transformed AST code for this transformation will look nothing like the original compiled code. The goal of this AST transformation is to provide a mini DSL for defining finite state machines. The syntax we are aiming for takes its queue from Spock and uses labels and string literals to be part of the DSL syntax.

Let's start ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required