SmaCC Transformation Toolkit properties
Scripts can define properties that are accessed through automatically generated getter and setter methods. For example, the method described on the SmaCC Transformation Toolkit methods page uses temporaryVariables and functions, and these properties are defined by a property rule:
nil for each file being transformed. Global properties retain their values across transformed files.
Global properties are useful for expensive computations whose results are reused for every processed file. For example, you might load an external file that controls the rules. You do not want to load that file for every source file, especially when processing thousands of files. Instead, you can initialize the global property once using SmaCCRewriteMatchContext>>#initializeGlobalProperty:withValueFrom:
and then access its value while processing other files.
To initialize properties before other rules are applied, it is common to create a rewrite rule that matches the top-level AST node. In the rewrite transformation, perform the required initialization and then call self continue.
To match the top-level AST node, you can either match the node type returned by the parser, or match SmaCCParseNode
with a matching expression such as match parent isNil.