3
votes

I wrote a Global AST transformation that should be applied to DSL scripts, and am now in the process of selecting the best way to identify specific groovy scripts as these DSL scripts.

I considered the following options:

  1. A custom file extension; The biggest disadvantage here is IDE support: many barely support compilation/editing of files that have non-groovy extensions (you can configure an editor but it requires some tweaking).
  2. A special file name suffix (prefix) but in this case the suffix should be really unique (and thus relatively long) to avoid accidental transformation of regular groovy files (my current choice).
  3. A local AST transformation applied to a script class, this has as disadvantage that one would need to write some boilerplate code for each script.
  4. Having some unique first statement in the scripts that will identify the DSL.

What would in your opinion be the best option to choose and why? Are there any other options at my disposal that I haven't thought about?

1

1 Answers

0
votes

If you compile your DSL scripts using GroovyShell you can use CompilerConfiguration.addCompilationCustomizer(ASTTransformationCustomizer(YourGlobalASTTransformation)) to apply the transformation on them.