aboutsummaryrefslogtreecommitdiff
path: root/build2/token
blob: c896ba13e4c1a6c3b08155dfd501e1465b20010e (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// file      : build2/token -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD2_TOKEN
#define BUILD2_TOKEN

#include <build2/types>
#include <build2/utility>

namespace build2
{
  enum class token_type
  {
    eos,
    name,
    newline,
    pair_separator,
    colon,
    lcbrace,       // {
    rcbrace,       // }
    lsbrace,       // [
    rsbrace,       // ]
    assign,        // =
    prepend,       // =+
    append,        // +=
    equal,         // ==
    not_equal,     // !=
    less,          // <
    greater,       // >
    less_equal,    // <=
    greater_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.

    string value;   // Only valid for name.

    uint64_t line;
    uint64_t column;

  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) {}
  };

  // Output the token value in a format suitable for diagnostics.
  //
  ostream&
  operator<< (ostream&, const token&);
}

#endif // BUILD2_TOKEN