Update to 0.4.0

- Context handling
- evalexpr 10.0.0

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-05-31 10:27:23 +03:00
parent 96e88f02fa
commit 053e938d32
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D
6 changed files with 62 additions and 60 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
Cargo.lock

10
.rustfmt.toml Normal file
View file

@ -0,0 +1,10 @@
edition = "2021"
hard_tabs = true
merge_derives = true
reorder_imports = true
reorder_modules = true
use_field_init_shorthand = true
use_small_heuristics = "Off"
wrap_comments = true
comment_width = 80
indent_style = "Block"

16
Cargo.lock generated
View file

@ -1,16 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "evalexpr"
version = "8.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aacfb566035f8cd02f6ec9247c242f3f9904a0b288ea383abcf4e95df6436a34"
[[package]]
name = "feval"
version = "0.3.0"
dependencies = [
"evalexpr",
]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "feval" name = "feval"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
description = "clt for fast evaluations" description = "clt for fast evaluations"
readme = "README.md" readme = "README.md"
@ -9,4 +9,4 @@ license = "MIT"
authors = ["Ivan ivabus Bushchik"] authors = ["Ivan ivabus Bushchik"]
[dependencies] [dependencies]
evalexpr = "8.1.0" evalexpr = "10.0.0"

View file

@ -1,26 +1,33 @@
use std::{env::args, io::{stdin, stdout, Write}}; use std::{
env::args,
io::{stdin, stdout, Write},
};
use evalexpr; use evalexpr;
use evalexpr::HashMapContext;
use crate::tasks::tasks::all; use crate::tasks::tasks::all;
mod tasks; mod tasks;
fn help() { fn help() {
println!(r#"feval: help println!(
r#"feval: help
usage: provide exactly one argument (with expression) or no arguments for shell mode. usage: provide exactly one argument (with expression) or no arguments for shell mode.
example: feval "math::sin(30 * math::pi / 180)""#); example: feval "math::sin(30 * math::pi / 180)""#
);
} }
fn main_loop() { fn main_loop() {
print!(">>> "); print!(">>> ");
stdout().flush().unwrap(); stdout().flush().unwrap();
let mut input = String::new(); let mut input = String::new();
let mut context = HashMapContext::new();
while stdin().read_line(&mut input).unwrap() != 0 { while stdin().read_line(&mut input).unwrap() != 0 {
let result = evalexpr::eval(&all(input.trim().to_string())); let result = evalexpr::eval_with_context_mut(&all(input.trim().to_string()), &mut context);
match result { match result {
Ok(succ_res) => println!("{}", succ_res), Ok(succ_res) => println!("{}", succ_res),
Err(err) => println!("Error: {}", err) Err(err) => println!("Error: {}", err),
} }
input.clear(); input.clear();
print!(">>> "); print!(">>> ");
@ -41,8 +48,8 @@ fn main() {
std::process::exit(127); std::process::exit(127);
} }
} }
}, }
1 => {main_loop()}, 1 => main_loop(),
_ => { _ => {
if args.len() > 2 { if args.len() > 2 {
println!("Too many args."); println!("Too many args.");