diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index c93ebeb999a..e3578161b75 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -165,6 +165,8 @@ static std::ostream & showDebugTrace(std::ostream & out, const PosTable & positi return out; } +MakeError(IncompleteReplExpr, ParseError); + static bool isFirstRepl = true; ReplExitStatus NixRepl::mainLoop() @@ -213,6 +215,7 @@ ReplExitStatus NixRepl::mainLoop() default: unreachable(); } +<<<<<<< HEAD } catch (ParseError & e) { if (e.msg().find("unexpected end of file") != std::string::npos) { // For parse errors on incomplete input, we continue waiting for the next line of @@ -223,6 +226,10 @@ ReplExitStatus NixRepl::mainLoop() } } catch (EvalError & e) { printMsg(lvlError, e.msg()); +======= + } catch (IncompleteReplExpr &) { + continue; +>>>>>>> d8b067b54 (repl: Don't wait on incomplete parses from imported file) } catch (Error & e) { printMsg(lvlError, e.msg()); } catch (Interrupted & e) { @@ -841,7 +848,17 @@ Expr * NixRepl::parseString(std::string s) void NixRepl::evalString(std::string s, Value & v) { - Expr * e = parseString(s); + Expr * e; + try { + e = parseString(s); + } catch (ParseError & e) { + if (e.msg().find("unexpected end of file") != std::string::npos) + // For parse errors on incomplete input, we continue waiting for the next line of + // input without clearing the input so far. + throw IncompleteReplExpr(e.msg()); + else + throw; + } e->eval(*state, *env, v); state->forceValue(v, v.determinePos(noPos)); } diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh index 82a932e2b1e..21b3fc08565 100755 --- a/tests/functional/repl.sh +++ b/tests/functional/repl.sh @@ -278,6 +278,12 @@ testReplResponseNoRegex ' } ' +# Don't prompt for more input when getting unexpected EOF in imported files. +testReplResponse " +import $testDir/lang/parse-fail-eof-pos.nix +" \ +'.*error: syntax error, unexpected end of file.*' + # TODO: move init to characterisation/framework.sh badDiff=0 badExitCode=0