Expression class
An expression which can be analyzed or evaluated to produce a value. This provides an open-ended wrapper that supports a number of built-in functions and can also be extended at runtime. It also supports validation of the correctness of an expression and evaluation that should be exception free.
Constructors
| Expression(string, Expression | expression constructor. | 
Properties
| children | Children expressions. | 
| evaluator | Evaluator of expression. | 
| functions | Dictionary of function => ExpressionEvaluator. This is all available functions, you can add custom functions to it, but you cannot replace builtin functions. If you clear the dictionary, it will be reset to the built in functions. | 
| return | Expected result of evaluating the expression. | 
| type | Type of expression. | 
Methods
| and | Construct and validate an And expression. | 
| deep | Do a deep equality between expressions. | 
| equals | Construct and validate an Equals expression. | 
| lamba | Construct an expression from a EvaluateExpressionDelegate | 
| lambda((arg0: any) => any) | Construct an expression from a lamba expression over the state. Exceptions will be caught and surfaced as an error string. | 
| lookup(string) | Lookup an ExpressionEvaluator function by name. | 
| make | Make an expression and validate it. | 
| not | Construct and validate an Not expression. | 
| or | Construct and validate an Or expression. | 
| parse(string, Evaluator | Parse an expression string into an Expression object. | 
| references() | Return the static reference paths to memory. Return all static paths to memory. If there is a computed element index, then the path is terminated there, but you might get other paths from the computed part as well. | 
| reference | Walking function for identifying static memory references in an expression. | 
| set | Construct and validate an Set a property expression to a value expression. | 
| to | Returns a string that represents the current Expression object. | 
| try | Evaluate the expression. | 
| validate() | Validate immediate expression. | 
| validate | Recursively validate the expression tree. | 
Constructor Details
		Expression(string, ExpressionEvaluator, Expression[])
	 
	expression constructor.
new Expression(type: string, evaluator: ExpressionEvaluator, children: Expression[])Parameters
- type
- 
				string 
Type of expression from ExpressionType
- evaluator
- ExpressionEvaluator
Information about how to validate and evaluate expression.
- children
Child expressions.
Property Details
children
evaluator
functions
Dictionary of function => ExpressionEvaluator. This is all available functions, you can add custom functions to it, but you cannot replace builtin functions. If you clear the dictionary, it will be reset to the built in functions.
static functions: FunctionTable = new FunctionTable()Property Value
		returnType
	 
	Expected result of evaluating the expression.
ReturnType returnTypeProperty Value
The expected result of evaluating the expression.
type
Type of expression.
string typeProperty Value
string
The type of the expression.
Method Details
		andExpression(Expression[])
	 
	Construct and validate an And expression.
static function andExpression(children: Expression[]): ExpressionParameters
- children
Child clauses.
Returns
New expression.
		deepEquals(Expression)
	 
	Do a deep equality between expressions.
function deepEquals(other: Expression): booleanParameters
- other
- Expression
Other expression.
Returns
boolean
True if expressions are the same.
		equalsExpression(Expression[])
	 
	Construct and validate an Equals expression.
static function equalsExpression(children: Expression[]): ExpressionParameters
- children
Child clauses.
Returns
New expression.
		lambaExpression(EvaluateExpressionDelegate)
	   
	Construct an expression from a EvaluateExpressionDelegate
static function lambaExpression(func: EvaluateExpressionDelegate): ExpressionParameters
Function to create an expression from.
Returns
The new expression.
lambda((arg0: any) => any)
Construct an expression from a lamba expression over the state. Exceptions will be caught and surfaced as an error string.
static function lambda(func: (arg0: any) => any): ExpressionParameters
- func
- 
				(arg0: any) => any 
ambda expression to evaluate.
Returns
New expression.
lookup(string)
Lookup an ExpressionEvaluator function by name.
static function lookup(functionName: string): ExpressionEvaluatorParameters
- functionName
- 
				string 
Name of function to lookup.
Returns
An ExpressionEvaluator corresponding to the function name.
		makeExpression(string, ExpressionEvaluator, Expression[])
	  
	Make an expression and validate it.
static function makeExpression(type: string, evaluator: ExpressionEvaluator, children: Expression[]): ExpressionParameters
- type
- 
				string 
Type of expression from ExpressionType.
- evaluator
- ExpressionEvaluator
Information about how to validate and evaluate expression.
- children
Child expressions.
Returns
The new expression.
		notExpression(Expression)
	 
	Construct and validate an Not expression.
static function notExpression(child: Expression): ExpressionParameters
- child
- Expression
Child clauses.
Returns
New expression.
		orExpression(Expression[])
	 
	Construct and validate an Or expression.
static function orExpression(children: Expression[]): ExpressionParameters
- children
Child clauses.
Returns
New expression.
		parse(string, EvaluatorLookup)
	 
	Parse an expression string into an Expression object.
static function parse(expression: string, lookup?: EvaluatorLookup): ExpressionParameters
- expression
- 
				string 
Expression string.
- lookup
- EvaluatorLookup
Optional. EvaluatorLookup function lookup when parsing the expression. Default is Expression.lookup which uses Expression.functions table.
Returns
The expression object.
references()
Return the static reference paths to memory. Return all static paths to memory. If there is a computed element index, then the path is terminated there, but you might get other paths from the computed part as well.
function references(): string[]Returns
string[]
List of the static reference paths.
		referenceWalk(Expression, (arg0: Expression) => boolean)
	 
	Walking function for identifying static memory references in an expression.
function referenceWalk(expression: Expression, extension?: (arg0: Expression) => boolean): { path: string, refs: Set<string> }Parameters
- expression
- Expression
Expression to analyze.
- extension
- 
				(arg0: Expression) => boolean 
If present, called to override lookup for things like template expansion.
Returns
{ path: string, refs: Set<string> }
Accessor path of expression.
		setPathToValue(Expression, any)
	  
	Construct and validate an Set a property expression to a value expression.
static function setPathToValue(property: Expression, value: any): ExpressionParameters
- property
- Expression
property expression.
- value
- 
				any 
value expression.
Returns
New expression.
		toString()
	 
	Returns a string that represents the current Expression object.
function toString(): stringReturns
string
A string that represents the current Expression object.
		tryEvaluate(MemoryInterface | any, Options)
	  
	Evaluate the expression.
function tryEvaluate(state: MemoryInterface | any, options: Options): ValueWithErrorParameters
- state
- 
				MemoryInterface | any 
Global state to evaluate accessor expressions against. Can be Dictionary, otherwise reflection is used to access property and then indexer.
- options
- Options
Options used in the evaluation.
Returns
Computed value and an error string. If the string is non-null, then there was an evaluation error.
validate()
Validate immediate expression.
function validate()
		validateTree()
	 
	Recursively validate the expression tree.
function validateTree()