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 second replaces the original source with a string built from the statements in the block:
The first version is better not only because it is faster, but also because it preserves most of the formatting of the original code. It also makes debugging easier, because each edit operation is tagged with the rule that performed it.

The order in which nodes are processed can be controlled by where the SmaCCRewriteMatchContext>>#continue continue continuation value , SmaCCRewriteMatchContext>>#processChild: processChild: aSmaCCParseNode rewriteEngine rewriteNode: aSmaCCParseNode , or SmaCCRewriteMatchContext>>#processChildren processChildren match nodesDo: [ :each | self processChild: each ] 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.