-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtok.h
54 lines (39 loc) · 1 KB
/
tok.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
46
47
48
49
50
51
52
53
54
#ifndef _stran_tok_h_
#define _stran_tok_h_
#include <string>
namespace stran {
template <class t> using sp = std::shared_ptr<t>;
template <class t, class u> sp<t> sp_cast(const sp<u> &r) {
t *p = dynamic_cast<t *>(r.get());
return p ? sp<t>(r, p) : sp<t>();
}
template <class t, class... types> sp<t> make_sp(types &&...args) {
return sp<t>(new t(std::forward<types>(args)...));
}
struct tok {
friend std::string to_string(const sp<tok> &p_t) {
return p_t ? static_cast<std::string>(*p_t) : "()";
}
virtual ~tok() {}
private:
virtual operator std::string() const = 0;
};
typedef std::vector<sp<tok>> tok_list;
struct beginl : tok {
private:
operator std::string() const override { return "("; }
};
struct endl : tok {
private:
operator std::string() const override { return ")"; }
};
struct dot : tok {
private:
operator std::string() const override { return "."; }
};
struct apos : tok {
private:
operator std::string() const override { return "'"; }
};
} // namespace stran
#endif