From e42da2a469404e1d421ccee7ccbccb36f363a98b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 30 Sep 2019 13:57:10 +0200 Subject: Handle attributes in switch value and pattern expressions --- libbuild2/parser.cxx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'libbuild2/parser.cxx') diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index a6a5a83..6a5698d 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -2105,7 +2105,10 @@ namespace build2 expr e; e.value = - parse_value (t, tt, pattern_mode::expand, "expression", nullptr); + parse_value_with_attributes (t, tt, + pattern_mode::expand, + "expression", + nullptr); if (tt == type::colon) { @@ -2203,7 +2206,7 @@ namespace build2 auto parse_pattern = [this] (token& t, type& tt) { - return parse_value ( + return parse_value_with_attributes ( t, tt, pattern_mode::ignore, "pattern", nullptr); }; @@ -3048,6 +3051,29 @@ namespace build2 } } + value parser:: + parse_value_with_attributes (token& t, token_type& tt, + pattern_mode pmode, + const char* what, + const string* separators) + { + // Parse value attributes if any. Note that it's ok not to have anything + // after the attributes (think [null]). + // + attributes_push (t, tt, true); + + value rhs (tt != type::newline && tt != type::eos + ? parse_value (t, tt, pmode, what, separators) + : value (names ())); + + if (pre_parse_) + return rhs; // Empty. + + value lhs; + apply_value_attributes (nullptr, lhs, move (rhs), type::assign); + return lhs; + } + values parser:: parse_eval (token& t, type& tt, pattern_mode pmode) { -- cgit v1.1