SmaCC Transformation Toolkit script file
Scripts are files that containSmaCC Transformation Toolkit rewrite rules,SmaCC Transformation Toolkit methods, SmaCC Transformation Toolkit properties, or imports of other script files. When AST nodes are processed by the script, the rules are processed in order that they appear in the script.
In general it is better to structure your rules as editing operations instead of building a new source for everything. As an example, consider the these two different rules for rewriting begin and end in blocks to be {} for Javascript. The first just edits the original source by changing the tokens to be curly brackets:
The order which the nodes are processed can be determined by where the SmaCCRewriteMatchContext>>#continue
, SmaCCRewriteMatchContext>>#processChild:
, or SmaCCRewriteMatchContext>>#processChildren
messages are put in the code. For example, normally AST nodes are processed from the root to the leaves, but that can be changed. For example, if you add a rewrite rule at the top of the script that simply does a self processChildren followed by a self continue, you can effectively change the top-down traversal into a bottom-up (leaves to root) traversal. If the order does not matter, then having self continue at the end is the best since tail recursion elimination is performed to keep the stack size down.