diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-03 16:38:23 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-04 14:20:33 +0300 |
commit | d280946474568925016359be742b59fd6c000c52 (patch) | |
tree | 5b48a599c33f442867dfa32690e141883af0322d /libbuild2/build/script/parser.hxx | |
parent | f50d0d58c8eb659e803282e19cf15398e3a8e373 (diff) |
Properly handle diag directive in build script parser
Diffstat (limited to 'libbuild2/build/script/parser.hxx')
-rw-r--r-- | libbuild2/build/script/parser.hxx | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx index 15d4ede..4b98cbc 100644 --- a/libbuild2/build/script/parser.hxx +++ b/libbuild2/build/script/parser.hxx @@ -36,7 +36,7 @@ namespace build2 script pre_parse (const target&, istream&, const path_name&, uint64_t line, - optional<string> diag, const location& diag_loc); + optional<string> diag_name, const location& diag_loc); // Recursive descent parser. // @@ -67,6 +67,16 @@ namespace build2 execute (const scope& root, const scope& base, environment&, const script&, runner&); + // Parse a special builtin line into names, performing the variable + // and pattern expansions. If omit_builtin is true, then omit the + // builtin name from the result. + // + names + execute_special (const scope& root, const scope& base, + environment&, + const line&, + bool omit_builtin = true); + protected: void exec_script (); @@ -87,24 +97,28 @@ namespace build2 // leaving the rest for the base parser to handle. // // During pre-parsing try to deduce the low-verbosity script - // diagnostics name. + // diagnostics name as a program/builtin name or obtain the custom + // low-verbosity diagnostics specified with the diag builtin. Note + // that the diag builtin can only appear at the beginning of the + // command line. // virtual optional<process_path> - parse_program (token&, build2::script::token_type&, names&) override; - - void - parse_program_diag (token&, build2::script::token_type&, names&); + parse_program (token&, build2::script::token_type&, + bool first, + names&) override; protected: script* script_; - // Current low-verbosity script diagnostics name and weight. + // Current low-verbosity script diagnostics and its weight. // // During pre-parsing each command leading names are translated into a - // potential script name, unless it is set manually (with the diag - // directive or via the constructor). The potential script name has a - // weight associated with it, so script names with greater weights - // override names with lesser weights. The possible weights are: + // potential low-verbosity script diagnostics name, unless the + // diagnostics is set manually (script name via the constructor or + // custom diagnostics via the diag builtin). The potential script + // name has a weight associated with it, so script names with greater + // weights override names with lesser weights. The possible weights + // are: // // 0 - builtins that do not add to the script semantics (exit, // true, etc) and are never picked up as a script name @@ -119,8 +133,20 @@ namespace build2 // then this ambiguity is reported unless a higher-weighted name is // encountered later. // - optional<pair<string, location>> diag; - optional<pair<string, location>> diag2; + // If the diag builtin is encountered, then its whole line is saved + // (including the leading 'diag' word) for later execution and the + // diagnostics weight is set to 4. + // + // Any attempt to manually set the custom diagnostics twice (the diag + // builtin after the script name or after another diag builtin) is + // reported as ambiguity. + // + // At the end of pre-parsing either diag_name or diag_line (but not + // both) are present. + // + optional<pair<string, location>> diag_name; + optional<pair<string, location>> diag_name2; // Ambiguous script name. + optional<pair<line, location>> diag_line; uint8_t diag_weight = 0; // True during pre-parsing when the pre-parse mode is temporarily @@ -128,6 +154,15 @@ namespace build2 // bool pre_parse_suspended_ = false; + // The alternative location where the next line should be saved. + // + // It is set to NULL before the script line get parsed, indicating + // that the line should by default be appended to the script. However, + // parse_program() can point it to a different location where the line + // should be saved instead (e.g., diag_line, etc). + // + line* save_line_; + // Execute state. // runner* runner_; |