From 9f12981b3055d4bcb7aab79005f577fb2c232a9f Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 25 Nov 2025 12:50:56 +0100 Subject: [PATCH] parser: improve error message for missing } in attrset Change-Id: I2846dbd8d0c1beb23c885a2d6d388a4f6a6a6964 --- lix/libexpr/parser/grammar.hh | 5 +++-- lix/libexpr/parser/parser-impl1.inc.cc | 1 + .../lang/assets/test_lang_infra/runner_ef.err.exp | 2 +- .../lang/assets/test_lang_infra/runner_pf.err.exp | 2 +- tests/functional2/lang/attrs/in-unterminated.nix | 2 ++ tests/functional2/lang/attrs/parse-fail-unterminated.err.exp | 5 +++++ 6 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/functional2/lang/attrs/in-unterminated.nix create mode 100644 tests/functional2/lang/attrs/parse-fail-unterminated.err.exp diff --git a/lix/libexpr/parser/grammar.hh b/lix/libexpr/parser/grammar.hh index 73fe63adb..cd549f150 100644 --- a/lix/libexpr/parser/grammar.hh +++ b/lix/libexpr/parser/grammar.hh @@ -209,6 +209,7 @@ namespace d { namespace t { struct inherit : one<';'> { }; struct binding : one<';'> { }; + struct attrs : one<'}'> { }; } } @@ -401,7 +402,7 @@ struct _attr { struct expr : semantic, seq< TAO_PEGTL_STRING("${"), seps, must, seps, - must> + must > {}; }; struct attr : _attr, sor< @@ -505,7 +506,7 @@ struct _expr { Init..., OpenMod>, seps, bindings, seps, - must> + must > {}; struct select; diff --git a/lix/libexpr/parser/parser-impl1.inc.cc b/lix/libexpr/parser/parser-impl1.inc.cc index a1ab213b4..41e070e4d 100644 --- a/lix/libexpr/parser/parser-impl1.inc.cc +++ b/lix/libexpr/parser/parser-impl1.inc.cc @@ -58,6 +58,7 @@ 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"; +error_message_for(grammar::v1::d::t::attrs) = "expecting '}' to end attribute set"; struct SyntaxErrors { diff --git a/tests/functional2/lang/assets/test_lang_infra/runner_ef.err.exp b/tests/functional2/lang/assets/test_lang_infra/runner_ef.err.exp index e322e0b44..a65fa228a 100644 --- a/tests/functional2/lang/assets/test_lang_infra/runner_ef.err.exp +++ b/tests/functional2/lang/assets/test_lang_infra/runner_ef.err.exp @@ -1,4 +1,4 @@ -error: syntax error, unexpected end of file, expecting '}' +error: syntax error, unexpected end of file, expecting '}' to end attribute set at /pwd/in.nix:1:2: 1| { | ^ diff --git a/tests/functional2/lang/assets/test_lang_infra/runner_pf.err.exp b/tests/functional2/lang/assets/test_lang_infra/runner_pf.err.exp index e322e0b44..a65fa228a 100644 --- a/tests/functional2/lang/assets/test_lang_infra/runner_pf.err.exp +++ b/tests/functional2/lang/assets/test_lang_infra/runner_pf.err.exp @@ -1,4 +1,4 @@ -error: syntax error, unexpected end of file, expecting '}' +error: syntax error, unexpected end of file, expecting '}' to end attribute set at /pwd/in.nix:1:2: 1| { | ^ diff --git a/tests/functional2/lang/attrs/in-unterminated.nix b/tests/functional2/lang/attrs/in-unterminated.nix new file mode 100644 index 000000000..4c5f29a89 --- /dev/null +++ b/tests/functional2/lang/attrs/in-unterminated.nix @@ -0,0 +1,2 @@ +{ + a = "b"; diff --git a/tests/functional2/lang/attrs/parse-fail-unterminated.err.exp b/tests/functional2/lang/attrs/parse-fail-unterminated.err.exp new file mode 100644 index 000000000..d22c111d1 --- /dev/null +++ b/tests/functional2/lang/attrs/parse-fail-unterminated.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected end of file, expecting '}' to end attribute set + at /pwd/in.nix:3:1: + 2| a = "b"; + 3| + | ^