From ea1a4a3c8b7551a59667889edc35f806fd2ce45a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Nov 2022 11:06:18 +0200 Subject: Improve diagnostics for value subscript out of evaluation context --- libbuild2/parser.cxx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index c8f66de..b4df45b 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -7759,8 +7759,27 @@ namespace build2 // This should be a simple value or a simple directory. // if (lv.size () > 1) - fail (loc) << "concatenating " << what << " contains multiple " - << "values"; + { + diag_record dr (fail (loc)); + + dr << "concatenating " << what << " contains multiple values"; + + // See if this looks like a subscript without an evaluation + // context and help the user out. + // + if (mode () != lexer_mode::eval) + { + const token& t (peeked ()); // Should be peeked at. + + if (t.type == type::word && + t.qtype == quote_type::unquoted && + t.value[0] == '[') + { + dr << info << "wrap it in (...) evaluation context if this " + << "is value subscript"; + } + } + } const name& n (lv[0]); -- cgit v1.1