Evaluator class
Evaluation runtime engine
- Extends
-
AbstractParseTreeVisitor<unknown>
Constructors
Evaluator(Templates, Evaluation |
Creates a new instance of the Evaluator class. |
Properties
activity |
|
expand |
|
expression |
Expression parser. |
from |
|
is |
|
LGType | |
Re |
|
template |
|
template |
TemplateMap. |
templates | Templates. |
Methods
check |
Checks an expression result and throws the corresponding error. |
concat |
Concatenates two error messages. |
construct |
Constructs the scope for mapping the values of arguments to the parameters of the template. Throws errors if certain errors detected TemplateErrors. |
evaluate |
Evaluate 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.structuredTemplateBody. |
visit |
Visit a parse tree produced by the switchCaseBody labeled alternative in LGTemplateParser.body. |
wrapped |
Replaces an expression contained in text. |
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
Evaluator(Templates, EvaluationOptions)
Creates a new instance of the Evaluator class.
new Evaluator(templates: Templates, opt?: EvaluationOptions)
Parameters
- templates
- Templates
Templates.
Options for LG.
Property Details
activityAttachmentFunctionName
static activityAttachmentFunctionName: "ActivityAttachment" = "ActivityAttachment"
Property Value
"ActivityAttachment"
expandTextFunctionName
static expandTextFunctionName: "expandText" = "expandText"
Property Value
"expandText"
expressionParser
Expression parser.
expressionParser: ExpressionParser
Property Value
ExpressionParser
fromFileFunctionName
static fromFileFunctionName: "fromFile" = "fromFile"
Property Value
"fromFile"
isTemplateFunctionName
static isTemplateFunctionName: "isTemplate" = "isTemplate"
Property Value
"isTemplate"
LGType
static LGType: "lgType" = "lgType"
Property Value
"lgType"
ReExecuteSuffix
static ReExecuteSuffix: "!" = "!"
Property Value
"!"
templateFunctionName
static templateFunctionName: "template" = "template"
Property Value
"template"
templateMap
templates
Method Details
checkExpressionResult(string, string, unknown, string, string, string)
Checks an expression result and throws the corresponding error.
static function checkExpressionResult(exp: string, error: string, result: unknown, templateName: string, inlineContent: string, errorPrefix: string)
Parameters
- exp
-
string
Expression text.
- error
-
string
Error message.
- result
-
unknown
Result.
- templateName
-
string
Template name.
- inlineContent
-
string
Optional. In line content.
- errorPrefix
-
string
Optional. Error prefix.
concatErrorMsg(string, string)
Concatenates two error messages.
static function concatErrorMsg(firstError: string, secondError: string): string
Parameters
- firstError
-
string
First error message to concatenate.
- secondError
-
string
Second error message to concatenate.
Returns
string
The concatenated error messages.
constructScope(string, unknown[], Template[])
Constructs the scope for mapping the values of arguments to the parameters of the template. Throws errors if certain errors detected TemplateErrors.
function constructScope(inputTemplateName: string, args: unknown[], allTemplates: Template[]): MemoryInterface
Parameters
- inputTemplateName
-
string
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.
evaluateTemplate(string, unknown)
Evaluate a template with given name and scope.
function evaluateTemplate(inputTemplateName: string, scope: unknown): unknown
Parameters
- inputTemplateName
-
string
Template name.
- scope
-
unknown
Scope.
Returns
unknown
Evaluate result.
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 visitor result.
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 string result of visiting the normal template string.
visitStructuredTemplateBody(StructuredTemplateBodyContext)
Visit a parse tree produced by LGTemplateParser.structuredTemplateBody.
function visitStructuredTemplateBody(ctx: StructuredTemplateBodyContext): unknown
Parameters
The parse tree.
Returns
unknown
The result of visiting the structured template 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 string result of visiting the switch case body.
wrappedEvalTextContainsExpression(string, RegExp)
Replaces an expression contained in text.
function wrappedEvalTextContainsExpression(exp: string, regex: RegExp): string
Parameters
- exp
-
string
Expression Text.
- regex
-
RegExp
Regex to select the text to replace.
Returns
string
Text with expression replaced.
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