1 #ifndef INCLUDE_INJA_NODE_HPP_
2 #define INCLUDE_INJA_NODE_HPP_
8 #include "function_storage.hpp"
20 class ExpressionListNode;
22 class ForStatementNode;
23 class ForArrayStatementNode;
24 class ForObjectStatementNode;
25 class IfStatementNode;
26 class IncludeStatementNode;
27 class ExtendsStatementNode;
28 class BlockStatementNode;
29 class SetStatementNode;
35 virtual void visit(
const BlockNode& node) = 0;
36 virtual void visit(
const TextNode& node) = 0;
39 virtual void visit(
const DataNode& node) = 0;
62 AstNode(
size_t pos): pos(pos) {}
68 std::vector<std::shared_ptr<AstNode>> nodes;
81 explicit TextNode(
size_t pos,
size_t length):
AstNode(pos), length(length) {}
110 const std::string name;
111 const json::json_pointer ptr;
113 static std::string convert_dot_to_ptr(std::string_view ptr_name) {
116 std::string_view part;
117 std::tie(part, ptr_name) = string_view::split(ptr_name,
'.');
118 result.push_back(
'/');
119 result.append(part.begin(), part.end());
120 }
while (!ptr_name.empty());
124 explicit DataNode(std::string_view ptr_name,
size_t pos):
ExpressionNode(pos), name(ptr_name), ptr(json::json_pointer(convert_dot_to_ptr(ptr_name))) {}
132 using Op = FunctionStorage::Operation;
135 enum class Associativity {
140 unsigned int precedence;
141 Associativity associativity;
147 std::vector<std::shared_ptr<ExpressionNode>> arguments;
148 CallbackFunction callback;
150 explicit FunctionNode(std::string_view name,
size_t pos)
151 :
ExpressionNode(pos), precedence(8), associativity(Associativity::Left), operation(Op::Callback), name(name), number_args(0) {}
157 associativity = Associativity::Left;
162 associativity = Associativity::Left;
167 associativity = Associativity::Left;
172 associativity = Associativity::Left;
177 associativity = Associativity::Left;
182 associativity = Associativity::Left;
187 associativity = Associativity::Left;
189 case Op::GreaterEqual: {
192 associativity = Associativity::Left;
197 associativity = Associativity::Left;
199 case Op::LessEqual: {
202 associativity = Associativity::Left;
207 associativity = Associativity::Left;
212 associativity = Associativity::Left;
214 case Op::Multiplication: {
217 associativity = Associativity::Left;
222 associativity = Associativity::Left;
227 associativity = Associativity::Right;
232 associativity = Associativity::Left;
237 associativity = Associativity::Left;
241 associativity = Associativity::Left;
253 std::shared_ptr<ExpressionNode> root;
283 const std::string value;
294 const std::string key;
295 const std::string value;
312 const bool is_nested;
313 bool has_false_statement {
false};
325 const std::string file;
336 const std::string file;
347 const std::string name;
360 const std::string key;
Base node class for the abstract syntax tree (AST).
Definition: node.hpp:56