A simple AST-transformer plugin architecture for Opal...
-> subclass OCCompilerASTPlugin
-> implement #transform e.g.
transform
| rule |
rule := RBParseTreeRewriter replaceLiteral: 42 with: 'meaning of life'.
rule executeTree: ast.
^ast
The plugin can be activated *per class hierarchy* by overriding #compiler
compiler
"the example plugin is active for this class"
^super compiler addPlugin: ASTPluginMeaningOfLife.
or of course for a single compilation:
(Smalltalk compiler addPlugin: ASTPluginMeaningOfLife) evaluate: ’42’
For review here:
https://pharo.fogbugz.com/f/cases/15019/Compiler-AST-transformation-Plugins Marcus