aboutsummaryrefslogtreecommitdiff
path: root/build2/token
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-05 11:55:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-05 11:55:15 +0200
commit9fb791e9fad6c63fc1dac49f4d05ae63b8a3db9b (patch)
treed60322d4382ca5f97b676c5abe2e39524f35eab4 /build2/token
parentf159b1dac68c8714f7ba71ca168e3b695891aad9 (diff)
Rename build directory/namespace to build2
Diffstat (limited to 'build2/token')
-rw-r--r--build2/token73
1 files changed, 73 insertions, 0 deletions
diff --git a/build2/token b/build2/token
new file mode 100644
index 0000000..55ab1ee
--- /dev/null
+++ b/build2/token
@@ -0,0 +1,73 @@
+// file : build2/token -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BUILD2_TOKEN
+#define BUILD2_TOKEN
+
+#include <string>
+#include <iosfwd>
+#include <cstddef> // size_t
+#include <cstdint> // uint64_t
+#include <utility> // move
+
+namespace build2
+{
+ enum class token_type
+ {
+ eos,
+ name,
+ newline,
+ pair_separator,
+ colon,
+ lcbrace,
+ rcbrace,
+ equal,
+ equal_plus,
+ plus_equal,
+ dollar,
+ lparen,
+ rparen
+ };
+
+ class token
+ {
+ public:
+ token_type type;
+ bool separated; // Whitespace-separated from the previous token.
+ bool quoted; // Name (or some part of it) was quoted.
+
+ char pair; // Only valid for pair_separator.
+ std::string value; // Only valid for name.
+
+ std::uint64_t line;
+ std::uint64_t column;
+
+ public:
+ token (token_type t, bool s, std::uint64_t l, std::uint64_t c)
+ : type (t), separated (s), quoted (false), line (l), column (c) {}
+
+ token (char p, bool s, std::uint64_t l, std::uint64_t c)
+ : type (token_type::pair_separator),
+ separated (s),
+ quoted (false),
+ pair (p),
+ line (l),
+ column (c) {}
+
+ token (std::string n, bool s, bool q, std::uint64_t l, std::uint64_t c)
+ : type (token_type::name),
+ separated (s),
+ quoted (q),
+ value (std::move (n)),
+ line (l),
+ column (c) {}
+ };
+
+ // Output the token value in a format suitable for diagnostics.
+ //
+ std::ostream&
+ operator<< (std::ostream&, const token&);
+}
+
+#endif // BUILD2_TOKEN