This commit is contained in:
Ivan Bushchik 2023-01-25 22:35:37 +03:00
parent d0a71244b2
commit 27a825b2a2
No known key found for this signature in database
GPG key ID: 3E4E9C7D66E44BF7
3 changed files with 33 additions and 14 deletions

2
Cargo.lock generated
View file

@ -10,7 +10,7 @@ checksum = "aacfb566035f8cd02f6ec9247c242f3f9904a0b288ea383abcf4e95df6436a34"
[[package]] [[package]]
name = "feval" name = "feval"
version = "0.1.2" version = "0.2.0"
dependencies = [ dependencies = [
"evalexpr", "evalexpr",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "feval" name = "feval"
version = "0.1.2" version = "0.2.0"
edition = "2021" edition = "2021"
description = "clt for fast evaluations" description = "clt for fast evaluations"
readme = "README.md" readme = "README.md"

View file

@ -1,25 +1,44 @@
use evalexpr; use evalexpr;
use std::env::args; use std::{env::args, io::{stdin, stdout, Write}};
mod tasks; mod tasks;
use crate::tasks::tasks::all; use crate::tasks::tasks::all;
fn help() { fn help() {
println!(r#"feval: evaluate expressions println!(r#"feval: evaluate expressions
usage: provide exactly one argument (with expression) 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 {
println!("{}", evalexpr::eval(&input.trim()).unwrap());
input.clear();
print!(">>> ");
stdout().flush().unwrap();
}
}
fn main() { fn main() {
let args: Vec<String> = args().collect(); let args: Vec<String> = args().collect();
if args.len() > 2 { match args.len() {
println!("Too many args."); 2 => {
help(); let expr = all(args[1].clone());
return println!("{}", evalexpr::eval(&expr).unwrap())
} else if args.len() < 2 { },
println!("Too few args."); 1 => {main_loop()},
help(); _ => {
return if args.len() > 2 {
println!("Too many args.");
help();
return
} else if args.len() < 1 {
println!("Too few args.");
help();
return
}
}
} }
let expr = all(args[1].clone());
println!("{}", evalexpr::eval(&expr).unwrap())
} }