mirror of https://github.com/rm-dr/daisy
Added incomplete flag
parent
522917da63
commit
f130bed7aa
|
@ -15,7 +15,7 @@ use termion::{
|
||||||
use super::promptbuffer::PromptBuffer;
|
use super::promptbuffer::PromptBuffer;
|
||||||
use crate::parser;
|
use crate::parser;
|
||||||
use crate::command;
|
use crate::command;
|
||||||
use crate::evaluate::evaluate;
|
use crate::evaluate;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::parser::substitute;
|
use crate::parser::substitute;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ fn do_expression(
|
||||||
// Evaluate expression
|
// Evaluate expression
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
RawTerminal::suspend_raw_mode(&stdout).unwrap();
|
RawTerminal::suspend_raw_mode(&stdout).unwrap();
|
||||||
let g_evaluated = evaluate(&g, context);
|
let g_evaluated = evaluate::evaluate(&g, context, false);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
RawTerminal::activate_raw_mode(&stdout).unwrap();
|
RawTerminal::activate_raw_mode(&stdout).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use super::operator::eval_operator;
|
||||||
use super::function::eval_function;
|
use super::function::eval_function;
|
||||||
use super::EvalError;
|
use super::EvalError;
|
||||||
|
|
||||||
pub fn evaluate(t: &Expression, context: &mut Context) -> Result<Expression, (LineLocation, EvalError)> {
|
pub fn evaluate(t: &Expression, context: &mut Context, allow_incomplete: bool) -> Result<Expression, (LineLocation, EvalError)> {
|
||||||
|
|
||||||
// Keeps track of our position in the expression tree.
|
// Keeps track of our position in the expression tree.
|
||||||
// For example, the coordinates [0, 2, 1] are interpreted as follows:
|
// For example, the coordinates [0, 2, 1] are interpreted as follows:
|
||||||
|
@ -44,7 +44,7 @@ pub fn evaluate(t: &Expression, context: &mut Context) -> Result<Expression, (Li
|
||||||
let new = match g {
|
let new = match g {
|
||||||
Expression::Quantity(_, _) => None,
|
Expression::Quantity(_, _) => None,
|
||||||
|
|
||||||
Expression::Constant(_, c) => { Some(evaluate(&c.value(), context).unwrap()) },
|
Expression::Constant(_, c) => { Some(evaluate(&c.value(), context, false).unwrap()) },
|
||||||
Expression::Variable(l, s) => {
|
Expression::Variable(l, s) => {
|
||||||
// Don't move up, re-evaluate
|
// Don't move up, re-evaluate
|
||||||
// This makes variables containing floating variables work properly
|
// This makes variables containing floating variables work properly
|
||||||
|
@ -71,6 +71,15 @@ pub fn evaluate(t: &Expression, context: &mut Context) -> Result<Expression, (Li
|
||||||
}
|
}
|
||||||
*g = new;
|
*g = new;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if !allow_incomplete {
|
||||||
|
if let Expression::Quantity(_, _) = g {}
|
||||||
|
else {
|
||||||
|
let l = g.get_linelocation();
|
||||||
|
return Err((l, EvalError::EvaluationError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Always move up if we couldn't evaluate this node.
|
// Always move up if we couldn't evaluate this node.
|
||||||
move_up = true;
|
move_up = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ fn eval_to_str(s: &str) -> Result<String, ()> {
|
||||||
};
|
};
|
||||||
//let out_str = g.print();
|
//let out_str = g.print();
|
||||||
|
|
||||||
return match evaluate(&g, &mut Context::new()) {
|
return match evaluate(&g, &mut Context::new(), false) {
|
||||||
Ok(x) => Ok(x.to_string_outer()),
|
Ok(x) => Ok(x.to_string_outer()),
|
||||||
Err(_) => Err(())
|
Err(_) => Err(())
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue