diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-10-14 10:39:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-10-14 11:57:28 +0200 |
commit | 3a2969cf54fb21273b7949095c709f6aa9a2a6d9 (patch) | |
tree | 280611d6fa951589dbd9faa165b31df8dbf364af | |
parent | 51aabbc8814c229e48c02836a32c402834c3425e (diff) |
Pass along parse_names_result during script command parsing
-rw-r--r-- | libbuild2/build/script/parser.cxx | 18 | ||||
-rw-r--r-- | libbuild2/build/script/parser.hxx | 5 | ||||
-rw-r--r-- | libbuild2/script/parser.cxx | 33 | ||||
-rw-r--r-- | libbuild2/script/parser.hxx | 6 |
4 files changed, 34 insertions, 28 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx index e55eca1..217fa11 100644 --- a/libbuild2/build/script/parser.cxx +++ b/libbuild2/build/script/parser.cxx @@ -356,9 +356,8 @@ namespace build2 optional<process_path> parser:: parse_program (token& t, build2::script::token_type& tt, - bool first, - bool env, - names& ns) + bool first, bool env, + names& ns, parse_names_result& pr) { const location l (get_location (t)); @@ -588,7 +587,6 @@ namespace build2 << "with the 'diag' builtin"; }; - parse_names_result pr; { // During pre-parse, if the script name is not set manually we // suspend pre-parse, parse the command names for real and try to @@ -692,10 +690,12 @@ namespace build2 // syntactic cases to the typed ones. // names pp_ns; + const value_type* pp_vt (nullptr); if (pr.type == &value_traits<process_path>::value_type || pr.type == &value_traits<process_path_ex>::value_type) { pp_ns = move (ns); + pp_vt = pr.type; ns.clear (); } else if (ns[0].file ()) @@ -711,9 +711,9 @@ namespace build2 ns.erase (b, i); - pr.type = i != b + 1 - ? &value_traits<process_path_ex>::value_type - : &value_traits<process_path>::value_type; + pp_vt = (i != b + 1 + ? &value_traits<process_path_ex>::value_type + : &value_traits<process_path>::value_type); } } @@ -723,7 +723,7 @@ namespace build2 // $cxx.path ... // }} // - if (pr.type == &value_traits<process_path>::value_type) + if (pp_vt == &value_traits<process_path>::value_type) { auto pp (convert<process_path> (move (pp_ns))); @@ -737,7 +737,7 @@ namespace build2 else return optional<process_path> (move (pp)); } - else if (pr.type == &value_traits<process_path_ex>::value_type) + else if (pp_vt == &value_traits<process_path_ex>::value_type) { auto pp (convert<process_path_ex> (move (pp_ns))); diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx index e744c08..09a349f 100644 --- a/libbuild2/build/script/parser.hxx +++ b/libbuild2/build/script/parser.hxx @@ -150,9 +150,8 @@ namespace build2 // virtual optional<process_path> parse_program (token&, build2::script::token_type&, - bool first, - bool env, - names&) override; + bool first, bool env, + names&, parse_names_result&) override; protected: script* script_; diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx index f234d58..b0431a9 100644 --- a/libbuild2/script/parser.cxx +++ b/libbuild2/script/parser.cxx @@ -97,14 +97,16 @@ namespace build2 } optional<process_path> parser:: - parse_program (token& t, type& tt, bool, bool, names& ns) + parse_program (token& t, type& tt, + bool, bool, + names& ns, parse_names_result& pr) { - parse_names (t, tt, - ns, - pattern_mode::ignore, - true /* chunk */, - "command line", - nullptr); + pr = parse_names (t, tt, + ns, + pattern_mode::ignore, + true /* chunk */, + "command line", + nullptr); return nullopt; } @@ -1048,10 +1050,13 @@ namespace build2 // reset_quoted (t); + parse_names_result pr; if (prog) { optional<process_path> pp ( - parse_program (t, tt, p == pending::program_first, env, ns)); + parse_program (t, tt, + p == pending::program_first, env, + ns, pr)); // During pre-parsing we are not interested in the // parse_program() call result, so just discard the potentially @@ -1072,12 +1077,12 @@ namespace build2 } } else - parse_names (t, tt, - ns, - pattern_mode::ignore, - true /* chunk */, - "command line", - nullptr); + pr = parse_names (t, tt, + ns, + pattern_mode::ignore, + true /* chunk */, + "command line", + nullptr); // Nothing else to do if we are pre-parsing. // diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx index 2a10311..077cb22 100644 --- a/libbuild2/script/parser.hxx +++ b/libbuild2/script/parser.hxx @@ -188,7 +188,7 @@ namespace build2 // During the execution phase try to parse and translate the leading // names into the process path and return nullopt if choose not to do // so, leaving it to the parser to handle. Also return in the last - // argument uninterpreted names, if any. + // two arguments uninterpreted names, if any. // // The default implementation always returns nullopt. The derived parser // can provide an override that can, for example, handle process path @@ -206,7 +206,9 @@ namespace build2 // recognize and execute certain directives, or some such. // virtual optional<process_path> - parse_program (token&, token_type&, bool first, bool env, names&); + parse_program (token&, token_type&, + bool first, bool env, + names&, parse_names_result&); // Set lexer pointers for both the current and the base classes. // |