-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkind.cpp
43 lines (32 loc) · 1 KB
/
kind.cpp
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
#include "kind.hpp"
#include <ostream>
namespace kind {
// constants
any term() { return constant{"*"}; }
any row() { return constant{"..."}; }
any operator>>=(any from, any to) {
return constructor{make_ref<any>(from), make_ref<any>(to)};
}
bool constructor::operator==(const constructor& other) const {
return *from == *other.from && *to == *other.to;
}
namespace {
struct ostream_visitor {
using type = void;
void operator()(const constant& self, std::ostream& out, bool ) const {
out << self.name;
}
void operator()(const constructor& self, std::ostream& out, bool parens) const {
if(parens) out << "(";
self.from->visit(ostream_visitor(), out, true);
out << " -> ";
self.to->visit(ostream_visitor(), out, false);
if(parens) out << ")";
}
};
}
std::ostream& operator<<(std::ostream& out, const any& self) {
self.visit(ostream_visitor(), out, false);
return out;
}
}