From b808c255b6a9ddba085bf5646e7d20ec344f2e2d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 28 Apr 2020 08:48:53 +0200 Subject: Initial support for ad hoc recipes (still work in progress) --- libbuild2/token.cxx | 109 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 39 deletions(-) (limited to 'libbuild2/token.cxx') diff --git a/libbuild2/token.cxx b/libbuild2/token.cxx index 4975a02..7ce85be 100644 --- a/libbuild2/token.cxx +++ b/libbuild2/token.cxx @@ -8,51 +8,82 @@ using namespace std; namespace build2 { void - token_printer (ostream& os, const token& t, bool d) + token_printer (ostream& os, const token& t, print_mode m) { // Only quote non-name tokens for diagnostics. // - const char* q (d ? "'" : ""); + const char* q (m == print_mode::diagnostics ? "'" : ""); + bool r (m == print_mode::raw); switch (t.type) { - case token_type::eos: os << ""; break; - case token_type::newline: os << ""; break; - case token_type::pair_separator: os << ""; break; - case token_type::word: os << '\'' << t.value << '\''; break; - - case token_type::colon: os << q << ':' << q; break; - case token_type::dollar: os << q << '$' << q; break; - case token_type::question: os << q << '?' << q; break; - case token_type::comma: os << q << ',' << q; break; - - case token_type::lparen: os << q << '(' << q; break; - case token_type::rparen: os << q << ')' << q; break; - - case token_type::lcbrace: os << q << '{' << q; break; - case token_type::rcbrace: os << q << '}' << q; break; - - case token_type::lsbrace: os << q << '[' << q; break; - case token_type::rsbrace: os << q << ']' << q; break; - - case token_type::labrace: os << q << '<' << q; break; - case token_type::rabrace: os << q << '>' << q; break; - - case token_type::assign: os << q << '=' << q; break; - case token_type::prepend: os << q << "=+" << q; break; - case token_type::append: os << q << "+=" << q; break; - case token_type::default_assign: os << q << "?=" << q; break; - - case token_type::equal: os << q << "==" << q; break; - case token_type::not_equal: os << q << "!=" << q; break; - case token_type::less: os << q << '<' << q; break; - case token_type::greater: os << q << '>' << q; break; - case token_type::less_equal: os << q << "<=" << q; break; - case token_type::greater_equal: os << q << ">=" << q; break; - - case token_type::log_or: os << q << "||" << q; break; - case token_type::log_and: os << q << "&&" << q; break; - case token_type::log_not: os << q << '!' << q; break; + case token_type::eos: + { + if (!r) + os <<""; + + break; + } + case token_type::newline: + { + os << (r ? "\n" : ""); + break; + } + case token_type::pair_separator: + { + if (r) + os << t.value[0]; + else + os << ""; + + break; + } + case token_type::word: + { + if (r) + os << t.value; + else + os << '\'' << t.value << '\''; + + break; + } + + case token_type::colon: os << q << ':' << q; break; + case token_type::dollar: os << q << '$' << q; break; + case token_type::question: os << q << '?' << q; break; + case token_type::percent: os << q << '%' << q; break; + case token_type::comma: os << q << ',' << q; break; + + case token_type::lparen: os << q << '(' << q; break; + case token_type::rparen: os << q << ')' << q; break; + + case token_type::lcbrace: os << q << '{' << q; break; + case token_type::rcbrace: os << q << '}' << q; break; + + case token_type::multi_lcbrace: os << q << t.value << q; break; + case token_type::multi_rcbrace: os << q << t.value << q; break; + + case token_type::lsbrace: os << q << '[' << q; break; + case token_type::rsbrace: os << q << ']' << q; break; + + case token_type::labrace: os << q << '<' << q; break; + case token_type::rabrace: os << q << '>' << q; break; + + case token_type::assign: os << q << '=' << q; break; + case token_type::prepend: os << q << "=+" << q; break; + case token_type::append: os << q << "+=" << q; break; + case token_type::default_assign: os << q << "?=" << q; break; + + case token_type::equal: os << q << "==" << q; break; + case token_type::not_equal: os << q << "!=" << q; break; + case token_type::less: os << q << '<' << q; break; + case token_type::greater: os << q << '>' << q; break; + case token_type::less_equal: os << q << "<=" << q; break; + case token_type::greater_equal: os << q << ">=" << q; break; + + case token_type::log_or: os << q << "||" << q; break; + case token_type::log_and: os << q << "&&" << q; break; + case token_type::log_not: os << q << '!' << q; break; default: assert (false); // Unhandled extended token. } -- cgit v1.1