Add Child Inheritance Feature (#198)

* add block and extend feature

* constify, code cleaning

* update single include

* add html language to readme

* clean tests

* constantify, update year
This commit is contained in:
pantor
2021-05-25 10:18:21 +02:00
committed by GitHub
parent b4b9d8dc16
commit 95af782ca2
22 changed files with 561 additions and 173 deletions
+29 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Pantor. All rights reserved.
// Copyright (c) 2021 Pantor. All rights reserved.
#ifndef INCLUDE_INJA_NODE_HPP_
#define INCLUDE_INJA_NODE_HPP_
@@ -28,6 +28,8 @@ class ForArrayStatementNode;
class ForObjectStatementNode;
class IfStatementNode;
class IncludeStatementNode;
class ExtendsStatementNode;
class BlockStatementNode;
class SetStatementNode;
@@ -48,6 +50,8 @@ public:
virtual void visit(const ForObjectStatementNode& node) = 0;
virtual void visit(const IfStatementNode& node) = 0;
virtual void visit(const IncludeStatementNode& node) = 0;
virtual void visit(const ExtendsStatementNode& node) = 0;
virtual void visit(const BlockStatementNode& node) = 0;
virtual void visit(const SetStatementNode& node) = 0;
};
@@ -331,6 +335,30 @@ public:
}
};
class ExtendsStatementNode : public StatementNode {
public:
const std::string file;
explicit ExtendsStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }
void accept(NodeVisitor& v) const {
v.visit(*this);
};
};
class BlockStatementNode : public StatementNode {
public:
const std::string name;
BlockNode block;
BlockNode *const parent;
explicit BlockStatementNode(BlockNode *const parent, const std::string& name, size_t pos) : StatementNode(pos), parent(parent), name(name) { }
void accept(NodeVisitor& v) const {
v.visit(*this);
};
};
class SetStatementNode : public StatementNode {
public:
const std::string key;