gfy-cpp
Loading...
Searching...
No Matches
token.hpp
Go to the documentation of this file.
1#ifndef __TOKEN_HPP__
2#define __TOKEN_HPP__
3
4#include <string>
5#include <tuple>
6
7using namespace std;
8
12enum class Type {
13 Module,
14 Keyword,
18 Bracket,
19 Int,
20 Float,
21 String,
22 Boolean,
23 List,
24 Eof,
26};
27
28class Token {
29 public:
39 Type type,
40 const string& text,
41 const string& file,
42 tuple<int, int> position
44
50 Type get_type();
51
57 string get_text();
58
64 string get_file();
65
71 tuple<int, int> get_position();
72
78 int get_line();
79
85 int get_column();
86
92 string to_string() const;
93
94 private:
96 string text;
97 string file;
98 tuple<int, int> position;
99};
100
106string type2str(Type type);
107
108#endif // __TOKEN_HPP__
Definition token.hpp:28
int get_column()
Get token column number.
Definition token.cpp:32
int get_line()
Get token line number.
Definition token.cpp:28
Token(Type type, const string &text, const string &file, tuple< int, int > position)
Construct a new Token object.
Definition token.hpp:38
string file
Definition token.hpp:97
Type type
Definition token.hpp:95
Type get_type()
Type getter.
Definition token.cpp:12
string text
Definition token.hpp:96
tuple< int, int > get_position()
Position getter.
Definition token.cpp:24
string get_text()
Text getter.
Definition token.cpp:16
tuple< int, int > position
Definition token.hpp:98
string to_string() const
Stringify the token.
Definition token.cpp:5
string get_file()
File getter.
Definition token.cpp:20
Type
Token types.
Definition token.hpp:12
@ Keyword
@ String
@ Boolean
@ Identifier
@ Parenthesis
@ Unknown
@ Bracket
@ Operator
@ Module
string type2str(Type type)
Convert a type to a string.
Definition token.cpp:36