From 88e9287d01af8c0d66287b73ef0c981610850514 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 12 Oct 2023 21:08:04 -0700 Subject: [PATCH] fabricate surrounding parens for top level statements from repl Signed-off-by: Ava Hahn --- src/bin/relish.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/bin/relish.rs b/src/bin/relish.rs index 226c8ab..d44df1a 100644 --- a/src/bin/relish.rs +++ b/src/bin/relish.rs @@ -240,21 +240,20 @@ fn incomplete_brackets(line: &str) -> bool { for c in line.chars() { match c { c if ['"', '`', '\''].contains(&c) => { - match within_string { - Some(w) if c == w => { - balance.pop(); - within_string = None - } - Some(_) => {}, - None => { - balance.push(c); - within_string = Some(c) - }, - } - }, - - '(' if within_string.is_none() => balance.push(')'), + match within_string { + Some(w) if c == w => { + balance.pop(); + within_string = None + } + Some(_) => {}, + None => { + balance.push(c); + within_string = Some(c) + }, + } + }, + '(' if within_string.is_none() => balance.push(')'), ')' => if let Some(last) = balance.last() { if last == &c { balance.pop(); @@ -391,7 +390,10 @@ fn main() { match user_doc { Signal::Success(line) => { println!(""); // add a new line before output gets printed - let l = line.as_str().to_owned(); + let mut l = line.as_str().to_owned(); + if !l.starts_with('(') { + l = "(".to_owned() + &l + ")"; + } match lex(&l) { Ok(a) => match eval(&a, &mut syms) { Ok(a) => println!("{}", a),