tp_expressions version: 0.2.13

Published 2023-05-22

n/a

sdk | dart
repository | svn
platform | n/a
status | n/a
  • Readme
  • Changelog
  • Versions

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.

Changelog

0.2.13 - 2023-05-22

Changed

  • Version bump from 0.2.12 to 0.2.13.

0.2.12 - 2023-02-09

Changed

  • Version bump from 0.2.11 to 0.2.12 (Version confusion after compiler bug chaos).

0.2.11 - 2023-01-31

Changed

  • Version bump from 0.2.10 to 0.2.11.

0.2.10 - 2023-01-31

Changed

  • Version bump from 0.2.9 to 0.2.10.

0.2.9 - 2022-12-22

Changed

  • Version bump from 0.2.8 to 0.2.9.

0.2.8 - 2022-12-22

Changed

  • Version bump from 0.2.7 to 0.2.8 (Recompile due to installer optimizations).

0.2.7 - 2022-10-11

Changed

  • Version bump from 0.2.6 to 0.2.7 (Recompile due to wrong GetIt.instance syntax.).

0.2.6 - 2022-10-05

Changed

  • Version bump from 0.2.5 to 0.2.6 (fixed pdflib searchpath macos crash).

0.2.5 - 2022-10-01

Changed

  • Version bump from 0.2.4 to 0.2.5 (pkg_pdflib bundle macos dylib).

0.2.4 - 2022-09-29

Changed

  • Version bump from 0.2.3+1 to 0.2.4 (dependencies upgraded).

0.2.3+1 - 2022-01-01

Changed

  • upgrade petitparser to 5.0.0

0.2.3 - 2022-01-01

Changed

  • upgrade rxdart dependency to 0.27.0

0.2.2 - 2022-01-01

Changed

  • ExpressionEvaluator.async now also handles futures
  • Support petitparser 4.1.0

0.2.1 - 2022-01-01

Changed

  • add memberAccessors argument to ExpressionEvaluator that defines how to handle member expressions
  • add ExpressionEvaluator.async constructor to create an async expression evaluator that applies expressions to the values of streams

0.2.0 - 2022-01-01

Changed

  • null-safety

0.1.5 - 2022-01-01

Changed

  • add Expression.tryParse method

0.1.4 - 2022-01-01

Changed

  • fix parsing empty array or argument list
  • parse map expressions

0.1.3 - 2022-01-01

Changed

  • petitparser 3 compatibility

0.1.2 - 2022-01-01

Changed

  • Support Dart 2 in pubspec.yaml
  • Use the petitparser version 2 package with fully typed parsers instead of the typedparser package

0.1.1 - 2022-01-01

Changed

  • Dart 2 strong mode fixes
  • Evaluate right expression in a binary expression only when necessary

0.1.0 - 2022-01-01

Changed

  • Initial version

0.2.13

2023-05-22 download

0.2.12

2023-02-09 download

0.2.11

2023-01-31 download

0.2.9

2022-12-22 download

0.2.8

2022-12-22 download

0.2.7

2022-10-11 download

0.2.6

2022-10-05 download

0.2.5

2022-10-01 download

0.2.4

2022-09-29 download

0.2.3+1

2022-01-01 download