BaseTranslationRule'3
Class for Extensibility Translation Rules with three generic arguments. Forces the 'IsApplicable' and 'Replace' methods to be implemented.
Class Definition
This class allows the creation of additional translation rule classes using three 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
.TContext
, a context object with information about the current translation process.
With the BaseExtensibleTranslationRule
overload of two arguments (without the context), the user can create simple translation rules that need nothing more than the input AST for creating the output AST. The difference with this overload of three arguments is the TContext
object, which contains additional information about the current translation process. Some of the properties the user can use from the context include, but are not limited to:
Parent
, the parent node of the current input AST. Sometimes, the same AST can be present in two different grammars, and the translation of the element depends on the context where is being used in. Asking theTContext
object for theParent
AST property can help in these situations.OriginalNode
, the original AST without any changes that have already happened during the translation process. This can be helpful in situations in which a child of the current node has been already translated (because of the bottom-up traverse of the tree) and it is helpful to know the original node as it was recognized by the parser.
Also, there are multiple classes that implement the IReplaceContext
interface, for example, there is a context class specific for translation rules from Teradata to Snowflake, there is another one for translating from Oracle to Snowflake, and so on for each of the supported languages. So the TContext
object can have other specific properties depending on where it is being used.
Class Members to Override
IsApplicable
This IsApplicable
overload has the same description as the one with a single argument, the only difference is the second parameter which represents the context.
Replace
This Replace
overload has the same description as the one with two arguments, the only difference is the third parameter which represents the context.
Last updated