diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 476403c4c..727ee94b4 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -62,6 +62,10 @@ using namespace nix; void yyerror(YYLTYPE * loc, yyscan_t scanner, ParserState * state, const char * error) { + if (std::string_view(error).starts_with("syntax error, unexpected end of file")) { + loc->first_column = loc->last_column; + loc->first_line = loc->last_line; + } throw ParseError({ .msg = HintFmt(error), .pos = state->positions[state->at(*loc)] diff --git a/tests/functional/lang/parse-fail-eof-in-string.err.exp b/tests/functional/lang/parse-fail-eof-in-string.err.exp index b28d35950..17f34b62d 100644 --- a/tests/functional/lang/parse-fail-eof-in-string.err.exp +++ b/tests/functional/lang/parse-fail-eof-in-string.err.exp @@ -1,5 +1,5 @@ error: syntax error, unexpected end of file, expecting '"' - at «stdin»:3:5: + at «stdin»:3:6: 2| # Note that this file must not end with a newline. 3| a 1"$ - | ^ + | ^ diff --git a/tests/functional/lang/parse-fail-eof-pos.err.exp b/tests/functional/lang/parse-fail-eof-pos.err.exp new file mode 100644 index 000000000..ef9ca381c --- /dev/null +++ b/tests/functional/lang/parse-fail-eof-pos.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected end of file + at «stdin»:3:1: + 2| # no content + 3| + | ^ diff --git a/tests/functional/lang/parse-fail-eof-pos.nix b/tests/functional/lang/parse-fail-eof-pos.nix new file mode 100644 index 000000000..bd66a2c98 --- /dev/null +++ b/tests/functional/lang/parse-fail-eof-pos.nix @@ -0,0 +1,2 @@ +( +# no content