From 6bb532ed03738110aab0b46fb13caec30051c5b0 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 24 Nov 2025 12:50:44 +0100 Subject: [PATCH] parser: improve error message for missing semicolon in let/{} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the same vein as be18b7dc2ยน. Before: error: syntax error, expecting ';' After: error: syntax error, expecting ';' to end binding [1]: be18b7dc25da54ada1d102993a17ac27afbca5e4 Change-Id: Iffbcb113d2b892a50c646c9875e970376a6a6964 --- lix/libexpr/parser/grammar.hh | 7 ++++--- lix/libexpr/parser/parser-impl1.inc.cc | 1 + tests/functional2/lang/let/in-unterminated.nix | 3 +++ tests/functional2/lang/let/parse-fail-unterminated.err.exp | 6 ++++++ tests/functional2/lang/let/test.toml | 4 ++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/functional2/lang/let/in-unterminated.nix create mode 100644 tests/functional2/lang/let/parse-fail-unterminated.err.exp diff --git a/lix/libexpr/parser/grammar.hh b/lix/libexpr/parser/grammar.hh index 610df3ed2..73fe63adb 100644 --- a/lix/libexpr/parser/grammar.hh +++ b/lix/libexpr/parser/grammar.hh @@ -208,6 +208,7 @@ namespace d { // Terminators. namespace t { struct inherit : one<';'> { }; + struct binding : one<';'> { }; } } @@ -438,7 +439,7 @@ struct bindings : opt< list< sor< inherit, - seq>> + seq> >, seps > @@ -447,9 +448,9 @@ struct bindings : opt< struct repl_binding : binding {}; struct repl_bindings : seq< - list, t::sep>, + list, /* Optional semicolon at the end for convenience */ - opt> + opt > {}; struct op { diff --git a/lix/libexpr/parser/parser-impl1.inc.cc b/lix/libexpr/parser/parser-impl1.inc.cc index e9b8ded77..a1ab213b4 100644 --- a/lix/libexpr/parser/parser-impl1.inc.cc +++ b/lix/libexpr/parser/parser-impl1.inc.cc @@ -56,6 +56,7 @@ error_message_for(grammar::v1::expr::select) = "expecting selection expression"; error_message_for(grammar::v1::t::kw_then) = "expecting 'then'"; error_message_for(grammar::v1::t::kw_else) = "expecting 'else'"; error_message_for(grammar::v1::t::kw_in) = "expecting 'in'"; +error_message_for(grammar::v1::d::t::binding) = "expecting ';' to end binding"; error_message_for(grammar::v1::d::t::inherit) = "expecting ';' to end 'inherit' bindings"; struct SyntaxErrors diff --git a/tests/functional2/lang/let/in-unterminated.nix b/tests/functional2/lang/let/in-unterminated.nix new file mode 100644 index 000000000..83215f4b0 --- /dev/null +++ b/tests/functional2/lang/let/in-unterminated.nix @@ -0,0 +1,3 @@ +let + a = "" +in a diff --git a/tests/functional2/lang/let/parse-fail-unterminated.err.exp b/tests/functional2/lang/let/parse-fail-unterminated.err.exp new file mode 100644 index 000000000..924a952a0 --- /dev/null +++ b/tests/functional2/lang/let/parse-fail-unterminated.err.exp @@ -0,0 +1,6 @@ +error: syntax error, expecting ';' to end binding + at /pwd/in.nix:3:1: + 2| a = "" + 3| in a + | ^ + 4| diff --git a/tests/functional2/lang/let/test.toml b/tests/functional2/lang/let/test.toml index 77ae4290f..5fdf05b87 100644 --- a/tests/functional2/lang/let/test.toml +++ b/tests/functional2/lang/let/test.toml @@ -5,3 +5,7 @@ runner = "eval-okay" runner = "eval-okay" in = "in-ancient-let.nix" flags = [ "--extra-deprecated-features", "ancient-let" ] + +[[test]] +runner = "parse-fail" +in = "in-unterminated.nix"