fabricate surrounding parens for top level statements from repl

Signed-off-by: Ava Hahn <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2023-10-12 21:08:04 -07:00
parent c05b94e92a
commit 88e9287d01

View file

@ -240,21 +240,20 @@ fn incomplete_brackets(line: &str) -> bool {
for c in line.chars() { for c in line.chars() {
match c { match c {
c if ['"', '`', '\''].contains(&c) => { c if ['"', '`', '\''].contains(&c) => {
match within_string { match within_string {
Some(w) if c == w => { Some(w) if c == w => {
balance.pop(); balance.pop();
within_string = None within_string = None
} }
Some(_) => {}, Some(_) => {},
None => { None => {
balance.push(c); balance.push(c);
within_string = Some(c) within_string = Some(c)
}, },
} }
}, },
'(' if within_string.is_none() => balance.push(')'),
'(' if within_string.is_none() => balance.push(')'),
')' => if let Some(last) = balance.last() { ')' => if let Some(last) = balance.last() {
if last == &c { if last == &c {
balance.pop(); balance.pop();
@ -391,7 +390,10 @@ fn main() {
match user_doc { match user_doc {
Signal::Success(line) => { Signal::Success(line) => {
println!(""); // add a new line before output gets printed 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) { match lex(&l) {
Ok(a) => match eval(&a, &mut syms) { Ok(a) => match eval(&a, &mut syms) {
Ok(a) => println!("{}", a), Ok(a) => println!("{}", a),