MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
tok.cpp
Go to the documentation of this file.
1#include "mim/ast/tok.h"
2
3#include <fe/assert.h>
4
5#include "mim/lam.h"
6#include "mim/tuple.h"
7
8namespace mim::ast {
9
10const char* Tok::tag2str(Tok::Tag tag) {
11 switch (tag) {
12#define CODE(t, str) \
13 case Tok::Tag::t: return str;
16#undef CODE
17 case Tag::Nil: fe::unreachable();
18 }
19 fe::unreachable();
20}
21
22std::string Tok::str() const {
23 std::ostringstream oss;
24 oss << *this;
25 return oss.str();
26}
27
28/// @name std::ostream operator
29///@{
30std::ostream& operator<<(std::ostream& os, Tok tok) {
31 if (tok.isa(Tok::Tag::M_anx) || tok.isa(Tok::Tag::M_id) || tok.isa(Tok::Tag::L_str)) return os << tok.sym();
32 return os << Tok::tag2str(tok.tag());
33}
34///@}
35
36} // namespace mim::ast
Sym sym() const
Definition tok.h:178
bool isa(Tag tag) const
Definition tok.h:169
static const char * tag2str(Tok::Tag)
Definition tok.cpp:10
std::string str() const
Definition tok.cpp:22
Tag tag() const
Definition tok.h:170
Definition ast.h:13
std::ostream & operator<<(std::ostream &os, Tok tok)
Definition tok.cpp:30
#define MIM_TOK(m)
Definition tok.h:57
#define MIM_KEY(m)
Definition tok.h:13