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)