aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/moon_ast.h
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2018-03-05 14:18:35 +0800
committerLi Jin <dragon-fly@qq.com>2018-03-05 14:18:35 +0800
commit525591758ce178e44da6aa3a11d557fd75b232e7 (patch)
tree27a2eaef7a47697888ad16ec5b27b9aee999ab71 /MoonParser/moon_ast.h
parent3b270690501cfcc9220c8d5b63ab6f13fc2bd6b0 (diff)
downloadyuescript-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.h21
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
5template<class Facet> 5input& trim(input& s);
6struct deletable_facet : Facet
7{
8 template<class ...Args>
9 deletable_facet(Args&& ...args): Facet(std::forward<Args>(args)...) {}
10 ~deletable_facet() {}
11};
12typedef std::wstring_convert<deletable_facet<std::codecvt<char32_t, char, std::mbstate_t>>, char32_t> Converter;
13
14std::string& trim(std::string& s);
15 6
16class AstLeaf : public ast_node 7class AstLeaf : public ast_node
17{ 8{
18public: 9public:
19 const std::string& getValue(); 10 const input& getValue();
20private: 11private:
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; \
26class type##_t : public AstLeaf \ 17class type##_t : public AstLeaf \
27{ \ 18{ \
28public: \ 19public: \
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) \
32extern rule type; \ 24extern rule type; \
33class type##_t : public ast_container \ 25class type##_t : public ast_container \
34{ \ 26{ \
35public: \ 27public: \
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};