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() {
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),