commit 365be9f72f42f00a83cd264d2ec767245df85a96 Author: Ivan Bushchik Date: Wed Jan 25 22:03:01 2023 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f13fbf5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,16 @@ +# 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.1.0" +dependencies = [ + "evalexpr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..33b1686 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "feval" +version = "0.1.0" +edition = "2021" +description = "clt for fast evaluations" +readme = "README.md" +repository = "https://github.com/ivabus/feval" +license = "MIT" +authors = ["Ivan ivabus Bushchik"] + +[dependencies] +evalexpr = "8.1.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e5589b4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2023 Ivan Bushchik + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0925bf1 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# fEval + +> Fast EVALuator + +Simple command line tool, that \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e67dfc0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,21 @@ +use evalexpr; +use std::env::args; +mod tasks; +use crate::tasks::tasks::all; + +fn help() { + println!(r#"feval: evaluate expressions +usage: provide exactly one argument (with expression) +example: feval "math::sin(30 * math::pi / 180)""#); +} + +fn main() { + let args: Vec = args().collect(); + if args.len() != 2 { + println!("Too many args."); + help(); + return + } + let expr = all(args[1].clone()); + println!("{}", evalexpr::eval(&expr).unwrap()) +} diff --git a/src/tasks.rs b/src/tasks.rs new file mode 100644 index 0000000..87bc793 --- /dev/null +++ b/src/tasks.rs @@ -0,0 +1,10 @@ +pub mod tasks { + use std::f64::consts; + + pub fn all(expr: String) -> String { + convert_constants(expr) + } + fn convert_constants(expr: String) -> String { + expr.replace("math::pi", &consts::PI.to_string()).replace("math::e", &consts::E.to_string()) + } +} \ No newline at end of file