// file : build/token -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef BUILD_TOKEN #define BUILD_TOKEN #include <string> #include <iosfwd> #include <cstddef> // size_t #include <cstdint> // uint64_t #include <cassert> #include <utility> // move namespace build { enum class token_type { eos, name, newline, pair_separator, colon, lcbrace, rcbrace, equal, plus_equal, dollar, lparen, rparen }; class token { public: token_type type () const {return t_;} // Token is whitespace-separated from the previous token. // bool separated () const {return s_;} std::string const& name () const {assert (t_ == token_type::name); return n_;} std::uint64_t line () const {return l_;} std::uint64_t column () const {return c_;} public: token (token_type t, bool s, std::uint64_t l, std::uint64_t c) : t_ (t), s_ (s), l_ (l), c_ (c) {} token (std::string n, bool s, std::uint64_t l, std::uint64_t c) : t_ (token_type::name), s_ (s), n_ (std::move (n)), l_ (l), c_ (c) {} private: token_type t_; bool s_; std::string n_; std::uint64_t l_; std::uint64_t c_; }; // Output the token value in a format suitable for diagnostics. // std::ostream& operator<< (std::ostream&, const token&); } #endif // BUILD_TOKEN