mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Token.hpp
Go to the documentation of this file.
1#pragma once
2
7
8
9namespace m {
10
11namespace ast {
12
13struct Token
14{
18
19 private:
20 explicit Token(TokenType type) : pos(nullptr), text(), type(type) { }
21
22 public:
24 : pos(pos)
25 , text(std::move(text))
26 , type(type)
27 { }
28
29 static Token CreateArtificial(TokenType type = TK_EOF) { return Token(type); }
30
31 operator bool() const { return type != TK_EOF; }
32 operator TokenType() const { return type; }
33
35 friend std::string to_string(const Token &tok) {
36 std::ostringstream os;
37 os << tok;
38 return os.str();
39 }
40
41 friend std::ostream & operator<<(std::ostream &os, const Token &tok) {
42 return os << tok.pos << ", '" << tok.text << "', " << tok.type;
43 }
44
45 void dump(std::ostream &out) const { out << *this << std::endl; }
46 void dump() const;
48};
49
50}
51
52}
‍mutable namespace
Definition: Backend.hpp:10
ThreadSafeStringPool::proxy_type ThreadSafePooledString
Definition: Pool.hpp:464
ThreadSafeStringPool::proxy_optional_type ThreadSafePooledOptionalString
Definition: Pool.hpp:465
TokenType
Definition: TokenType.hpp:10
STL namespace.
void dump(std::ostream &out) const
Definition: Token.hpp:45
M_LCOV_EXCL_START friend std::string to_string(const Token &tok)
Definition: Token.hpp:35
TokenType type
Definition: Token.hpp:17
Token(Position pos, ThreadSafePooledString text, TokenType type)
Definition: Token.hpp:23
ThreadSafePooledOptionalString text
declared as optional for dummy tokens
Definition: Token.hpp:16
static Token CreateArtificial(TokenType type=TK_EOF)
Definition: Token.hpp:29
Token(TokenType type)
Definition: Token.hpp:20
friend std::ostream & operator<<(std::ostream &os, const Token &tok)
Definition: Token.hpp:41
void dump() const
Definition: Token.cpp:9
Position pos
Definition: Token.hpp:15