diff options
-rw-r--r-- | build2/parser | 5 | ||||
-rw-r--r-- | build2/parser.cxx | 43 | ||||
-rw-r--r-- | tests/directive/assert.test | 2 |
3 files changed, 20 insertions, 30 deletions
diff --git a/build2/parser b/build2/parser index 45f5b16..61c5c80 100644 --- a/build2/parser +++ b/build2/parser @@ -208,12 +208,13 @@ namespace build2 value parse_value (token& t, token_type& tt, const char* what = "name", - const string* separators = &name_separators) + const string* separators = &name_separators, + bool chunk = false) { names ns; pair<bool, const value_type*> p ( parse_names ( - t, tt, ns, false, what, separators, 0, nullptr, nullptr, nullptr)); + t, tt, ns, chunk, what, separators, 0, nullptr, nullptr, nullptr)); value r (p.second); // Potentially typed NULL value. diff --git a/build2/parser.cxx b/build2/parser.cxx index 4126aff..b287550 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -1326,24 +1326,19 @@ namespace build2 // Parse as names to get variable expansion, evaluation, etc. // - const location nsl (get_location (t)); - names ns (parse_names (t, tt, false, "expression", nullptr)); + const location l (get_location (t)); - // Should evaluate to 'true' or 'false'. - // try { - if (ns.size () != 1) - throw invalid_argument (string ()); + // Should evaluate to 'true' or 'false'. + // + bool e ( + convert<bool> ( + parse_value (t, tt, "expression", nullptr))); - bool e (convert<bool> (move (ns[0]))); take = (k.back () == '!' ? !e : e); } - catch (const invalid_argument&) - { - fail (nsl) << "expected " << k << "-expression to evaluate to " - << "'true' or 'false' instead of '" << ns << "'"; - } + catch (const invalid_argument& e) { fail (l) << e.what (); } } } else @@ -1427,16 +1422,14 @@ namespace build2 next (t, tt); const location el (get_location (t)); - names ns (parse_names (t, tt, true, "expression", nullptr)); - // Should evaluate to 'true' or 'false'. - // try { - if (ns.size () != 1) - throw invalid_argument (string ()); - - bool e (convert<bool> (move (ns[0]))); + // Should evaluate to 'true' or 'false'. + // + bool e ( + convert<bool> ( + parse_value (t, tt, "expression", nullptr, true))); e = (neg ? !e : e); if (e) @@ -1449,18 +1442,14 @@ namespace build2 return; } } - catch (const invalid_argument&) - { - fail (el) << "expected assert-expression to evaluate to " - << "'true' or 'false' instead of '" << ns << "'"; - } + catch (const invalid_argument& e) { fail (el) << e.what (); } // Being here means things didn't end up well. Parse the description, if // any, with expansion. Then fail. // - ns = tt != type::newline && tt != type::eos - ? parse_names (t, tt, false, "description", nullptr) - : names (); + names ns (tt != type::newline && tt != type::eos + ? parse_names (t, tt, false, "description", nullptr) + : names ()); diag_record dr (fail (al)); dr << "assertion failed"; diff --git a/tests/directive/assert.test b/tests/directive/assert.test index 80e28ba..f7f2a4f 100644 --- a/tests/directive/assert.test +++ b/tests/directive/assert.test @@ -24,5 +24,5 @@ EOE : invalid : $* <'assert junk' 2>>EOE != 0 -<stdin>:1:8: error: expected assert-expression to evaluate to 'true' or 'false' instead of 'junk' +<stdin>:1:8: error: invalid bool value: 'junk' EOE |