From 1e176814e91f84edcc5f5c9a3165ec946ce27788 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 12 Sep 2023 20:39:37 +0200 Subject: [PATCH] rename computer to calculator --- src/bin/ccc/mod.rs | 20 ++++---- src/math/{computer => calculator}/mod.rs | 57 +++++++++++++-------- src/math/{computer => calculator}/result.rs | 18 +++---- src/math/{computer => calculator}/term.rs | 2 +- src/math/mod.rs | 2 +- 5 files changed, 56 insertions(+), 43 deletions(-) rename src/math/{computer => calculator}/mod.rs (75%) rename src/math/{computer => calculator}/result.rs (91%) rename src/math/{computer => calculator}/term.rs (96%) diff --git a/src/bin/ccc/mod.rs b/src/bin/ccc/mod.rs index 9e48d5d..b54a719 100644 --- a/src/bin/ccc/mod.rs +++ b/src/bin/ccc/mod.rs @@ -1,9 +1,9 @@ //! # Executable for the math/compute submodule //! -//! Compute computations with your computer! +//! Calculate Calculations with your Computer! //! //! This command line tool allows you to input a mathematical expression. It will then process the -//! expression. +//! expression. //// ATTRIBUTES //////////////////////////////////////////////////////////////////////////////////// // we want docs @@ -15,7 +15,7 @@ #![warn(clippy::pedantic)] //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// -use pt::math::computer::{*, self}; +use pt::math::calculator::{*, self}; use pt::logger::*; use clap::{Parser, Subcommand}; @@ -29,9 +29,9 @@ use std::path::PathBuf; //// CONSTANTS ///////////////////////////////////////////////////////////////////////////////////// /// short about section displayed in help const ABOUT_ROOT: &'static str = r##" -Compute computations with your computer +Calculate Calculations with your Computer - This commandline tool allows you to calculate complex mathematical expressions right in your + This commandline tool allows you to calculate complex mathematical expressions right in your shell. "##; /// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT) @@ -44,11 +44,11 @@ static LONG_ABOUT_ROOT: &'static str = r##" //// STATICS /////////////////////////////////////////////////////////////////////////////////////// #[derive(Debug, Clone, Parser)] #[command( - author, - version, - about = ABOUT_ROOT, + author, + version, + about = ABOUT_ROOT, long_about = format!("{}{}", ABOUT_ROOT ,LONG_ABOUT_ROOT), - help_template = + help_template = r#"libpt: {version}{about-section}Author: {author-with-newline} {usage-heading} {usage}{all-args}{tab}"# @@ -128,7 +128,7 @@ fn main() { } debug!("exporssion: {}", expr); - let r = Computer::oneshot(expr); + let r = Calculator::oneshot(expr); println!("{}", r.unwrap()); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/math/computer/mod.rs b/src/math/calculator/mod.rs similarity index 75% rename from src/math/computer/mod.rs rename to src/math/calculator/mod.rs index 043f920..bb6d3c1 100644 --- a/src/math/computer/mod.rs +++ b/src/math/calculator/mod.rs @@ -1,8 +1,8 @@ -//! # Compute expressions +//! # Calculate expressions //! -//! Compute computations with your computer (`ccc`) +//! Calculate Calculations with your Calculator (`ccc`) //! -//! This modules aim is to take a term of any kind ([String]) and compute it's value, be it +//! This modules aim is to take a term of any kind ([String]) and calculate it's value, be it //! variable based or a concrete numerical value. It implements different operators and //! (mathematical) functions. @@ -17,8 +17,9 @@ //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// pub mod result; -pub use result::{Error, Result, ComputeResult}; +pub use result::{Error, Result, CalculateResult}; +#[allow(unused_imports)] // we possibly want to use all log levels use crate::logger::{trace, debug, info, warn, error}; //// TYPES ///////////////////////////////////////////////////////////////////////////////////////// @@ -53,6 +54,23 @@ pub enum Operations { Division, /// Mathmatical modulo, finite field arithmetic Modulo, + /// Any function, seel [`Function`] + Function(Function) + +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// ## Supported Functions +/// +/// This `enum` contains all functions supported in this module. +/// +/// A function has a name followed by braces directly afterwards. +/// A function may have 0 to 31 Arguments. +/// +/// Example: `sqrt(19)`, `floor(19.9)` +#[non_exhaustive] +#[derive(Debug)] +pub enum Function { /// Draw the mathmatical root, attribute n is the nth root Root(u16), /// round up @@ -61,46 +79,41 @@ pub enum Operations { Ceil, /// round to nearest integer /// (commercial rounding) - Round -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -#[non_exhaustive] -pub enum Functions { - Root + Round, } //// STRUCTS /////////////////////////////////////////////////////////////////////////////////////// -pub struct Computer; +/// ## A Calculator object +pub struct Calculator; //////////////////////////////////////////////////////////////////////////////////////////////////// #[derive(Debug)] pub struct Term { original: String, - result: Option, + result: Option, parts: Vec } //// IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////// -impl Computer { - pub fn oneshot(t: String) -> Result { +impl Calculator { + pub fn oneshot(t: String) -> Result { trace!(orig=t, "parsing original string to Term"); let mut t = Term::new(t); - trace!("term has been parsed, starting computation"); + trace!("term has been parsed, starting Calculation"); debug!("parsed term: {t:#?}"); - Self::compute(t) + Self::calc(t) } - /// ## compute a [`Term`] + /// ## Calculate a [`Term`] /// /// This method makes use of the /// [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) to - /// compute the final value of any term. + /// Calculate the final value of any term. /// /// This method only processes a single term at a time, without caching. - pub fn compute(mut t: Term) -> Result { - trace!("computing term {t:?}"); - return Ok(ComputeResult::from(0)) + pub fn calc(mut t: Term) -> Result { + trace!("Calculating term {t:?}"); + return Ok(CalculateResult::from(0)) } } diff --git a/src/math/computer/result.rs b/src/math/calculator/result.rs similarity index 91% rename from src/math/computer/result.rs rename to src/math/calculator/result.rs index 35f0406..b381502 100644 --- a/src/math/computer/result.rs +++ b/src/math/calculator/result.rs @@ -1,4 +1,4 @@ -//! # Results and Errors for the compute module +//! # Results and Errors for the calculate module //! //! This module defines the errors and results that can be processed from any given term. @@ -33,7 +33,7 @@ pub enum Error { //////////////////////////////////////////////////////////////////////////////////////////////////// #[derive(Debug)] -pub enum ComputeResult { +pub enum CalculateResult { Variable(VarResult), Numerical(NumericResult), Complex(ComplexResult), @@ -78,7 +78,7 @@ impl From for NumericResult where } //////////////////////////////////////////////////////////////////////////////////////////////////// -impl From for ComputeResult where +impl From for CalculateResult where u128: TryFrom, u128: TryFrom { fn from(value: T) -> Self { @@ -87,23 +87,23 @@ impl From for ComputeResult where } //////////////////////////////////////////////////////////////////////////////////////////////////// -impl From for ComputeResult { +impl From for CalculateResult { fn from(value: NumericResult) -> Self { - ComputeResult::Numerical(value) + CalculateResult::Numerical(value) } } //////////////////////////////////////////////////////////////////////////////////////////////////// -impl Display for ComputeResult { +impl Display for CalculateResult { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - ComputeResult::Numerical(val) => { + CalculateResult::Numerical(val) => { write!(f, "{}", val) } - ComputeResult::Complex(val) => { + CalculateResult::Complex(val) => { write!(f, "{}", val) } - ComputeResult::Variable(val) => { + CalculateResult::Variable(val) => { write!(f, "{}", val) } } diff --git a/src/math/computer/term.rs b/src/math/calculator/term.rs similarity index 96% rename from src/math/computer/term.rs rename to src/math/calculator/term.rs index c6c483b..6bcdf95 100644 --- a/src/math/computer/term.rs +++ b/src/math/calculator/term.rs @@ -1,4 +1,4 @@ -//! # A term that can be the input for computation +//! # A term that can be the input for calculation //! //! Short description //! diff --git a/src/math/mod.rs b/src/math/mod.rs index ac6d0e3..0a4de71 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -18,7 +18,7 @@ #![warn(clippy::pedantic)] //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// -pub mod computer; +pub mod calculator; //// TYPES /////////////////////////////////////////////////////////////////////////////////////////