Added constant generation

This commit is contained in:
2023-06-13 20:15:10 -07:00
parent 86a3f506ba
commit 9fdabb80d3
10 changed files with 466 additions and 362 deletions

View File

@ -74,14 +74,7 @@ impl PreToken {
},
PreToken::PreWord(l, s) => {
let c = match &s[..] {
"π"|"pi" => { Some(Constant::Pi)},
"e" => { Some(Constant::E) },
"phi"|"φ" => { Some(Constant::Phi) },
"mpg" => { Some(Constant::MPG) },
"mph" => { Some(Constant::MPH) },
_ => { None }
};
let c = Constant::from_string(&s);
if c.is_some() {
return Ok(Token::Constant(c.unwrap()));

View File

@ -1,27 +0,0 @@
#[derive(Debug)]
#[derive(Clone)]
pub enum Constant {
// Fake units
MPG,
MPH,
// Mathematics
Pi,
Phi,
E,
}
impl Constant {
pub fn to_string(&self) -> String {
match self {
// Fake units
Constant::MPG => { String::from("mpg") },
Constant::MPH => { String::from("mph") },
// Mathematics
Constant::Pi => { String::from("π") },
Constant::Phi => { String::from("φ") },
Constant::E => { String::from("e") }
}
}
}

View File

@ -1,9 +1,11 @@
mod operator;
mod function;
mod token;
mod constant;
pub use self::operator::Operator;
pub use self::function::Function;
pub use self::token::Token;
pub use self::constant::Constant;
use super::parse;
include!(concat!(env!("OUT_DIR"), "/constants.rs"));