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

The order which the nodes are processed can be determined 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 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.