From 7dbba9bf1ee0837f38ba315382829951769ed854 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Thu, 23 May 2024 12:53:39 -0400 Subject: [PATCH] Fix bug where single statements could not be executed in the REPL --- src/parse.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parse.rs b/src/parse.rs index 63c3436..b6b443c 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -13,6 +13,7 @@ struct ParseError { line: Option, } +#[derive(Debug)] enum ParsedStatement { Stmt { stmt: Stmt }, ImplicitStmt { stmt: Stmt, line_number: usize }, @@ -32,9 +33,13 @@ pub fn parse_repl_line + Clone, F: FnMut(ScriptError)> ) -> Vec { 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)