mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
diagnose "unexpected EOF" at EOF
this needs a string comparison because there seems to be no other way to get that information out of bison. usually the location info is going to be correct (pointing at a bad token), but since EOF isn't a token as such it'll be wrong in that this case. this hasn't shown up much so far because a single line ending *is* a token, so any file formatted in the usual manner (ie, ending in a line ending) would have its EOF position reported correctly.
This commit is contained in:
parent
2be6b14328
commit
855fd5a1bb
4 changed files with 13 additions and 2 deletions
|
@ -64,6 +64,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)]
|
||||
|
|
|
@ -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"$
|
||||
| ^
|
||||
| ^
|
||||
|
|
5
tests/functional/lang/parse-fail-eof-pos.err.exp
Normal file
5
tests/functional/lang/parse-fail-eof-pos.err.exp
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: syntax error, unexpected end of file
|
||||
at «stdin»:3:1:
|
||||
2| # no content
|
||||
3|
|
||||
| ^
|
2
tests/functional/lang/parse-fail-eof-pos.nix
Normal file
2
tests/functional/lang/parse-fail-eof-pos.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
(
|
||||
# no content
|
Loading…
Reference in a new issue