pyisheval

Crates.iopyisheval
lib.rspyisheval
version
sourcesrc
created_at2024-12-12 15:48:28.321489
updated_at2024-12-12 16:37:56.319018
descriptionA Python-like expression evaluator in Rust
homepage
repositoryhttps://github.com/neka-nat/pyisheval
max_upload_size
id1481369
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | 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
Shirokuma (k tanaka) (neka-nat)

documentation

README

pyisheval

pyisheval is a Rust library that allows you to evaluate Python-like expressions.
It's not a full Python interpreter, but it supports a subset of Python-like syntax:

  • Arithmetic operations: +, -, *, /, %, **
  • Variables and assignments
  • Lambda expressions (lambda x: x + 1)
  • Built-in functions: abs, max, min, int, float
  • List and dictionary literals

No classes, functions (def), or control structures are supported.

Installation

cargo add pyisheval

Example

use pyisheval::Interpreter;

fn main() {
    let mut interp = Interpreter::new();

    // Assign variables
    interp.eval("x = 10").unwrap();
    interp.eval("y = 20").unwrap();

    // Arithmetic
    let val = interp.eval("x + y * 2").unwrap();
    println!("{}", val); // 50

    // Lambda
    interp.eval("inc = lambda a: a + 1").unwrap();
    let val = interp.eval("inc(x)").unwrap();
    println!("{}", val); // 11
}

Why

This library aims to provide a lightweight and embedded Python-like expression evaluator for scenarios where you want to let users provide arithmetic expressions or simple lambdas without embedding a full Python interpreter.

Commit count: 14

cargo fmt