ArkScript
A small, fast, functional and scripting language for video games
Token.hpp
Go to the documentation of this file.
1 /**
2  * @file Token.hpp
3  * @author Alexandre Plateau (lexplt.dev@gmail.com)
4  * @brief Token definition for ArkScript
5  * @version 0.1
6  * @date 2021-10-02
7  *
8  * @copyright Copyright (c) 2021
9  *
10  */
11 
12 #ifndef ARK_COMPILER_AST_TOKEN_HPP
13 #define ARK_COMPILER_AST_TOKEN_HPP
14 
15 #include <array>
16 #include <string>
17 #include <string_view>
18 
19 namespace Ark::internal
20 {
21  enum class TokenType
22  {
23  Grouping,
24  String,
25  Number,
26  Operator,
27  Identifier,
28  Capture,
29  GetField,
30  Keyword,
31  Skip,
32  Comment,
33  Shorthand,
34  Spread,
35  Mismatch
36  };
37 
38  // TokenType to string
39  constexpr std::array<std::string_view, 13> tokentype_string = {
40  "Grouping",
41  "String",
42  "Number",
43  "Operator",
44  "Identifier",
45  "Capture",
46  "GetField",
47  "Keyword",
48  "Skip",
49  "Comment",
50  "Shorthand",
51  "Spread",
52  "Mistmatch"
53  };
54 
55  struct Token
56  {
58  std::string token;
59  std::size_t line;
60  std::size_t col;
61 
62  /**
63  * @brief Construct a new Token object
64  *
65  */
66  Token() = default;
67 
68  /**
69  * @brief Construct a new Token object
70  *
71  * @param type the token type
72  * @param tok the token value
73  * @param line the line where we found the token
74  * @param col the column at which was the token
75  */
76  Token(TokenType type, const std::string& tok, std::size_t line, std::size_t col) noexcept :
77  type(type), token(tok), line(line), col(col)
78  {}
79  };
80 }
81 
82 #endif
constexpr std::array< std::string_view, 13 > tokentype_string
Definition: Token.hpp:39
std::size_t line
Definition: Token.hpp:59
Token(TokenType type, const std::string &tok, std::size_t line, std::size_t col) noexcept
Construct a new Token object.
Definition: Token.hpp:76
std::size_t col
Definition: Token.hpp:60
Token()=default
Construct a new Token object.
TokenType type
Definition: Token.hpp:57
std::string token
Definition: Token.hpp:58