Implemented evaluator
This code adds a new evaluation engine that can execute expressions and formulas written in a custom language. Think of it like a calculator that can handle not just math (like 1 + 2 * 3) but also work with text, lists, objects, and custom functions.
The main features include:
- Basic math operations: addition, subtraction, multiplication, division with proper order of operations
- Text manipulation: combining strings and templates with embedded expressions
-
Data structures: creating and accessing arrays
[1, 2, 3]and objects{name: "value"} - Logical operations: AND/OR logic with short-circuiting (stops evaluating when result is known)
- Comparisons: equal, not equal, greater than, less than operations
-
Function calls: ability to call custom functions like
min()orstr() -
Variable access: looking up values from a data context using dot notation like
ctx.property
The code includes comprehensive error handling that shows exactly where problems occur in the expression, and a robust test suite covering both successful evaluations and various error conditions. It also tracks "marks" on values, which appears to be a security or auditing feature to trace where data comes from.
This would typically be used in applications that need to evaluate user-defined formulas or business rules dynamically.
Edited by Cameron Swords