mirror of
https://github.com/rm-dr/daisy
synced 2025-08-02 01:34:50 -07:00
Added constant generation
This commit is contained in:
@ -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()));
|
||||
|
@ -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") }
|
||||
}
|
||||
}
|
||||
}
|
@ -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"));
|
Reference in New Issue
Block a user