From 183a0f3d21dce7e50ac001f626c6492c0d36e7a3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Jul 2017 19:33:22 +0200 Subject: Add support for fail, warn, info, text directives --- build2/parser.cxx | 41 ++++++++++++++++++++++++++++++++++++++++- build2/parser.hxx | 3 +++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/build2/parser.cxx b/build2/parser.cxx index 96694c5..0c45e17 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -295,10 +295,17 @@ namespace build2 { f = &parser::parse_assert; } - else if (n == "print") + else if (n == "print") // Unlike text goes to stdout. { f = &parser::parse_print; } + else if (n == "fail" || + n == "warn" || + n == "info" || + n == "text") + { + f = &parser::parse_diag; + } else if (n == "source") { f = &parser::parse_source; @@ -1529,6 +1536,38 @@ namespace build2 next (t, tt); // Swallow newline. } + void parser:: + parse_diag (token& t, type& tt) + { + diag_record dr; + const location l (get_location (t)); + + switch (t.value[0]) + { + case 'f': dr << fail (l); break; + case 'w': dr << warn (l); break; + case 'i': dr << info (l); break; + case 't': dr << text (l); break; + default: assert (false); + } + + // Parse the rest as a variable value to get expansion, attributes, etc. + // + value rhs (parse_variable_value (t, tt)); + + value lhs; + apply_value_attributes (nullptr, lhs, move (rhs), type::assign); + + if (lhs) + { + names storage; + dr << reverse (lhs, storage); + } + + if (tt != type::eos) + next (t, tt); // Swallow newline. + } + string parser:: parse_variable_name (names&& ns, const location& l) { diff --git a/build2/parser.hxx b/build2/parser.hxx index e7afe3a..2ee0a64 100644 --- a/build2/parser.hxx +++ b/build2/parser.hxx @@ -81,6 +81,9 @@ namespace build2 parse_print (token&, token_type&); void + parse_diag (token&, token_type&); + + void parse_source (token&, token_type&); void -- cgit v1.1