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