-
Notifications
You must be signed in to change notification settings - Fork 26
Home
Shaun Lawrence edited this page Aug 27, 2019
·
3 revisions
Expressive is a cross-platform expression parsing and evaluation framework. The cross-platform nature is achieved through compiling for .NET Standard
so it will run on practically any platform.
There are 3 main stages of the parsing/evaluation of an Expression.
- Tokenising - this deals with walking through the characters in the expression and matching the items against the known set of
Operators
,Functions
andValues
. - Compiling - once the
Expression
has been tokenised the set of tokens is then used to build a tree of internalIExpression
nodes. - Evaluation - each individual
IExpression
node is then evaluated to determine it's result and eventually the overall result of the top levelExpression
.
The Expression
will terminate early in the following situations:
- Any part of the tokenising process fails (i.e. unrecognised tokens).
- If any of the
Function
s are supplied with an incorrect number of parameters.
Operators can now handle aggregates (i.e. a variable passed in as an array of values will each be enumerated).
var expression = new Expression("[array] + 2");
var result = expression.Evaluate(new Dictionary<string, object> { ["variable"] = new [] { 2, 3, 4, 5});
// result == 16
Each individual parameter
will only be evaluated at the point of being used within its IExpression
node. This will prevent parts of an expression being evaluated should the result already be determined (e.g. when the left hand side of an && (logical AND) operator being false
).
- AddDays
- AddHours
- AddMilliseconds
- AddMinutes
- AddMonths
- AddSeconds
- AddYears
- DayOf
- HourOf
- MillisecondOf
- MinuteOf
- MonthOf
- SecondOf
- YearOf
- DaysBetween
- HoursBetween
- MillisecondsBetween
- MinutesBetween
- SecondsBetween