Metadata
Number: |
GEP-2 |
Title: |
AST Builder Support |
Version: |
1 |
Type: |
Feature |
Target: |
1.7 |
Status: |
Draft |
Leader: |
|
Created: |
2009-04-01 |
Last modification: |
2009-04-01 |
Abstract
Groovy 1.6 introduced the ability to perform local and global AST (Abstract Syntax Tree) transformations, allowing users to read and modify the AST of Groovy code as it is being compiled. Reading information in the AST is relatively easy in Groovy. The core library provides a strongly typed visitor called GroovyCodeVisitor. Nodes can be read and modified using the API provided through the subtypes of ASTNode. Writing new AST nodes is not as simple. The AST generated from source is not always obvious, and using constructor calls to generate trees of nodes can be verbose. This GEP proposes an ASTBuilder object that allows users to easily create AST.
The ASTBuilder object allows AST to be created from Strings containing Groovy source code, from a closure containing Groovy source, and from a closure containing an AST creation DSL.
Approach
General Approach
Examples
The following examples have all been proposed at some point:
1. ASTNode form GString
2. ASTNode from GString in Closure
3. ASTNode from Templated GString
4. ASTNode from code block
5. ASTNode from psuedo-specification
Advantages
Disadvantages
Alternatives
References
Mailing-list discussions
JIRA issues
- Pending
Useful links
- Boo Meta Methods
- Template Haskell in Wikipedia
- Template Haskell Home Page
- "First Stab at Template Haskell" Blog Post
Reference Implementation
Pending...
