Skip to main content

Crate yash_arith

Crate yash_arith 

Source
Expand description

This crate implements shell arithmetic expansion.

Arithmetic expansion evaluates an expression that may contain some operators that perform basic maths. The expression is given as a string and parsed like an expression in C. The expression can include variables that interact with the environment.

To evaluate an expression, you call the eval() function with a string and an environment.

use std::collections::HashMap;
use yash_arith::{eval, Value};
let mut env = HashMap::new();
env.insert("a".to_owned(), "2".to_owned());
let result = eval("1 + a", &mut env);
assert_eq!(result, Ok(Value::Integer(3)));

Structs§

Config
Configuration for arithmetic expansion
Error
Description of an error that occurred during expansion

Enums§

ErrorCause
Cause of an arithmetic expansion error
EvalError
Cause of an evaluation error
PortabilityError
Cause of an error because an expression contains a non-portable construct
SyntaxError
Cause of a syntax error
TokenError
Cause of a tokenization error
Value
Result of evaluating an expression

Traits§

Env
Interface for accessing variables during evaluation

Functions§

eval
Performs arithmetic expansion
eval_with_config
Performs arithmetic expansion with the specified configuration.