A simple AST-transformer plugin architecture for Opal…

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

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: