expressions
0.2.5+3, released a year ago by appsup.be
Parse and evaluate simple Dart and JavaScript like expressions.
What it does
Parses string expressions into an expression object and evaluates them against a provided context of variables and functions. It supports common programming language syntax but does not handle complex blocks of code or control flow statements.
AI-written summary of version 0.2.5+3, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to evaluate user-entered math or logic formulas at runtime.
- You want to parse simple JSON-like structures or dynamic property lookups.
Skip it when
- You need a full Dart interpreter supporting control flow, blocks, and statements.
- You require advanced language features like string interpolation or named parameters out of the box.
Strengths
- Lightweight parser powered by petitparser.
- Supports custom evaluators for member expressions and async execution.
Weaknesses
- Does not support full Dart language constructs, blocks, or control flow statements.
- Default evaluator cannot handle member expressions without custom implementation.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
Expression expression = Expression.parse("cos(x)*cos(x)+sin(x)*sin(x)==1");
var context = {
"x": pi / 5,
"cos": cos,
"sin": sin
};
final evaluator = const ExpressionEvaluator();
var r = evaluator.eval(expression, context);Alternatives
Packages that do the same job and could replace expressions.
- cel
Parses and evaluates Common Expression Language (CEL) expressions in Dart.
77Compare - apollovm
Portable multi-language VM to parse, run, translate, and compile Dart, Java, Kotlin, Go, C#, JS, and Python.
76Compare - json_path
Dart implementation of RFC 9535 JSONPath for querying and manipulating JSON
65Compare - math_parser
Parse and evaluate mathematical expressions in Dart.
52Compare
Works with
Packages commonly used together with expressions: ones it builds on, ones built on it, and its own family.
- petitparserexpressions depends on itBuild fast, composable, and type-safe grammars and parsers in plain Dart code.
- rxdartexpressions depends on itImplementation of the ReactiveX API for asynchronous programming leveraging native Dart Streams.
- quiverexpressions depends on itA set of utility libraries for Dart containing collections, async tools, and testing helpers.
- firebase_dartBuilt on expressionsA pure Dart implementation of Firebase Authentication, Realtime Database, and Cloud Storage.
- xpath_selectorBuilt on expressionsXPath package for HTML and XML parsing with basic XPath syntax support.
- bones_uiBuilt on expressionsAn intuitive and user-friendly Web User Interface framework for Dart.
- casbinBuilt on expressionsAn authorization library supporting access control models like ACL, RBAC, and ABAC.