Expander class
LG template expander.
- Extends
-
AbstractParseTreeVisitor<unknown[]>
Constructors
Expander(Templates, Evaluation |
Creates a new instance of the Expander class. |
Properties
template |
TemplateMap. |
templates | Templates. |
Methods
construct |
Constructs the scope for mapping the values of arguments to the parameters of the template. |
expand |
Expand the results of a template with given name and scope. |
visit |
Visit a parse tree produced by the ifElseBody labeled alternative in LGTemplateParser.body. |
visit |
Visit a parse tree produced by the normalBody labeled alternative in LGTemplateParser.body. |
visit |
Visit a parse tree produced by LGTemplateParser.normalTemplateBody. |
visit |
Visit a parse tree produced by LGTemplateParser.normalTemplateString. |
visit |
Visit a parse tree produced by LGTemplateParser.structuredBody. |
visit |
Visit a parse tree produced by the switchCaseBody labeled alternative in LGTemplateParser.body. |
Inherited Methods
visit(Parse |
{@inheritDoc} The default implementation calls <xref:ParseTree%23accept> on the specified tree. |
visit |
{@inheritDoc}
The default implementation initializes the aggregate result to
defaultResult(). Before visiting each child, it
calls shouldVisitNextChild; if the result
is The default implementation is not safe for use in visitors that modify the tree structure. Visitors that modify the tree should override this method to behave properly in respect to the specific algorithm in use. |
visit |
{@inheritDoc} The default implementation returns the result of defaultResult. |
visit |
{@inheritDoc} The default implementation returns the result of defaultResult. |
Constructor Details
Expander(Templates, EvaluationOptions)
Creates a new instance of the Expander class.
new Expander(templates: Templates, opt?: EvaluationOptions)
Parameters
- templates
- Templates
Template list.
Options for LG.
Property Details
templateMap
templates
Method Details
constructScope(string, unknown[], Template[])
Constructs the scope for mapping the values of arguments to the parameters of the template.
function constructScope(inputTemplateName: string, args: unknown[], allTemplates: Template[]): MemoryInterface
Parameters
- inputTemplateName
-
string
The template name to evaluate.
- args
-
unknown[]
Arguments to map to the template parameters.
- allTemplates
-
Template[]
All templates.
Returns
MemoryInterface
The current scope if the number of arguments is 0, otherwise, returns a CustomizedMemory. with the mapping of the parameter name to the argument value added to the scope.
expandTemplate(string, unknown)
Expand the results of a template with given name and scope.
function expandTemplate(templateName: string, scope: unknown): unknown[]
Parameters
- templateName
-
string
Given template name.
- scope
-
unknown
Given scope.
Returns
unknown[]
All possiable results.
visitIfElseBody(IfElseBodyContext)
Visit a parse tree produced by the ifElseBody labeled alternative in LGTemplateParser.body.
function visitIfElseBody(ctx: IfElseBodyContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting if-else body.
visitNormalBody(NormalBodyContext)
Visit a parse tree produced by the normalBody labeled alternative in LGTemplateParser.body.
function visitNormalBody(ctx: NormalBodyContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting the normal body.
visitNormalTemplateBody(NormalTemplateBodyContext)
Visit a parse tree produced by LGTemplateParser.normalTemplateBody.
function visitNormalTemplateBody(ctx: NormalTemplateBodyContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting the normal template body.
visitNormalTemplateString(NormalTemplateStringContext)
Visit a parse tree produced by LGTemplateParser.normalTemplateString.
function visitNormalTemplateString(ctx: NormalTemplateStringContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting NormalTemplateString.
visitStructuredBody(StructuredBodyContext)
Visit a parse tree produced by LGTemplateParser.structuredBody.
function visitStructuredBody(ctx: StructuredBodyContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting the structured body.
visitSwitchCaseBody(SwitchCaseBodyContext)
Visit a parse tree produced by the switchCaseBody labeled alternative in LGTemplateParser.body.
function visitSwitchCaseBody(ctx: SwitchCaseBodyContext): unknown[]
Parameters
The parse tree.
Returns
unknown[]
The result of visiting the switch case body.
Inherited Method Details
visit(ParseTree)
{@inheritDoc} The default implementation calls <xref:ParseTree%23accept> on the specified tree.
function visit(tree: ParseTree): unknown[]
Parameters
- tree
-
ParseTree
Returns
unknown[]
Inherited From AbstractParseTreeVisitor.visit
visitChildren(RuleNode)
{@inheritDoc}
The default implementation initializes the aggregate result to
defaultResult(). Before visiting each child, it
calls shouldVisitNextChild; if the result
is false
no more children are visited and the current aggregate
result is returned. After visiting a child, the aggregate result is
updated by calling aggregateResult with the
previous aggregate result and the result of visiting the child.
The default implementation is not safe for use in visitors that modify the tree structure. Visitors that modify the tree should override this method to behave properly in respect to the specific algorithm in use.
function visitChildren(node: RuleNode): unknown[]
Parameters
- node
-
RuleNode
Returns
unknown[]
Inherited From AbstractParseTreeVisitor.visitChildren
visitErrorNode(ErrorNode)
{@inheritDoc} The default implementation returns the result of defaultResult.
function visitErrorNode(node: ErrorNode): unknown[]
Parameters
- node
-
ErrorNode
Returns
unknown[]
Inherited From AbstractParseTreeVisitor.visitErrorNode
visitTerminal(TerminalNode)
{@inheritDoc} The default implementation returns the result of defaultResult.
function visitTerminal(node: TerminalNode): unknown[]
Parameters
- node
-
TerminalNode
Returns
unknown[]
Inherited From AbstractParseTreeVisitor.visitTerminal