aboutsummaryrefslogtreecommitdiff
path: root/build/token
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-12-11 13:57:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-12-11 13:57:42 +0200
commite6d92a1fb21232ab09886431d39ccb8a95c7c68d (patch)
tree0d543e1e3c1b22e88f22f02e2dae75ae9eba2db5 /build/token
parentfdc21950905d64b2ca1df5a0b2622022beffe922 (diff)
Initial lexer implementation for buildfiles
Diffstat (limited to 'build/token')
-rw-r--r--build/token55
1 files changed, 55 insertions, 0 deletions
diff --git a/build/token b/build/token
new file mode 100644
index 0000000..bade45c
--- /dev/null
+++ b/build/token
@@ -0,0 +1,55 @@
+// file : build/token -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BUILD_TOKEN
+#define BUILD_TOKEN
+
+#include <string>
+#include <cstddef> // size_t
+#include <cstdint> // uint64_t
+#include <cassert>
+#include <utility> // move
+
+namespace build
+{
+ enum class token_type {eos, name, punctuation};
+ enum class token_punctuation {newline, colon, lcbrace, rcbrace};
+
+ class token
+ {
+ public:
+ token_type
+ type () const {return t_;}
+
+ std::string const&
+ name () const {assert (t_ == token_type::name); return n_;}
+
+ token_punctuation
+ punctuation () const {assert (t_ == token_type::punctuation); return p_;}
+
+ std::uint64_t line () const {return l_;}
+ std::uint64_t column () const {return c_;}
+
+ public:
+ token (std::uint64_t l, std::uint64_t c)
+ : t_ (token_type::eos), l_ (l), c_ (c) {}
+
+ token (std::string n, std::uint64_t l, std::uint64_t c)
+ : t_ (token_type::name), n_ (std::move (n)), l_ (l), c_ (c) {}
+
+ token (token_punctuation p, std::uint64_t l, std::uint64_t c)
+ : t_ (token_type::punctuation), p_ (p), l_ (l), c_ (c) {}
+
+ private:
+ token_type t_;
+
+ token_punctuation p_;
+ std::string n_;
+
+ std::uint64_t l_;
+ std::uint64_t c_;
+ };
+}
+
+#endif // BUILD_TOKEN