diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-14 11:25:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-14 11:25:04 +0200 |
commit | 60c2c496357d3259c2fb29f7e2f1c3804eb5ad33 (patch) | |
tree | e9267dc523ce684ab177d56829e23c9b37b8b556 /libbuild2/parser.cxx | |
parent | 14485a1ebe8daccf80498efbb0b88a6ab2021fa2 (diff) |
Add parser::parse_eval() public API function
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r-- | libbuild2/parser.cxx | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index f42666b..9fbcd2b 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -355,6 +355,50 @@ namespace build2 return make_pair (move (lhs), move (t)); } + value parser:: + parse_eval (lexer& l, scope& rs, scope& bs, pattern_mode pmode) + { + path_ = &l.name (); + lexer_ = &l; + + root_ = &rs; + scope_ = &bs; + target_ = nullptr; + prerequisite_ = nullptr; + + pbase_ = scope_->src_path_; + + // Note that root_ may not be a project root. + // + auto_project_env penv ( + stage_ != stage::boot && root_ != nullptr && root_->root_extra != nullptr + ? auto_project_env (*root_) + : auto_project_env ()); + + token t; + type tt; + next (t, tt); + + if (tt != type::lparen) + fail (t) << "expected '(' instead of " << t; + + location loc (get_location (t)); + mode (lexer_mode::eval, '@'); + next_with_attributes (t, tt); + + values vs (parse_eval (t, tt, pmode)); + + if (next (t, tt) != type::eos) + fail (t) << "unexpected " << t; + + switch (vs.size ()) + { + case 0: return value (names ()); + case 1: return move (vs[0]); + default: fail (loc) << "expected single value" << endf; + } + } + bool parser:: parse_clause (token& t, type& tt, bool one) { |