mirror of
https://github.com/rm-dr/daisy
synced 2025-08-02 01:34:50 -07:00
Added "ans" variable
This commit is contained in:
@ -83,6 +83,9 @@ impl PreToken {
|
||||
let c = Unit::from_string(&s);
|
||||
if c.is_some() { return Ok(Token::Quantity(c.unwrap())); }
|
||||
|
||||
|
||||
if s == "ans" { return Ok(Token::Variable(String::from("ans"))); }
|
||||
|
||||
return Err((l, ParserError::Undefined(s)));
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ fn push_token(g: &mut VecDeque<PreToken>, t: Option<PreToken>, stop_i: usize) {
|
||||
}
|
||||
}
|
||||
|
||||
// Some operators are written as words.
|
||||
if let PreToken::PreWord(l, s) = &t {
|
||||
let o = Operator::from_string(s);
|
||||
if o.is_some() {
|
||||
if Operator::from_string(s).is_some() {
|
||||
t = PreToken::PreOperator(*l, s.clone());
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use super::Constant;
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone)]
|
||||
pub enum Token {
|
||||
Variable(String),
|
||||
Quantity(Quantity),
|
||||
Constant(Constant),
|
||||
Operator(Operator, VecDeque<Token>),
|
||||
@ -18,6 +19,7 @@ impl ToString for Token {
|
||||
match self {
|
||||
Token::Quantity(v) => v.to_string(),
|
||||
Token::Constant(c) => c.to_string(),
|
||||
Token::Variable(s) => s.clone(),
|
||||
Token::Operator(o,a) => o.print(a)
|
||||
}
|
||||
}
|
||||
@ -30,6 +32,7 @@ impl Token {
|
||||
match self {
|
||||
Token::Quantity(v) => v.to_string_outer(),
|
||||
Token::Constant(c) => c.to_string(),
|
||||
Token::Variable(s) => s.clone(),
|
||||
Token::Operator(o,a) => o.print(a)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user