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,56 +1,63 @@
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();
while stdin().read_line(&mut input).unwrap() != 0 { let mut context = HashMapContext::new();
let result = evalexpr::eval(&all(input.trim().to_string())); while stdin().read_line(&mut input).unwrap() != 0 {
match result { let result = evalexpr::eval_with_context_mut(&all(input.trim().to_string()), &mut context);
Ok(succ_res) => println!("{}", succ_res), match result {
Err(err) => println!("Error: {}", err) Ok(succ_res) => println!("{}", succ_res),
} Err(err) => println!("Error: {}", err),
input.clear(); }
print!(">>> "); input.clear();
stdout().flush().unwrap(); print!(">>> ");
} stdout().flush().unwrap();
}
} }
fn main() { fn main() {
let args: Vec<String> = args().collect(); let args: Vec<String> = args().collect();
match args.len() { match args.len() {
2 => { 2 => {
let expr = all(args[1].clone()); let expr = all(args[1].clone());
let result = evalexpr::eval(&expr.trim()); let result = evalexpr::eval(&expr.trim());
match result { match result {
Ok(succ_res) => println!("{}", succ_res), Ok(succ_res) => println!("{}", succ_res),
Err(err) => { Err(err) => {
println!("Error: {}", err); println!("Error: {}", err);
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.");
help(); help();
} else if args.len() < 1 { } else if args.len() < 1 {
println!("Too few args."); println!("Too few args.");
help(); help();
} }
} }
} }
} }

View file

@ -1,5 +1,5 @@
pub mod tasks { pub mod tasks {
use std::f64::consts; use std::f64::consts;
pub fn all(expr: String) -> String { pub fn all(expr: String) -> String {
convert_constants(exit(expr)) convert_constants(exit(expr))
@ -13,4 +13,4 @@ pub mod tasks {
} }
expr expr
} }
} }