From 6498adb002bcf7e715afe46c23b8635d4592c156 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Wed, 24 Feb 2016 04:32:18 -0600 Subject: Throw a specific error for incomplete parse errors. `nix-repl` will use this for deciding whether to keep waiting for input or error out right away. --- src/libexpr/lexer.l | 2 ++ src/libexpr/nixexpr.hh | 1 + src/libexpr/parser.y | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/libexpr') diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 701c01aff9..f3660ab437 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -195,5 +195,7 @@ or { return OR_KW; } } +<> { data->atEnd = true; return 0; } + %% diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 5e7bc40c85..d2ca09b3a5 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -11,6 +11,7 @@ namespace nix { MakeError(EvalError, Error) MakeError(ParseError, Error) +MakeError(IncompleteParseError, ParseError) MakeError(AssertionError, EvalError) MakeError(ThrownError, AssertionError) MakeError(Abort, EvalError) diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index f87aa26193..80ecd44c59 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -31,10 +31,12 @@ namespace nix { Path basePath; Symbol path; string error; + bool atEnd; Symbol sLetBody; ParseData(EvalState & state) : state(state) , symbols(state.symbols) + , atEnd(false) , sLetBody(symbols.create("")) { }; }; @@ -539,7 +541,12 @@ Expr * EvalState::parse(const char * text, int res = yyparse(scanner, &data); yylex_destroy(scanner); - if (res) throw ParseError(data.error); + if (res) { + if (data.atEnd) + throw IncompleteParseError(data.error); + else + throw ParseError(data.error); + } data.result->bindVars(staticEnv); -- cgit 1.4.1