From 4881a227779a78db1de2a7723e2a86f2b61453b3 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 20 Oct 2022 19:39:57 +0300 Subject: Change attribute syntax in script to come after variable in set and for (set x [...], for x [...]) --- libbuild2/script/run.cxx | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'libbuild2/script/run.cxx') diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index b7f3314..ca04443 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -1171,7 +1171,7 @@ namespace build2 // The set pseudo-builtin: set variable from the stdin input. // - // set [-e|--exact] [(-n|--newline)|(-w|--whitespace)] [] + // set [-e|--exact] [(-n|--newline)|(-w|--whitespace)] [] // static void set_builtin (environment& env, @@ -1195,18 +1195,27 @@ namespace build2 if (!scan.more ()) fail (ll) << "set: missing variable name"; - string a (scan.next ()); // Either attributes or variable name. - const string* ats (!scan.more () ? nullptr : &a); - string vname (!scan.more () ? move (a) : scan.next ()); + string vname (scan.next ()); + if (vname.empty ()) + fail (ll) << "set: empty variable name"; + // Detect patterns analogous to parser::parse_variable_name() (so we + // diagnose `set x[string]`). + // + if (vname.find_first_of ("[*?") != string::npos) + fail (ll) << "set: expected variable name instead of " << vname; + + string attrs; if (scan.more ()) - fail (ll) << "set: unexpected argument '" << scan.next () << "'"; + { + attrs = scan.next (); - if (ats != nullptr && ats->empty ()) - fail (ll) << "set: empty variable attributes"; + if (attrs.empty ()) + fail (ll) << "set: empty variable attributes"; - if (vname.empty ()) - fail (ll) << "set: empty variable name"; + if (scan.more ()) + fail (ll) << "set: unexpected argument '" << scan.next () << "'"; + } stream_reader sr (move (in), pipe, ops.whitespace (), ops.newline (), ops.exact (), @@ -1220,10 +1229,7 @@ namespace build2 for (optional s; (s = sr.next ()); ) ns.emplace_back (move (*s)); - env.set_variable (move (vname), - move (ns), - ats != nullptr ? *ats : empty_string, - ll); + env.set_variable (move (vname), move (ns), attrs, ll); } catch (const io_error& e) { -- cgit v1.1