SmaCC Transformation Toolkit script file
Scripts are files that contain SmaCC 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 applied in the order in which they appear in the script.
In general, it is better to structure your rules as editing operations instead of building entirely new source text. For example, consider these two different rules for rewriting begin and end in blocks to {} for Javascript. The first edits the original source by changing the tokens to curly brackets:
The order in which nodes are processed can be controlled by where the SmaCCRewriteMatchContext>>#continue
, SmaCCRewriteMatchContext>>#processChild:
, or SmaCCRewriteMatchContext>>#processChildren
messages are sent in the code. Normally, AST nodes are processed from the root to the leaves, but this can be changed. For example, if you add a rewrite rule at the top of the script that simply sends self processChildren followed by self continue, you can effectively change the top-down traversal into a bottom-up traversal from leaves to root. If the order does not matter, having self continue at the end is best, because tail-recursion elimination is performed to keep the stack size down.