diff options
Diffstat (limited to 'libbuild2/token.cxx')
-rw-r--r-- | libbuild2/token.cxx | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/libbuild2/token.cxx b/libbuild2/token.cxx index cfdc6bd..7ce85be 100644 --- a/libbuild2/token.cxx +++ b/libbuild2/token.cxx @@ -8,18 +8,45 @@ 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 << "<end of file>"; break; - case token_type::newline: os << "<newline>"; break; - case token_type::pair_separator: os << "<pair separator " << t.value[0] << ">"; break; - case token_type::word: os << '\'' << t.value << '\''; break; + case token_type::eos: + { + if (!r) + os <<"<end of file>"; + + break; + } + case token_type::newline: + { + os << (r ? "\n" : "<newline>"); + break; + } + case token_type::pair_separator: + { + if (r) + os << t.value[0]; + else + os << "<pair separator " << t.value[0] << ">"; + + 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; |