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 (
[email protected]
)
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
{
57
TokenType
type
;
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
Ark::internal
Definition:
Builtins.hpp:26
Ark::internal::tokentype_string
constexpr std::array< std::string_view, 13 > tokentype_string
Definition:
Token.hpp:39
Ark::internal::Keyword
Keyword
The different keywords available.
Definition:
Common.hpp:59
Ark::internal::TokenType
TokenType
Definition:
Token.hpp:22
Ark::internal::TokenType::Grouping
@ Grouping
Ark::internal::TokenType::Comment
@ Comment
Ark::internal::TokenType::Spread
@ Spread
Ark::internal::TokenType::String
@ String
Ark::internal::TokenType::Identifier
@ Identifier
Ark::internal::TokenType::Capture
@ Capture
Ark::internal::TokenType::Mismatch
@ Mismatch
Ark::internal::TokenType::Skip
@ Skip
Ark::internal::TokenType::Shorthand
@ Shorthand
Ark::internal::TokenType::Number
@ Number
Ark::internal::TokenType::GetField
@ GetField
Ark::internal::TokenType::Operator
@ Operator
Ark::internal::Token
Definition:
Token.hpp:56
Ark::internal::Token::line
std::size_t line
Definition:
Token.hpp:59
Ark::internal::Token::Token
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
Ark::internal::Token::col
std::size_t col
Definition:
Token.hpp:60
Ark::internal::Token::Token
Token()=default
Construct a new Token object.
Ark::internal::Token::type
TokenType type
Definition:
Token.hpp:57
Ark::internal::Token::token
std::string token
Definition:
Token.hpp:58
include
Ark
Compiler
AST
Token.hpp
Generated on Sun Apr 23 2023 20:17:28 for ArkScript by
1.9.6