aboutsummaryrefslogtreecommitdiff
path: root/build/token
blob: 9f9b2b4a94c9e03026e40170d7c53eb59a86b4d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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,
    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_;}

    std::uint64_t line () const {return l_;}
    std::uint64_t column () const {return c_;}

  public:
    token (token_type t, std::uint64_t l, std::uint64_t c)
        : t_ (t), 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) {}

  private:
    token_type t_;
    std::string n_;

    std::uint64_t l_;
    std::uint64_t c_;
  };
}

#endif // BUILD_TOKEN