mirror of
https://github.com/rm-dr/daisy
synced 2025-07-05 01:59:30 -07:00
Fixed variable parse order
This commit is contained in:
@ -13,19 +13,29 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn push_hist(&mut self, t: Expression) { self.history.push(t); }
|
||||
pub fn push_var(&mut self, s: String, t: Expression) { self.variables.insert(s, t); }
|
||||
pub fn push_var(&mut self, s: String, t: Expression) -> Result<(), ()> {
|
||||
if self.valid_varible(&s) {
|
||||
self.variables.insert(s, t);
|
||||
return Ok(());
|
||||
} else { return Err(()); }
|
||||
}
|
||||
pub fn del_var(&mut self, s: &String) { self.variables.remove(s); }
|
||||
|
||||
pub fn get_variable(&self, s: &String) -> Option<Expression> {
|
||||
|
||||
let v: Option<&Expression>;
|
||||
|
||||
if s == "ans" {
|
||||
v = self.history.last();
|
||||
} else {
|
||||
v = self.variables.get(s);
|
||||
}
|
||||
|
||||
if v.is_some() { Some(v.unwrap().clone()) } else { None }
|
||||
}
|
||||
|
||||
pub fn valid_varible(&self, s: &str) -> bool {
|
||||
return match s {
|
||||
"ans" => false,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user