Book Image

Groovy for Domain-Specific Languages, Second Edition

By : Fergal Dearle
Book Image

Groovy for Domain-Specific Languages, Second Edition

By: Fergal Dearle

Overview of this book

Table of Contents (20 chapters)
Groovy for Domain-specific Languages Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introduction to DSLs and Groovy
Index

Chapter 8. AST Transformations

In this chapter, we will take a look at Groovy abstract syntax tree (AST) transformations. AST transformations are a mechanism for us to hook the Groovy compilation process. Up to now, we have looked at Groovy's runtime metaprogramming abilities. Here, we will look at compile time metaprogramming and see how we can use AST transformations to build code on the fly during the compilation process. This is a complex subject, for which we will focus on the following aspects in detail:

  • Local AST transformations: We will look at how we can use a local AST transformation to implement an annotation

  • Manipulating the AST: We will look at the various mechanisms for adding code to our programs using the ASTNode APIs and the ASTBuilder class

  • Global AST transformations: We will build one complete DSL based on a Global AST transformation

  • Compilation errors: We will learn how to add our own compilation errors

  • Packaging an AST transformation: We will learn how to package an...