Bash++
Bash++ compiler internal documentation
Token.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <iostream>
9#include <cstdint>
10
11namespace AST {
12
20template <class T>
21class Token {
22 private:
24 uint32_t line;
25 uint32_t column;
26 public:
27 Token() = default;
28 Token(const T& value, uint32_t line, uint32_t column) : value(value), line(line), column(column) {}
29 const T& getValue() const {
30 return value;
31 }
32 uint32_t getLine() const {
33 return line;
34 }
35 uint32_t getCharPositionInLine() const {
36 return column;
37 }
38
39 void setValue(const T& new_value) {
40 value = new_value;
41 }
42 void setLine(uint32_t new_line) {
43 line = new_line;
44 }
45 void setCharPositionInLine(uint32_t new_column) {
46 column = new_column;
47 }
48
49 operator T() const {
50 return value;
51 }
52 void operator=(const T& new_value) {
53 value = new_value;
54 }
55 void operator+=(const T& append_value) {
56 value += append_value;
57 }
58 bool operator==(const T& other) const {
59 return value == other;
60 }
61 bool operator!=(const T& other) const {
62 return value != other;
63 }
64
65 friend std::ostream& operator<<(std::ostream& os, const Token<T>& token) {
66 os << token.value;
67 return os;
68 }
69};
70
71} // namespace AST
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:21
void setValue(const T &new_value)
Definition Token.h:39
void operator+=(const T &append_value)
Definition Token.h:55
void setCharPositionInLine(uint32_t new_column)
Definition Token.h:45
void setLine(uint32_t new_line)
Definition Token.h:42
bool operator!=(const T &other) const
Definition Token.h:61
void operator=(const T &new_value)
Definition Token.h:52
Token(const T &value, uint32_t line, uint32_t column)
Definition Token.h:28
Token()=default
friend std::ostream & operator<<(std::ostream &os, const Token< T > &token)
Definition Token.h:65
uint32_t getCharPositionInLine() const
Definition Token.h:35
T value
Definition Token.h:23
uint32_t getLine() const
Definition Token.h:32
uint32_t line
Definition Token.h:24
bool operator==(const T &other) const
Definition Token.h:58
const T & getValue() const
Definition Token.h:29
uint32_t column
Definition Token.h:25
Definition AccessModifier.h:8