diff options
Diffstat (limited to 'MoonParser/ast.hpp')
-rw-r--r-- | MoonParser/ast.hpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/MoonParser/ast.hpp b/MoonParser/ast.hpp index 1d05779..4d52dfc 100644 --- a/MoonParser/ast.hpp +++ b/MoonParser/ast.hpp | |||
@@ -31,6 +31,12 @@ int ast_type() | |||
31 | return type; | 31 | return type; |
32 | } | 32 | } |
33 | 33 | ||
34 | enum class traversal { | ||
35 | Continue, | ||
36 | Return, | ||
37 | Stop | ||
38 | }; | ||
39 | |||
34 | /** Base class for AST nodes. | 40 | /** Base class for AST nodes. |
35 | */ | 41 | */ |
36 | class ast_node : public input_range { | 42 | class ast_node : public input_range { |
@@ -65,8 +71,19 @@ public: | |||
65 | 71 | ||
66 | /** interface for visiting AST tree use. | 72 | /** interface for visiting AST tree use. |
67 | */ | 73 | */ |
68 | virtual bool visit(const std::function<bool (ast_node*)>& begin, | 74 | virtual traversal traverse(const std::function<traversal (ast_node*)>& func); |
69 | const std::function<bool (ast_node*)>& end); | 75 | |
76 | virtual ast_node* getByPath(std::initializer_list<std::size_t> paths); | ||
77 | |||
78 | virtual void eachChild(const std::function<void (ast_node*)>& func); | ||
79 | |||
80 | virtual bool visitChild(const std::function<bool (ast_node*)>& func); | ||
81 | |||
82 | virtual ast_node* getChild(int) const { return nullptr; } | ||
83 | |||
84 | virtual int getChildCount() const { return 0; } | ||
85 | |||
86 | virtual size_t getId() const { return "ast_node"_id; } | ||
70 | 87 | ||
71 | virtual const char* getName() const { return "ast_node"; } | 88 | virtual const char* getName() const { return "ast_node"; } |
72 | 89 | ||
@@ -140,8 +157,19 @@ public: | |||
140 | */ | 157 | */ |
141 | virtual void construct(ast_stack &st) override; | 158 | virtual void construct(ast_stack &st) override; |
142 | 159 | ||
143 | virtual bool visit(const std::function<bool (ast_node*)>& begin, | 160 | virtual ast_node* getByPath(std::initializer_list<std::size_t> paths) override; |
144 | const std::function<bool (ast_node*)>& end) override; | 161 | |
162 | virtual traversal traverse(const std::function<traversal (ast_node*)>& func) override; | ||
163 | |||
164 | virtual void eachChild(const std::function<void (ast_node*)>& func) override; | ||
165 | |||
166 | virtual bool visitChild(const std::function<bool (ast_node*)>& func) override; | ||
167 | |||
168 | virtual ast_node* getChild(int index) const override; | ||
169 | |||
170 | virtual int getChildCount() const override; | ||
171 | |||
172 | virtual size_t getId() const override { return "ast_container"_id; } | ||
145 | 173 | ||
146 | virtual const char* getName() const override { return "ast_container"; } | 174 | virtual const char* getName() const override { return "ast_container"; } |
147 | private: | 175 | private: |