expr-lang

Crates.ioexpr-lang
lib.rsexpr-lang
version
sourcesrc
created_at2024-11-24 22:21:08.373611
updated_at2024-11-29 22:16:43.174276
descriptionImplementation of expr language in Rust
homepagehttps://github.com/jdx/expr-lang
repositoryhttps://github.com/jdx/expr-lang
max_upload_size
id1459663
Cargo.toml error:TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(jdx)

documentation

https://docs.rs/expr-lang

README

expr-lang

Implementation of expr in rust.

Usage

use expr::{Context, Parser};

fn main() {
    let mut p = Parser::new();

    let mut ctx = Context::default();
    ctx.insert("two".to_string(), 2);

    let three: i64 = p.eval("1 + two", &ctx).unwrap().as_number().unwrap();
    assert_eq!(three, 3);

    p.add_function("add", |c| {
        let mut sum = 0;
        for arg in c.args {
            sum += arg.as_number().unwrap();
        }
        Ok(sum.into())
    });

    let six: i64 = p.eval("add(1, two, 3)", &ctx).unwrap().as_number().unwrap();
    assert_eq!(six, 6);
}
Commit count: 32

cargo fmt