diff options
author | Li Jin <dragon-fly@qq.com> | 2018-03-05 14:18:35 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2018-03-05 14:18:35 +0800 |
commit | 525591758ce178e44da6aa3a11d557fd75b232e7 (patch) | |
tree | 27a2eaef7a47697888ad16ec5b27b9aee999ab71 /MoonParser/moon_ast.h | |
parent | 3b270690501cfcc9220c8d5b63ab6f13fc2bd6b0 (diff) | |
download | yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.tar.gz yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.tar.bz2 yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.zip |
refactoring some codes.
Diffstat (limited to 'MoonParser/moon_ast.h')
-rw-r--r-- | MoonParser/moon_ast.h | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/MoonParser/moon_ast.h b/MoonParser/moon_ast.h index 7a0e805..4511b1b 100644 --- a/MoonParser/moon_ast.h +++ b/MoonParser/moon_ast.h | |||
@@ -2,23 +2,14 @@ | |||
2 | 2 | ||
3 | #include "moon_parser.h" | 3 | #include "moon_parser.h" |
4 | 4 | ||
5 | template<class Facet> | 5 | input& trim(input& s); |
6 | struct deletable_facet : Facet | ||
7 | { | ||
8 | template<class ...Args> | ||
9 | deletable_facet(Args&& ...args): Facet(std::forward<Args>(args)...) {} | ||
10 | ~deletable_facet() {} | ||
11 | }; | ||
12 | typedef std::wstring_convert<deletable_facet<std::codecvt<char32_t, char, std::mbstate_t>>, char32_t> Converter; | ||
13 | |||
14 | std::string& trim(std::string& s); | ||
15 | 6 | ||
16 | class AstLeaf : public ast_node | 7 | class AstLeaf : public ast_node |
17 | { | 8 | { |
18 | public: | 9 | public: |
19 | const std::string& getValue(); | 10 | const input& getValue(); |
20 | private: | 11 | private: |
21 | std::string _value; | 12 | input _value; |
22 | }; | 13 | }; |
23 | 14 | ||
24 | #define AST_LEAF(type) \ | 15 | #define AST_LEAF(type) \ |
@@ -26,14 +17,16 @@ extern rule type; \ | |||
26 | class type##_t : public AstLeaf \ | 17 | class type##_t : public AstLeaf \ |
27 | { \ | 18 | { \ |
28 | public: \ | 19 | public: \ |
29 | virtual int get_type() override { return ast_type<type##_t>(); } | 20 | virtual int get_type() override { return ast_type<type##_t>(); } \ |
21 | virtual const char* getName() const override { return #type; } | ||
30 | 22 | ||
31 | #define AST_NODE(type) \ | 23 | #define AST_NODE(type) \ |
32 | extern rule type; \ | 24 | extern rule type; \ |
33 | class type##_t : public ast_container \ | 25 | class type##_t : public ast_container \ |
34 | { \ | 26 | { \ |
35 | public: \ | 27 | public: \ |
36 | virtual int get_type() override { return ast_type<type##_t>(); } | 28 | virtual int get_type() override { return ast_type<type##_t>(); } \ |
29 | virtual const char* getName() const override { return #type; } | ||
37 | 30 | ||
38 | #define AST_END(type) \ | 31 | #define AST_END(type) \ |
39 | }; | 32 | }; |