-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathToken.ostream.h
45 lines (41 loc) · 1.21 KB
/
Token.ostream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "Token.h"
#include <ostream>
namespace Token {
inline auto operator<<(std::ostream &out, const Num &num) -> std::ostream & {
return out << "Num{" << num.value << '}';
}
inline auto operator<<(std::ostream &out, const Id &id) -> std::ostream & {
return out << "Id{\"" << id.name << "\"}";
}
inline auto operator<<(std::ostream &out, const Simple &simple) -> std::ostream & {
switch (simple) {
case Var: return out << "Var";
case Assign: return out << "Assign";
case Add: return out << "Add";
case Multiply: return out << "Multiply";
}
return out << "Tok::<unknown>";
}
inline auto operator<<(std::ostream &out, const Token &t) -> std::ostream & {
return std::visit([&](auto &&e) -> std::ostream & { return out << e; }, t);
}
inline auto operator<<(std::ostream &out, Span ts) -> std::ostream & {
if (ts.empty()) {
return out;
}
out << ts.front();
ts = ts.subspan(1);
for (auto &t : ts) {
out << ", " << t;
}
return out;
}
template<size_t N>
inline auto operator<<(std::ostream &out, const std::array<Vec, N> &lines) -> std::ostream & {
for (auto &l : lines) {
out << l << '\n';
}
return out;
}
} // namespace Token