From be18b7dc25da54ada1d102993a17ac27afbca5e4 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 21 Nov 2025 12:53:51 +0100 Subject: [PATCH] parser: improve error message for missing semicolon in `inherit` Before: error: syntax error, expecting ';' After: error: syntax error, expecting ';' to end 'inherit' bindings Change-Id: I47c633cb5c696b646840c58e03270a7d6a6a6964 --- lix/libexpr/parser/grammar.hh | 10 +++++++++- lix/libexpr/parser/parser-impl1.inc.cc | 1 + tests/functional2/lang/inherit/in-unterminated.nix | 8 ++++++++ .../lang/inherit/parse-fail-unterminated.err.exp | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/functional2/lang/inherit/in-unterminated.nix create mode 100644 tests/functional2/lang/inherit/parse-fail-unterminated.err.exp diff --git a/lix/libexpr/parser/grammar.hh b/lix/libexpr/parser/grammar.hh index 21607c15b..610df3ed2 100644 --- a/lix/libexpr/parser/grammar.hh +++ b/lix/libexpr/parser/grammar.hh @@ -203,6 +203,14 @@ struct sep : sor< using seps = star; +// Delimiters. +namespace d { + // Terminators. + namespace t { + struct inherit : one<';'> { }; + } +} + // marker for semantic rules. not handling one of these in an action that cares about // semantics is probably an error. @@ -411,7 +419,7 @@ struct inherit : _inherit, seq< t::kw_inherit, seps, opt, seps, _inherit::from, seps, must>, seps>, opt<_inherit::attrs, seps>, - must> + must > {}; struct _binding { diff --git a/lix/libexpr/parser/parser-impl1.inc.cc b/lix/libexpr/parser/parser-impl1.inc.cc index b81c23477..e9b8ded77 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::inherit) = "expecting ';' to end 'inherit' bindings"; struct SyntaxErrors { diff --git a/tests/functional2/lang/inherit/in-unterminated.nix b/tests/functional2/lang/inherit/in-unterminated.nix new file mode 100644 index 000000000..552812778 --- /dev/null +++ b/tests/functional2/lang/inherit/in-unterminated.nix @@ -0,0 +1,8 @@ +let + c = { }; + b = 2; +in { + a = b; + inherit c b + d = 5; +} diff --git a/tests/functional2/lang/inherit/parse-fail-unterminated.err.exp b/tests/functional2/lang/inherit/parse-fail-unterminated.err.exp new file mode 100644 index 000000000..c378e4bcd --- /dev/null +++ b/tests/functional2/lang/inherit/parse-fail-unterminated.err.exp @@ -0,0 +1,6 @@ +error: syntax error, expecting ';' to end 'inherit' bindings + at /pwd/in.nix:7:5: + 6| inherit c b + 7| d = 5; + | ^ + 8| }