pull/2/head
Mark 2023-06-11 10:39:46 -07:00
parent 3c0952c3a3
commit dedb192d54
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 79 additions and 74 deletions

View File

@ -30,24 +30,39 @@ fn do_expression(
#[cfg(debug_assertions)]
RawTerminal::activate_raw_mode(&stdout)?;
match g {
Ok(g) => {
#[cfg(debug_assertions)]
RawTerminal::suspend_raw_mode(&stdout)?;
let out_str = g.to_string();
let g = g.evaluate();
#[cfg(debug_assertions)]
RawTerminal::activate_raw_mode(&stdout)?;
// Check for parse errors
if let Err((l, e)) = g {
write!(
stdout, "{}{}{} {}{}\r\n",
color::Fg(color::Red),
" ".repeat(l.pos + 4),
"^".repeat(l.len),
e.to_message(),
color::Fg(color::Reset),
)?;
return Ok(());
}
let Ok(g) = g else {panic!()};
// Display parsed string
write!(
stdout, " {}{}=>{}{} {}\r\n",
style::Bold, color::Fg(color::Magenta),
style::Reset, color::Fg(color::Reset),
out_str
g.to_string()
)?;
match g {
Ok(q) => {
// Evaluate expression
#[cfg(debug_assertions)]
RawTerminal::suspend_raw_mode(&stdout)?;
let g = g.evaluate();
#[cfg(debug_assertions)]
RawTerminal::activate_raw_mode(&stdout)?;
// Show output
if let Ok(q) = g {
write!(
stdout, "\n {}{}={} {}{}\r\n\n",
style::Bold,
@ -56,7 +71,9 @@ fn do_expression(
q.to_string_outer(),
color::Fg(color::Reset)
)?;
},
} else {
match g {
Ok(_) => panic!(),
Err(EvalError::TooBig) => {
write!(
@ -98,20 +115,8 @@ fn do_expression(
)?;
}
}
},
// Show parse error
Err((l, e)) => {
write!(
stdout, "{}{}{} {}{}\r\n",
color::Fg(color::Red),
" ".repeat(l.pos + 4),
"^".repeat(l.len),
e.to_message(),
color::Fg(color::Reset),
)?;
}
};
return Ok(());
}