From 2e4ba5a271cb5967feaf4686337e8f63d45acb1f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Dec 2016 16:11:07 +0200 Subject: Use new convert() in if-else, assert parsing --- build2/parser | 5 +++-- build2/parser.cxx | 43 ++++++++++++++++--------------------------- 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 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 ( + parse_value (t, tt, "expression", nullptr))); - bool e (convert (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 (move (ns[0]))); + // Should evaluate to 'true' or 'false'. + // + bool e ( + convert ( + 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 -:1:8: error: expected assert-expression to evaluate to 'true' or 'false' instead of 'junk' +:1:8: error: invalid bool value: 'junk' EOE -- cgit v1.1