expressions 0.1.4 copy "expressions: ^0.1.4" to clipboard
expressions: ^0.1.4 copied to clipboard

outdated

A library to parse and evaluate simple expressions.

expressions #

Build Status

A library to parse and evaluate simple expressions.

This library can handle simple expressions, but no operations, blocks of code, control flow statements and so on. It supports a syntax that is common to most programming languages (so no special things like string interpolation, cascade notation, named parameters).

It is partly inspired by jsep.

Usage #

Example 1: evaluate expression with default evaluator

// Parse expression:
Expression expression = Expression.parse("cos(x)*cos(x)+sin(x)*sin(x)==1");

// Create context containing all the variables and functions used in the expression
var context = {
  "x": pi / 5,
  "cos": cos,
  "sin": sin
};

// Evaluate expression
final evaluator = const ExpressionEvaluator();
var r = evaluator.eval(expression, context);


print(r); // = true

Example 2: evaluate expression with custom evaluator

// Parse expression:
Expression expression = Expression.parse("'Hello '+person.name");

// Create context containing all the variables and functions used in the expression
var context = {
  "person": new Person("Jane")
};

// The default evaluator can not handle member expressions like `person.name`.
// When you want to use these kind of expressions, you'll need to create a
// custom evaluator that implements the `evalMemberExpression` to get property
// values of an object (e.g. with `dart:mirrors` or some other strategy).
final evaluator = const MyEvaluator();
var r = evaluator.eval(expression, context);


print(r); // = 'Hello Jane'

Features and bugs #

Please file feature requests and bugs at the issue tracker.

77
likes
0
pub points
93%
popularity

Publisher

verified publisherappsup.be

A library to parse and evaluate simple expressions.

Homepage

License

unknown (LICENSE)

Dependencies

petitparser, quiver

More

Packages that depend on expressions