Clause class
A canonical normal form expression.
- Extends
Constructors
Clause(Clause | Expression | Expression[]) | Initializes a new instance of the |
Properties
any |
Gets or sets the anyBinding dictionary. |
return |
Expected result of evaluating the expression. |
subsumed | Gets or sets whether the clause is subsumed. |
type | Type of expression. |
Inherited 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. |
Methods
matches(Clause, Memory |
Determines whether the current |
relationship(Clause, Predicate |
Compares the current |
split |
Splits ignored child expressions. |
to |
Gets a string that represents the current clause. |
Inherited 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. |
try |
Evaluate the expression. |
validate() | Validate immediate expression. |
validate |
Recursively validate the expression tree. |
Constructor Details
Clause(Clause | Expression | Expression[])
Initializes a new instance of the Clause
class.
new Clause(clauseOrExpression?: Clause | Expression | Expression[])
Parameters
- clauseOrExpression
-
Clause | Expression | Expression[]
A clause, expression or an array of expressions to initialize a Clause
.
Property Details
anyBindings
Gets or sets the anyBinding dictionary.
anyBindings: Map<string, string> = new Map<string, string>()
Property Value
Map<string, string>
returnType
Expected result of evaluating the expression.
ReturnType returnType
Property Value
The expected result of evaluating the expression.
subsumed
Gets or sets whether the clause is subsumed.
subsumed: boolean = false
Property Value
boolean
type
Type of expression.
string type
Property Value
string
The type of the expression.
Inherited Property Details
children
evaluator
Evaluator of expression.
evaluator: ExpressionEvaluator
Property Value
Inherited From Expression.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
Inherited From Expression.functions
Method Details
matches(Clause, MemoryInterface | any)
Determines whether the current Clause
matches with another Clause
.
function matches(clause: Clause, memory: MemoryInterface | any): boolean
Parameters
- clause
- Clause
The other Clause
instance to compare with.
- memory
-
MemoryInterface | any
The scope for looking up variables.
Returns
boolean
A boolean value indicating whether the two clauses are matches.
relationship(Clause, PredicateComparers)
Compares the current Clause
with another Clause
.
function relationship(other: Clause, comparers: PredicateComparers): RelationshipType
Parameters
- other
- Clause
The other Clause
to compare.
- comparers
- PredicateComparers
A comparer, which is a dictionary of PredicateComparer
with string keys.
Returns
A RelationshipType
value between two Clause
instances.
splitIgnores()
Splits ignored child expressions.
function splitIgnores()
toString(string[], number)
Gets a string that represents the current clause.
function toString(builder: string[], indent: number): string
Parameters
- builder
-
string[]
An array of string to build the string of clause.
- indent
-
number
An integer represents the number of spaces at the start of a line.
Returns
string
A string that represents the current clause.
Inherited Method Details
andExpression(Expression[])
Construct and validate an And expression.
static function andExpression(children: Expression[]): Expression
Parameters
- children
Child clauses.
Returns
New expression.
Inherited From Expression.andExpression
deepEquals(Expression)
Do a deep equality between expressions.
function deepEquals(other: Expression): boolean
Parameters
- other
- Expression
Other expression.
Returns
boolean
True if expressions are the same.
Inherited From Expression.deepEquals
equalsExpression(Expression[])
Construct and validate an Equals expression.
static function equalsExpression(children: Expression[]): Expression
Parameters
- children
Child clauses.
Returns
New expression.
Inherited From Expression.equalsExpression
lambaExpression(EvaluateExpressionDelegate)
Construct an expression from a EvaluateExpressionDelegate
static function lambaExpression(func: EvaluateExpressionDelegate): Expression
Parameters
Function to create an expression from.
Returns
The new expression.
Inherited From Expression.lambaExpression
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): Expression
Parameters
- func
-
(arg0: any) => any
ambda expression to evaluate.
Returns
New expression.
Inherited From Expression.lambda
lookup(string)
Lookup an ExpressionEvaluator function by name.
static function lookup(functionName: string): ExpressionEvaluator
Parameters
- functionName
-
string
Name of function to lookup.
Returns
An ExpressionEvaluator corresponding to the function name.
Inherited From Expression.lookup
makeExpression(string, ExpressionEvaluator, Expression[])
Make an expression and validate it.
static function makeExpression(type: string, evaluator: ExpressionEvaluator, children: Expression[]): Expression
Parameters
- type
-
string
Type of expression from ExpressionType.
- evaluator
- ExpressionEvaluator
Information about how to validate and evaluate expression.
- children
Child expressions.
Returns
The new expression.
Inherited From Expression.makeExpression
notExpression(Expression)
Construct and validate an Not expression.
static function notExpression(child: Expression): Expression
Parameters
- child
- Expression
Child clauses.
Returns
New expression.
Inherited From Expression.notExpression
orExpression(Expression[])
Construct and validate an Or expression.
static function orExpression(children: Expression[]): Expression
Parameters
- children
Child clauses.
Returns
New expression.
Inherited From Expression.orExpression
parse(string, EvaluatorLookup)
Parse an expression string into an Expression object.
static function parse(expression: string, lookup?: EvaluatorLookup): Expression
Parameters
- 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.
Inherited From Expression.parse
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.
Inherited From Expression.references
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.
Inherited From Expression.referenceWalk
setPathToValue(Expression, any)
Construct and validate an Set a property expression to a value expression.
static function setPathToValue(property: Expression, value: any): Expression
Parameters
- property
- Expression
property expression.
- value
-
any
value expression.
Returns
New expression.
Inherited From Expression.setPathToValue
tryEvaluate(MemoryInterface | any, Options)
Evaluate the expression.
function tryEvaluate(state: MemoryInterface | any, options: Options): ValueWithError
Parameters
- 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.
Inherited From Expression.tryEvaluate
validate()
validateTree()
Recursively validate the expression tree.
function validateTree()
Inherited From Expression.validateTree