diff options
author | Li Jin <dragon-fly@qq.com> | 2019-09-19 01:01:11 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2019-09-19 01:01:11 +0800 |
commit | 42485c6f26b16900b228aeb73907fdbdd9ed17e0 (patch) | |
tree | 4ff846bf7159cd544c5a0ec177d5355a0b916871 /MoonParser/ast.cpp | |
parent | ad0b9c911095b402159f51abe4d98a56d2335973 (diff) | |
download | yuescript-42485c6f26b16900b228aeb73907fdbdd9ed17e0.tar.gz yuescript-42485c6f26b16900b228aeb73907fdbdd9ed17e0.tar.bz2 yuescript-42485c6f26b16900b228aeb73907fdbdd9ed17e0.zip |
spec/class.moon is done.
Diffstat (limited to 'MoonParser/ast.cpp')
-rw-r--r-- | MoonParser/ast.cpp | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/MoonParser/ast.cpp b/MoonParser/ast.cpp index 852593b..7f46bd0 100644 --- a/MoonParser/ast.cpp +++ b/MoonParser/ast.cpp | |||
@@ -14,8 +14,28 @@ traversal ast_node::traverse(const std::function<traversal (ast_node*)>& func) { | |||
14 | return func(this); | 14 | return func(this); |
15 | } | 15 | } |
16 | 16 | ||
17 | ast_node* ast_node::getByPath(std::initializer_list<size_t>) { | 17 | ast_node* ast_node::getByTypeIds(int* begin, int* end) { |
18 | return nullptr; | 18 | ast_node* current = this; |
19 | auto it = begin; | ||
20 | while (it != end) { | ||
21 | ast_node* findNode = nullptr; | ||
22 | int type = *it; | ||
23 | current->visitChild([&](ast_node* node) { | ||
24 | if (node->get_type() == type) { | ||
25 | findNode = node; | ||
26 | return true; | ||
27 | } | ||
28 | return false; | ||
29 | }); | ||
30 | if (findNode) { | ||
31 | current = findNode; | ||
32 | } else { | ||
33 | current = nullptr; | ||
34 | break; | ||
35 | } | ||
36 | ++it; | ||
37 | } | ||
38 | return current; | ||
19 | } | 39 | } |
20 | 40 | ||
21 | bool ast_node::visitChild(const std::function<bool (ast_node*)>&) { | 41 | bool ast_node::visitChild(const std::function<bool (ast_node*)>&) { |
@@ -68,30 +88,6 @@ traversal ast_container::traverse(const std::function<traversal (ast_node*)>& fu | |||
68 | return traversal::Continue; | 88 | return traversal::Continue; |
69 | } | 89 | } |
70 | 90 | ||
71 | ast_node* ast_container::getByPath(std::initializer_list<size_t> paths) { | ||
72 | ast_node* current = this; | ||
73 | auto it = paths.begin(); | ||
74 | while (it != paths.end()) { | ||
75 | ast_node* findNode = nullptr; | ||
76 | size_t id = *it; | ||
77 | current->visitChild([&](ast_node* node) { | ||
78 | if (node->getId() == id) { | ||
79 | findNode = node; | ||
80 | return true; | ||
81 | } | ||
82 | return false; | ||
83 | }); | ||
84 | if (findNode) { | ||
85 | current = findNode; | ||
86 | } else { | ||
87 | current = nullptr; | ||
88 | break; | ||
89 | } | ||
90 | ++it; | ||
91 | } | ||
92 | return current; | ||
93 | } | ||
94 | |||
95 | bool ast_container::visitChild(const std::function<bool (ast_node*)>& func) { | 91 | bool ast_container::visitChild(const std::function<bool (ast_node*)>& func) { |
96 | const auto& members = this->members(); | 92 | const auto& members = this->members(); |
97 | for (auto member : members) { | 93 | for (auto member : members) { |