aboutsummaryrefslogtreecommitdiff
path: root/build2/token
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-04 08:17:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 08:29:22 +0200
commit7efdbab3cd38b7e1693f0a4a85a9933adb50fb9d (patch)
tree85cc082c989123ad173a673a0b499e8904018bf6 /build2/token
parentae579402c8c64ea8ceea2e9fcee5097b3c53e353 (diff)
Handle printing of extended tokens
Diffstat (limited to 'build2/token')
-rw-r--r--build2/token37
1 files changed, 25 insertions, 12 deletions
diff --git a/build2/token b/build2/token
index 04a7ebd..065429c 100644
--- a/build2/token
+++ b/build2/token
@@ -18,6 +18,8 @@ namespace build2
{
enum
{
+ // NOTE: remember to update token_printer()!
+
eos,
name,
newline,
@@ -50,9 +52,16 @@ namespace build2
value_type v_;
};
+ class token;
+
+ void
+ token_printer (ostream&, const token&, bool);
+
class token
{
public:
+ using printer_type = void (ostream&, const token&, bool diag);
+
token_type type;
bool separated; // Whitespace-separated from the previous token.
bool quoted; // Name (or some part of it) was quoted.
@@ -62,23 +71,27 @@ namespace build2
uint64_t line;
uint64_t column;
+ printer_type* printer;
+
public:
- token (token_type t, bool s, uint64_t l, uint64_t c)
- : type (t), separated (s), quoted (false), line (l), column (c) {}
-
- token (string n, bool s, bool q, uint64_t l, uint64_t c)
- : type (token_type::name),
- separated (s),
- quoted (q),
- value (move (n)),
- line (l),
- column (c) {}
+ token ()
+ : token (token_type::eos, false, 0, 0, token_printer) {}
+
+ token (token_type t, bool s, uint64_t l, uint64_t c, printer_type* p)
+ : type (t), separated (s), quoted (false),
+ line (l), column (c),
+ printer (p) {}
+
+ token (string n, bool s, bool q, uint64_t l, uint64_t c, printer_type* p)
+ : type (token_type::name), separated (s), quoted (q), value (move (n)),
+ line (l), column (c),
+ printer (p) {}
};
// Output the token value in a format suitable for diagnostics.
//
- ostream&
- operator<< (ostream&, const token&);
+ inline ostream&
+ operator<< (ostream& o, const token& t) {t.printer (o, t, true); return o;}
// Diagnostics plumbing. We assume that any diag stream for which we can use
// token as location has its aux data pointing to pointer to path.