Fix bug where single statements could not be executed in the REPL

master
Nick Krichevsky 2024-05-23 12:53:39 -04:00
parent b00d635820
commit 7dbba9bf1e
1 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@ struct ParseError {
line: Option<usize>,
}
#[derive(Debug)]
enum ParsedStatement {
Stmt { stmt: Stmt },
ImplicitStmt { stmt: Stmt, line_number: usize },
@ -32,9 +33,13 @@ pub fn parse_repl_line<I: Iterator<Item = Token> + Clone, F: FnMut(ScriptError)>
) -> Vec<Stmt> {
let mut statements = parse(iter, &mut on_error);
if statements.len() == 1 {
if let ParsedStatement::ImplicitStmt { stmt, .. } = statements.remove(0) {
let removed = statements.remove(0);
if let ParsedStatement::ImplicitStmt { stmt, .. } = removed {
return vec![stmt];
}
// Put this statement back if it didn't match, otherwise we will execute nothing
statements.push(removed);
}
ensure_parsed_statements_explicit(statements, on_error)