mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
Merge pull request #13334 from NixOS/repl-incomplete-parse
repl: Don't wait on incomplete parses from imported file
This commit is contained in:
commit
530efc3121
2 changed files with 21 additions and 11 deletions
|
@ -158,6 +158,8 @@ static std::ostream & showDebugTrace(std::ostream & out, const PosTable & positi
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MakeError(IncompleteReplExpr, ParseError);
|
||||||
|
|
||||||
static bool isFirstRepl = true;
|
static bool isFirstRepl = true;
|
||||||
|
|
||||||
ReplExitStatus NixRepl::mainLoop()
|
ReplExitStatus NixRepl::mainLoop()
|
||||||
|
@ -205,16 +207,8 @@ ReplExitStatus NixRepl::mainLoop()
|
||||||
default:
|
default:
|
||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
} catch (ParseError & e) {
|
} catch (IncompleteReplExpr &) {
|
||||||
if (e.msg().find("unexpected end of file") != std::string::npos) {
|
continue;
|
||||||
// For parse errors on incomplete input, we continue waiting for the next line of
|
|
||||||
// input without clearing the input so far.
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
printMsg(lvlError, e.msg());
|
|
||||||
}
|
|
||||||
} catch (EvalError & e) {
|
|
||||||
printMsg(lvlError, e.msg());
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
printMsg(lvlError, e.msg());
|
printMsg(lvlError, e.msg());
|
||||||
} catch (Interrupted & e) {
|
} catch (Interrupted & e) {
|
||||||
|
@ -837,7 +831,17 @@ Expr * NixRepl::parseString(std::string s)
|
||||||
|
|
||||||
void NixRepl::evalString(std::string s, Value & v)
|
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);
|
e->eval(*state, *env, v);
|
||||||
state->forceValue(v, v.determinePos(noPos));
|
state->forceValue(v, v.determinePos(noPos));
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,6 +277,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
|
# TODO: move init to characterisation/framework.sh
|
||||||
badDiff=0
|
badDiff=0
|
||||||
badExitCode=0
|
badExitCode=0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue