pip_services3_expressions 1.0.1 copy "pip_services3_expressions: ^1.0.1" to clipboard
pip_services3_expressions: ^1.0.1 copied to clipboard

This library is a part of the [Pip.Services](http://pip.services.org) polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

example/README.md

Pip.Services Logo
Tokenizers, parsers and expression calculators in Dart #

This module is a part of the Pip.Services polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

The module contains the following packages:

  • Calculator - Expression calculator
  • CSV - CSV tokenizer
  • IO - input/output utility classes to support lexical analysis
  • Mustache - Mustache templating engine
  • Tokenizers - lexical analyzers to break incoming character streams into tokens
  • Variants - dynamic objects that can hold any values and operators for them

Quick links:

Use #

Add this to your package's pubspec.yaml file:

dependencies:
  pip_services3_expressions: version

Now you can install package from the command line:

pub get

The example below shows how to use expression calculator to dynamically calculate user-defined expressions.

import 'package:pip_services3_expressions/src/calculator/calculator.dart';
import 'package:pip_services3_expressions/src/calculator/variables/variables.dart';
import 'package:pip_services3_expressions/src/variants/variants.dart';

...
var calculator = ExpressionCalculator();

calculator.expression = 'A + b / (5 - Max(-123, 1)*2)';

var vars = VariableCollection();
vars.add(Variable('A', Variant('1')));
vars.add(Variable('B', Variant(3)));

var result = await calculator.evaluateWithVariables(vars);
print('The result of the expression is ' +
    result.asString); // The result of the expression is 11
...

This is an example to process mustache templates.

import 'package:pip_services3_expressions/src/mustache/mustache.dart';

var mustache = MustacheTemplate();
mustache.template =
    'Hello, {{{NAME}}}{{#ESCLAMATION}}!{{/ESCLAMATION}}{{#unless ESCLAMATION}}.{{/unless}}';
var result =
    mustache.evaluateWithVariables({'NAME': 'Mike', 'ESCLAMATION': true});
print("The result of template evaluation is '" + result.toString() + "'");

For development you shall install the following prerequisites:

  • Dart SDK 2
  • Visual Studio Code or another IDE of your choice
  • Docker

Install dependencies:

pub get

Run automated tests:

pub run test

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./build.ps1
./test.ps1
./clear.ps1

Contacts #

The library is created and maintained by Sergey Seroukhov and Levichev Dmitry.

The documentation is written by Egor Nuzhnykh, Alexey Dvoykin, Mark Makarychev, Levichev Dmitry.

0
likes
125
points
1.99k
downloads

Publisher

unverified uploader

Weekly Downloads

This library is a part of the [Pip.Services](http://pip.services.org) polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

pip_services3_commons

More

Packages that depend on pip_services3_expressions