From dfb1415d5eaf006ee45235f275d17f52d3db38e5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 18 May 2020 12:06:16 +0300 Subject: Add dump(ostream,script::lines) (partial implementation) --- libbuild2/token.hxx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'libbuild2/token.hxx') diff --git a/libbuild2/token.hxx b/libbuild2/token.hxx index c950ea3..c486193 100644 --- a/libbuild2/token.hxx +++ b/libbuild2/token.hxx @@ -84,13 +84,30 @@ namespace build2 class token; + enum class print_mode + { + // Print eos, newline, and pair separator in the form and other + // tokens as literals, single-quoting the word token. + // + normal, + + // Same as normal but all literals are quoted. + // + diagnostics, + + // Print all tokens as literals with newline represented as '\n' and eos + // as an empty string. + // + raw + }; + LIBBUILD2_SYMEXPORT void - token_printer (ostream&, const token&, bool); + token_printer (ostream&, const token&, print_mode); class token { public: - using printer_type = void (ostream&, const token&, bool diag); + using printer_type = void (ostream&, const token&, print_mode); token_type type; bool separated; // Whitespace-separated from the previous token. @@ -145,7 +162,11 @@ namespace build2 // Output the token value in a format suitable for diagnostics. // inline ostream& - operator<< (ostream& o, const token& t) {t.printer (o, t, true); return o;} + operator<< (ostream& o, const token& t) + { + t.printer (o, t, print_mode::diagnostics); + return o; + } // Context-dependent lexing (see lexer_mode for details). // -- cgit v1.1