Expander class

LG template expander.

Extends

AbstractParseTreeVisitor<unknown[]>

Constructors

Expander(Templates, EvaluationOptions)

Creates a new instance of the Expander class.

Properties

templateMap

TemplateMap.

templates

Templates.

Methods

constructScope(string, unknown[], Template[])

Constructs the scope for mapping the values of arguments to the parameters of the template.

expandTemplate(string, unknown)

Expand the results of a template with given name and scope.

visitIfElseBody(IfElseBodyContext)

Visit a parse tree produced by the ifElseBody labeled alternative in LGTemplateParser.body.

visitNormalBody(NormalBodyContext)

Visit a parse tree produced by the normalBody labeled alternative in LGTemplateParser.body.

visitNormalTemplateBody(NormalTemplateBodyContext)

Visit a parse tree produced by LGTemplateParser.normalTemplateBody.

visitNormalTemplateString(NormalTemplateStringContext)

Visit a parse tree produced by LGTemplateParser.normalTemplateString.

visitStructuredBody(StructuredBodyContext)

Visit a parse tree produced by LGTemplateParser.structuredBody.

visitSwitchCaseBody(SwitchCaseBodyContext)

Visit a parse tree produced by the switchCaseBody labeled alternative in LGTemplateParser.body.

Inherited Methods

visit(ParseTree)

{@inheritDoc} The default implementation calls <xref:ParseTree%23accept> on the specified tree.

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.

visitErrorNode(ErrorNode)

{@inheritDoc} The default implementation returns the result of defaultResult.

visitTerminal(TerminalNode)

{@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.

opt
EvaluationOptions

Options for LG.

Property Details

templateMap

TemplateMap.

templateMap: [key: string]: Template

Property Value

[key: string]: Template

templates

Templates.

templates: Templates

Property Value

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

ctx
IfElseBodyContext

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

ctx
NormalBodyContext

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

ctx
NormalTemplateBodyContext

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

ctx
NormalTemplateStringContext

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

ctx
StructuredBodyContext

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

ctx
SwitchCaseBodyContext

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