mirror of
https://github.com/pantor/inja.git
synced 2026-04-29 18:49:26 +00:00
clang-format
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include "function_storage.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
|
||||
namespace inja {
|
||||
|
||||
class NodeVisitor;
|
||||
@@ -29,7 +28,6 @@ class ExtendsStatementNode;
|
||||
class BlockStatementNode;
|
||||
class SetStatementNode;
|
||||
|
||||
|
||||
class NodeVisitor {
|
||||
public:
|
||||
virtual ~NodeVisitor() = default;
|
||||
@@ -61,16 +59,15 @@ public:
|
||||
|
||||
size_t pos;
|
||||
|
||||
AstNode(size_t pos) : pos(pos) { }
|
||||
virtual ~AstNode() { }
|
||||
AstNode(size_t pos): pos(pos) {}
|
||||
virtual ~AstNode() {}
|
||||
};
|
||||
|
||||
|
||||
class BlockNode : public AstNode {
|
||||
public:
|
||||
std::vector<std::shared_ptr<AstNode>> nodes;
|
||||
|
||||
explicit BlockNode() : AstNode(0) {}
|
||||
explicit BlockNode(): AstNode(0) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -81,7 +78,7 @@ class TextNode : public AstNode {
|
||||
public:
|
||||
const size_t length;
|
||||
|
||||
explicit TextNode(size_t pos, size_t length): AstNode(pos), length(length) { }
|
||||
explicit TextNode(size_t pos, size_t length): AstNode(pos), length(length) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -90,7 +87,7 @@ public:
|
||||
|
||||
class ExpressionNode : public AstNode {
|
||||
public:
|
||||
explicit ExpressionNode(size_t pos) : AstNode(pos) {}
|
||||
explicit ExpressionNode(size_t pos): AstNode(pos) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -101,7 +98,7 @@ class LiteralNode : public ExpressionNode {
|
||||
public:
|
||||
const json value;
|
||||
|
||||
explicit LiteralNode(std::string_view data_text, size_t pos) : ExpressionNode(pos), value(json::parse(data_text)) { }
|
||||
explicit LiteralNode(std::string_view data_text, size_t pos): ExpressionNode(pos), value(json::parse(data_text)) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -124,7 +121,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
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))) { }
|
||||
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))) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -150,98 +147,99 @@ public:
|
||||
std::vector<std::shared_ptr<ExpressionNode>> arguments;
|
||||
CallbackFunction callback;
|
||||
|
||||
explicit FunctionNode(std::string_view name, size_t pos) : ExpressionNode(pos), precedence(8), associativity(Associativity::Left), operation(Op::Callback), name(name), number_args(1) { }
|
||||
explicit FunctionNode(Op operation, size_t pos) : ExpressionNode(pos), operation(operation), number_args(1) {
|
||||
explicit FunctionNode(std::string_view name, size_t pos)
|
||||
: ExpressionNode(pos), precedence(8), associativity(Associativity::Left), operation(Op::Callback), name(name), number_args(1) {}
|
||||
explicit FunctionNode(Op operation, size_t pos): ExpressionNode(pos), operation(operation), number_args(1) {
|
||||
switch (operation) {
|
||||
case Op::Not: {
|
||||
number_args = 1;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::And: {
|
||||
number_args = 2;
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Or: {
|
||||
number_args = 2;
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::In: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Equal: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::NotEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Greater: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::GreaterEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Less: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::LessEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Add: {
|
||||
number_args = 2;
|
||||
precedence = 3;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Subtract: {
|
||||
number_args = 2;
|
||||
precedence = 3;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Multiplication: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Division: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Power: {
|
||||
number_args = 2;
|
||||
precedence = 5;
|
||||
associativity = Associativity::Right;
|
||||
} break;
|
||||
case Op::Modulo: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::AtId: {
|
||||
number_args = 2;
|
||||
precedence = 8;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
default: {
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
}
|
||||
case Op::Not: {
|
||||
number_args = 1;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::And: {
|
||||
number_args = 2;
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Or: {
|
||||
number_args = 2;
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::In: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Equal: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::NotEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Greater: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::GreaterEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Less: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::LessEqual: {
|
||||
number_args = 2;
|
||||
precedence = 2;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Add: {
|
||||
number_args = 2;
|
||||
precedence = 3;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Subtract: {
|
||||
number_args = 2;
|
||||
precedence = 3;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Multiplication: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Division: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::Power: {
|
||||
number_args = 2;
|
||||
precedence = 5;
|
||||
associativity = Associativity::Right;
|
||||
} break;
|
||||
case Op::Modulo: {
|
||||
number_args = 2;
|
||||
precedence = 4;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
case Op::AtId: {
|
||||
number_args = 2;
|
||||
precedence = 8;
|
||||
associativity = Associativity::Left;
|
||||
} break;
|
||||
default: {
|
||||
precedence = 1;
|
||||
associativity = Associativity::Left;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,8 +252,8 @@ class ExpressionListNode : public AstNode {
|
||||
public:
|
||||
std::shared_ptr<ExpressionNode> root;
|
||||
|
||||
explicit ExpressionListNode() : AstNode(0) { }
|
||||
explicit ExpressionListNode(size_t pos) : AstNode(pos) { }
|
||||
explicit ExpressionListNode(): AstNode(0) {}
|
||||
explicit ExpressionListNode(size_t pos): AstNode(pos) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -264,7 +262,7 @@ public:
|
||||
|
||||
class StatementNode : public AstNode {
|
||||
public:
|
||||
StatementNode(size_t pos) : AstNode(pos) { }
|
||||
StatementNode(size_t pos): AstNode(pos) {}
|
||||
|
||||
virtual void accept(NodeVisitor& v) const = 0;
|
||||
};
|
||||
@@ -273,9 +271,9 @@ class ForStatementNode : public StatementNode {
|
||||
public:
|
||||
ExpressionListNode condition;
|
||||
BlockNode body;
|
||||
BlockNode *const parent;
|
||||
BlockNode* const parent;
|
||||
|
||||
ForStatementNode(BlockNode *const parent, size_t pos) : StatementNode(pos), parent(parent) { }
|
||||
ForStatementNode(BlockNode* const parent, size_t pos): StatementNode(pos), parent(parent) {}
|
||||
|
||||
virtual void accept(NodeVisitor& v) const = 0;
|
||||
};
|
||||
@@ -284,7 +282,7 @@ class ForArrayStatementNode : public ForStatementNode {
|
||||
public:
|
||||
const std::string value;
|
||||
|
||||
explicit ForArrayStatementNode(const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), value(value) { }
|
||||
explicit ForArrayStatementNode(const std::string& value, BlockNode* const parent, size_t pos): ForStatementNode(parent, pos), value(value) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -296,7 +294,8 @@ public:
|
||||
const std::string key;
|
||||
const std::string value;
|
||||
|
||||
explicit ForObjectStatementNode(const std::string& key, const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), key(key), value(value) { }
|
||||
explicit ForObjectStatementNode(const std::string& key, const std::string& value, BlockNode* const parent, size_t pos)
|
||||
: ForStatementNode(parent, pos), key(key), value(value) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -308,13 +307,13 @@ public:
|
||||
ExpressionListNode condition;
|
||||
BlockNode true_statement;
|
||||
BlockNode false_statement;
|
||||
BlockNode *const parent;
|
||||
BlockNode* const parent;
|
||||
|
||||
const bool is_nested;
|
||||
bool has_false_statement {false};
|
||||
|
||||
explicit IfStatementNode(BlockNode *const parent, size_t pos) : StatementNode(pos), parent(parent), is_nested(false) { }
|
||||
explicit IfStatementNode(bool is_nested, BlockNode *const parent, size_t pos) : StatementNode(pos), parent(parent), is_nested(is_nested) { }
|
||||
explicit IfStatementNode(BlockNode* const parent, size_t pos): StatementNode(pos), parent(parent), is_nested(false) {}
|
||||
explicit IfStatementNode(bool is_nested, BlockNode* const parent, size_t pos): StatementNode(pos), parent(parent), is_nested(is_nested) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -325,7 +324,7 @@ class IncludeStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string file;
|
||||
|
||||
explicit IncludeStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }
|
||||
explicit IncludeStatementNode(const std::string& file, size_t pos): StatementNode(pos), file(file) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -336,7 +335,7 @@ class ExtendsStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string file;
|
||||
|
||||
explicit ExtendsStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }
|
||||
explicit ExtendsStatementNode(const std::string& file, size_t pos): StatementNode(pos), file(file) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -347,9 +346,9 @@ class BlockStatementNode : public StatementNode {
|
||||
public:
|
||||
const std::string name;
|
||||
BlockNode block;
|
||||
BlockNode *const parent;
|
||||
BlockNode* const parent;
|
||||
|
||||
explicit BlockStatementNode(BlockNode *const parent, const std::string& name, size_t pos) : StatementNode(pos), name(name), parent(parent) { }
|
||||
explicit BlockStatementNode(BlockNode* const parent, const std::string& name, size_t pos): StatementNode(pos), name(name), parent(parent) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
@@ -361,7 +360,7 @@ public:
|
||||
const std::string key;
|
||||
ExpressionListNode expression;
|
||||
|
||||
explicit SetStatementNode(const std::string& key, size_t pos) : StatementNode(pos), key(key) { }
|
||||
explicit SetStatementNode(const std::string& key, size_t pos): StatementNode(pos), key(key) {}
|
||||
|
||||
void accept(NodeVisitor& v) const {
|
||||
v.visit(*this);
|
||||
|
||||
Reference in New Issue
Block a user