summaryrefslogtreecommitdiff
path: root/src/token.cc
blob: 3ec3efd7751da541bc85e3cc775f88d2540d9df2 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// This file is part of Cait <https://github.com/Fuwn/cait>.
// Copyright (C) 2022-2022 Fuwn <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

#include "token.hh"

namespace cait {

token::token(std::size_t _line, std::size_t _begin, std::size_t _end,
             const std::string &_word)
    : line(_line), begin(_begin), end(_end), word(_word) {
  switch (utility::hash(_word.c_str())) {
  case utility::hash("rule"): {
    this->type = token_type::rule_declaration;
  } break;
  case utility::hash("command"): {
    this->type = token_type::rule_command;
  } break;
  case utility::hash("depfile"): {
    this->type = token_type::rule_depfile;
  } break;
  case utility::hash("deps"): {
    this->type = token_type::rule_deps;
  } break;
  case utility::hash("msvc_deps_prefix"): {
    this->type = token_type::rule_msvc_deps_prefix;
  } break;
  case utility::hash("description"): {
    this->type = token_type::rule_description;
  } break;
  case utility::hash("dyndep"): {
    this->type = token_type::rule_dyndep;
  } break;
  case utility::hash("generator"): {
    this->type = token_type::rule_generator;
  } break;
  case utility::hash("in"): {
    this->type = token_type::rule_in;
  } break;
  case utility::hash("in_newline"): {
    this->type = token_type::rule_in_newline;
  } break;
  case utility::hash("out"): {
    this->type = token_type::rule_out;
  } break;
  case utility::hash("restat"): {
    this->type = token_type::rule_restat;
  } break;
  case utility::hash("rspfile"): {
    this->type = token_type::rule_rspfile;
  } break;
  case utility::hash("rspfile_content"): {
    this->type = token_type::rule_rspfile_content;
  } break;
  case utility::hash("depth"): {
    this->type = token_type::pool_depth;
  } break;
  case utility::hash("build"): {
    this->type = token_type::build_declaration;
  } break;
  case utility::hash("default"): {
    this->type = token_type::default_declaration;
  } break;
  case utility::hash("pool"): {
    this->type = token_type::pool_declaration;
  } break;
  case utility::hash("subninja"): {
    this->type = token_type::subninja_declaration;
  } break;
  case utility::hash("include"): {
    this->type = token_type::include_declaration;
  } break;
  case utility::hash("="): {
    this->type = token_type::assignment_operator;
  } break;
  default: {
    this->type = token_type::string_literal;
  } break;
  }
}

auto token::with_type(token_type _type) -> token {
  this->type = _type;

  return *this;
}

} // namespace cait