BaseTranslationRule'2
Class for Extensibility Translation Rules with two generic arguments. Forces the 'IsApplicable' and 'Replace' methods to be implemented.
Class Definition
This class allows the creation of additional translation rule classes using two generic arguments:
TInputAst
, the input AST type, i.e, the type of AST that this translation rule will work with.TOutputAst
, the output (result) AST type, i.e, the type of AST that this translation rule will return. Most likely, it must be the same type asTInputAST
.
With this BaseExtensibleTranslationRule
overload, the user can create simple additional translation rule classes that need no more than the input AST for creating the output AST. If more information is needed to do this, the BaseTranslationRule'3
class is available.
Class Members to Override
IsApplicable
The IsApplicable
method filters out the instances of the TInputAst
type that should be excluded from this translation rule class. Sometimes it is necessary to do this because the translation only applies to a subset of all instances of the TInputAst
type; such criteria must be specified in the IsApplicable
method. If the translation rule needs to apply to all instances, the user can just return true.
Replace
The Replace
method is the one in charge of defining how the given nodes must be transformed into Snowflake equivalent code. Notice the outputNode
parameter is an out parameter that must be assigned before the end of the method. This argument represents the code in Snowflake that should be functionally equivalent to the inputNode
AST. Here are some common ways to assign this parameter:
If the input node is already fully supported in Snowflake, the user can you assign
outputNode = inputNode
, to mark the node as supported.If the input node should be removed from the output code, maybe because it is not applicable in Snowflake due to architectural reasons, the user can assign
outputNode = null
, to remove the element.If the input node needs to be transformed somehow to make it compatible with Snowflake, then a new node must be emitted with such modifications. As mentioned before, by design choice, the ASTs are immutable, so there is no way to modify an existing node, so a new one should be created by using Emitters. You can read more about it here.
Last updated