GROOVY Questions and Answers

Explain how you can build AST (Abstract Syntax Trees) in Groovy from string?

You can build AST in Groovy from

  • Strings
  • Code
  • From DSL like specification

An AstBuilder object provides an API to build AST from strings of Groovy Source Code. For example

List<ASTNode> nodes = new AstBuilder (). buildFromString (“\”Hello\” “)