diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-09-29 09:46:58 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2022-09-29 13:45:03 +0300 |
commit | d7cb460833e6dde3e3b958b993eee3eee4ae3bf0 (patch) | |
tree | d96f782c0c3e79b4ce21a510498517c4b1386b35 /libbuild2/build/script/parser.cxx | |
parent | e086480b76d995beb23b9b91bda335702f7f0d2a (diff) |
Fix variable append logic in script
Diffstat (limited to 'libbuild2/build/script/parser.cxx')
-rw-r--r-- | libbuild2/build/script/parser.cxx | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx index cb0dbbb..8759cdf 100644 --- a/libbuild2/build/script/parser.cxx +++ b/libbuild2/build/script/parser.cxx @@ -1305,19 +1305,25 @@ namespace build2 // Note that we rely on "small function object" optimization for the // exec_*() lambdas. // - auto exec_assign = [this] (const variable& var, - value&& val, - type kind, - const location& l) + auto exec_set = [this] (const variable& var, + token& t, build2::script::token_type& tt, + const location&) { + next (t, tt); + type kind (tt); // Assignment kind. + + mode (lexer_mode::variable_line); + value rhs (parse_variable_line (t, tt)); + + assert (tt == type::newline); + + // Assign. + // value& lhs (kind == type::assign ? environment_->assign (var) : environment_->append (var)); - if (kind == type::assign) - lhs = move (val); - else - append_value (&var, lhs, move (val), l); + apply_value_attributes (&var, lhs, move (rhs), kind); }; auto exec_cond = [this] (token& t, build2::script::token_type& tt, @@ -1333,9 +1339,22 @@ namespace build2 return runner_->run_cond (*environment_, ce, ii, li, ll); }; + auto exec_for = [this] (const variable& var, + value&& val, + const location& l) + { + value& lhs (environment_->assign (var)); + + // To match the function semantics also pass the value's type + // attribute, restoring it from RHS. Note that the value can't be + // NULL. + // + apply_value (&var, lhs, move (val), type::assign, l, val.type); + }; + build2::script::parser::exec_lines ( begin, end, - exec_assign, exec_cmd, exec_cond, + exec_set, exec_cmd, exec_cond, exec_for, nullptr /* iteration_index */, environment_->exec_line, &environment_->var_pool); |