mirror of
https://github.com/ivabus/feval
synced 2024-12-04 20:55:06 +03:00
Update to 0.4.0
- Context handling - evalexpr 10.0.0 Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
96e88f02fa
commit
053e938d32
6 changed files with 62 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
10
.rustfmt.toml
Normal file
10
.rustfmt.toml
Normal 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
16
Cargo.lock
generated
|
@ -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",
|
||||
]
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "feval"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
description = "clt for fast evaluations"
|
||||
readme = "README.md"
|
||||
|
@ -9,4 +9,4 @@ license = "MIT"
|
|||
authors = ["Ivan ivabus Bushchik"]
|
||||
|
||||
[dependencies]
|
||||
evalexpr = "8.1.0"
|
||||
evalexpr = "10.0.0"
|
||||
|
|
87
src/main.rs
87
src/main.rs
|
@ -1,56 +1,63 @@
|
|||
use std::{env::args, io::{stdin, stdout, Write}};
|
||||
use std::{
|
||||
env::args,
|
||||
io::{stdin, stdout, Write},
|
||||
};
|
||||
|
||||
use evalexpr;
|
||||
use evalexpr::HashMapContext;
|
||||
|
||||
use crate::tasks::tasks::all;
|
||||
|
||||
mod tasks;
|
||||
|
||||
fn help() {
|
||||
println!(r#"feval: help
|
||||
println!(
|
||||
r#"feval: help
|
||||
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() {
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
while stdin().read_line(&mut input).unwrap() != 0 {
|
||||
let result = evalexpr::eval(&all(input.trim().to_string()));
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => println!("Error: {}", err)
|
||||
}
|
||||
input.clear();
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
let mut context = HashMapContext::new();
|
||||
while stdin().read_line(&mut input).unwrap() != 0 {
|
||||
let result = evalexpr::eval_with_context_mut(&all(input.trim().to_string()), &mut context);
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => println!("Error: {}", err),
|
||||
}
|
||||
input.clear();
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = args().collect();
|
||||
match args.len() {
|
||||
2 => {
|
||||
let expr = all(args[1].clone());
|
||||
let result = evalexpr::eval(&expr.trim());
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => {
|
||||
println!("Error: {}", err);
|
||||
std::process::exit(127);
|
||||
}
|
||||
}
|
||||
},
|
||||
1 => {main_loop()},
|
||||
_ => {
|
||||
if args.len() > 2 {
|
||||
println!("Too many args.");
|
||||
help();
|
||||
} else if args.len() < 1 {
|
||||
println!("Too few args.");
|
||||
help();
|
||||
}
|
||||
}
|
||||
}
|
||||
let args: Vec<String> = args().collect();
|
||||
match args.len() {
|
||||
2 => {
|
||||
let expr = all(args[1].clone());
|
||||
let result = evalexpr::eval(&expr.trim());
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => {
|
||||
println!("Error: {}", err);
|
||||
std::process::exit(127);
|
||||
}
|
||||
}
|
||||
}
|
||||
1 => main_loop(),
|
||||
_ => {
|
||||
if args.len() > 2 {
|
||||
println!("Too many args.");
|
||||
help();
|
||||
} else if args.len() < 1 {
|
||||
println!("Too few args.");
|
||||
help();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub mod tasks {
|
||||
use std::f64::consts;
|
||||
use std::f64::consts;
|
||||
|
||||
pub fn all(expr: String) -> String {
|
||||
convert_constants(exit(expr))
|
||||
|
|
Loading…
Reference in a new issue