aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 05:17:36 +0100
committereldritch horrors <pennae@lix.systems>2024-03-09 00:25:54 -0700
commitba16d9912402de5556fa93a1381a019c35f80fcf (patch)
treeeab1fae800e6956acda8ce97485c2285a16bbb2f /src/libexpr
parent2cea973e291e1027dad57475107b54f33d98e47c (diff)
simplify parse error reporting
since nix doesn't use the bison `error` terminal anywhere any invocation of yyerror will immediately cause a failure. since we're *already* leaking tons of memory whatever little bit bison allocates internally doesn't much matter any more, and we'll be replacing the parser soon anyway. coincidentally this now also matches the error behavior of URIs when they are disabled or ~/ paths in pure eval mode, duplicate attr detection etc. (cherry picked from commit e8d9de967fe47a7f9324b0022a2ef50df59f419d) Change-Id: I560c50d11dceddc2d7cf9ed2c6c631a309ce574e
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/parser.y13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 425ff16c1..0c6952929 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -18,6 +18,7 @@
#include <variant>
+#include "finally.hh"
#include "util.hh"
#include "nixexpr.hh"
@@ -59,7 +60,6 @@ namespace nix {
Expr * result;
SourcePath basePath;
PosTable::Origin origin;
- std::optional<ErrorInfo> error;
};
}
@@ -314,10 +314,10 @@ static inline PosIdx makeCurPos(const YYLTYPE & loc, ParseData * data)
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * error)
{
- data->error = {
+ throw ParseError({
.msg = hintfmt(error),
.errPos = data->state.positions[makeCurPos(*loc, data)]
- };
+ });
}
@@ -685,11 +685,10 @@ Expr * EvalState::parse(
};
yylex_init(&scanner);
- yy_scan_buffer(text, length, scanner);
- int res = yyparse(scanner, &data);
- yylex_destroy(scanner);
+ Finally _destroy([&] { yylex_destroy(scanner); });
- if (res) throw ParseError(data.error.value());
+ yy_scan_buffer(text, length, scanner);
+ yyparse(scanner, &data);
data.result->bindVars(*this, staticEnv);