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;
26 uint32_t column;
27 public:
28 Token() = default;
29 Token(const T& value, uint32_t line, uint32_t column) : value(value), line(line), column(column) {}
30 const T& getValue() const {
31 return value;
32 }
33 uint32_t getLine() const {
34 return line;
35 }
36 uint32_t getCharPositionInLine() const {
37 return column;
38 }
39
40 void setValue(const T& new_value) {
41 value = new_value;
42 }
43 void setLine(uint32_t new_line) {
44 line = new_line;
45 }
46 void setCharPositionInLine(uint32_t new_column) {
47 column = new_column;
48 }
49
50 operator T() const {
51 return value;
52 }
53 void operator=(const T& new_value) {
54 value = new_value;
55 }
56 void operator+=(const T& append_value) {
57 value += append_value;
58 }
59 bool operator==(const T& other) const {
60 return value == other;
61 }
62 bool operator!=(const T& other) const {
63 return value != other;
64 }
65
66 friend std::ostream& operator<<(std::ostream& os, const Token<T>& token) {
67 os << token.value;
68 return os;
69 }
70};
71
72} // 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
void setValue(const T &new_value)
Definition Token.h:40
void operator+=(const T &append_value)
Definition Token.h:56
void setCharPositionInLine(uint32_t new_column)
Definition Token.h:46
void setLine(uint32_t new_line)
Definition Token.h:43
bool operator!=(const T &other) const
Definition Token.h:62
void operator=(const T &new_value)
Definition Token.h:53
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:66
uint32_t getCharPositionInLine() const
Definition Token.h:36
T value
Definition Token.h:24
uint32_t getLine() const
Definition Token.h:33
uint32_t line
Definition Token.h:25
bool operator==(const T &other) const
Definition Token.h:59
const T & getValue() const
Definition Token.h:30
uint32_t column
Definition Token.h:26
Definition AccessModifier.h:9