The project of anpai(namely 安排 in Chinese) is a suite of BPMN and DMN spec implementations in rust language.
The interpreter of the FEEL language(Friendly Enough Expression Language) in rust, FEEL is broadly used in DMN and BPMN to provide rule engine and script support, the FEEL module can be included into other rust projects or used as command line executable as FEEL interpreter.
- run
npm ci --prefix web/dmn-viewer && npm run build --prefix web/dmn-viewerto build the bundled DMN viewer assets - run
cargo buildto build the feel interpreter andanpaiCLI - run
cargo testto run testing
% ./target/debug/anpai feel -c '"hello " + "world"'
"hello world"
% ./target/debug/anpai feel -c '(function(a, b) a + b)(5, 8)'
13
% ./target/debug/anpai feel -c '>8,<4' --vars '{"?": 6}' --top unary-tests
false
# dump AST tree instead of evaluating the script
% ./target/debug/anpai feel -c 'if a > 3 then "larger" else "smaller"' --vars '{a: 5}' --ast
(if (> a 3) "larger" "smaller")
% ./target/debug/anpai feel -c 'some x in [3, 4, 8, 9] satisfies x % 2 = 0'
4
% ./target/debug/anpai feel -c 'every x in [3, 4, 8, 9] satisfies x % 2 = 0'
[4, 8]# evaluate dmn files, given context vars
% ./target/debug/anpai dmn eval examples/dmn/simpledish.dmn --vars '{season: "Summer", guestCount: 10, guestsWithChildren: true}'
{"Beverages":"Apple Juice"}DMN documents can also be parsed and evaluated entirely in memory:
use dmn::{eval_diagram, parse_string, Context, DmnError, Value};
fn evaluate(xml: &str) -> Result<Value, DmnError> {
let diagram = parse_string(xml)?;
let mut context = Context::new();
context.insert("season".to_owned(), Value::StrV("Summer".to_owned()));
eval_diagram(&diagram, context)
}Build the viewer assets, then start a local Axum server for a DMN diagram:
% npm ci --prefix web/dmn-viewer
% npm run build --prefix web/dmn-viewer
% ./target/debug/anpai dmn view crates/dmn/src/fixtures/dmn/simpledish.dmn
DMN viewer for "crates/dmn/src/fixtures/dmn/simpledish.dmn": http://127.0.0.1:6100/Open the printed URL in a browser. The viewer is read-only and serves only the selected DMN document and its bundled dmn-js assets. Press Ctrl-C to stop the server.
for more examples please refer to testing