refactored ast, started lexer
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
struct BlockNode : public Node {
|
||||
virtual ~BlockNode() = default;
|
||||
};
|
||||
namespace ast {
|
||||
struct BlockNode : public Node {
|
||||
virtual ~BlockNode() = default;
|
||||
};
|
||||
}
|
||||
@@ -3,15 +3,12 @@
|
||||
#include "ast/BlockNode/BlockNode.h"
|
||||
#include "utils/shorten.hpp"
|
||||
|
||||
struct CodeBlock : public BlockNode {
|
||||
std::string language;
|
||||
std::string code;
|
||||
namespace ast {
|
||||
struct CodeBlock : public BlockNode {
|
||||
std::string language;
|
||||
std::string code;
|
||||
|
||||
NodeKind getKind() const override {
|
||||
return NodeKind::CodeBlock;
|
||||
}
|
||||
|
||||
void repr(std::ostream &os, int indent = 0) const override {
|
||||
os << getIndent(indent) << toString(this->getKind()) << " lang: " << this->language << " code: " << shorten(this->code) << '\n';
|
||||
}
|
||||
};
|
||||
NodeKind getKind() const override;
|
||||
void repr(std::ostream &os, int indent = 0) const override;
|
||||
};
|
||||
}
|
||||
@@ -3,18 +3,12 @@
|
||||
#include "ast/BlockNode/BlockNode.h"
|
||||
#include "ast/InlineNode/InlineNode.h"
|
||||
|
||||
struct Header : public BlockNode {
|
||||
int level = 1;
|
||||
std::vector<std::unique_ptr<InlineNode>> children;
|
||||
namespace ast {
|
||||
struct Header : public BlockNode {
|
||||
int level = 1;
|
||||
std::vector<std::unique_ptr<InlineNode>> children;
|
||||
|
||||
NodeKind getKind() const override {
|
||||
return NodeKind::Header;
|
||||
}
|
||||
|
||||
void repr(std::ostream &os, int indent = 0) const override {
|
||||
os << getIndent(indent) << toString(this->getKind()) << " level: " << this->level << '\n';
|
||||
for (const std::unique_ptr<InlineNode> &child : this->children) {
|
||||
child->repr(os, indent + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
NodeKind getKind() const override;
|
||||
void repr(std::ostream &os, int indent = 0) const override;
|
||||
};
|
||||
}
|
||||
@@ -3,17 +3,11 @@
|
||||
#include "ast/BlockNode/BlockNode.h"
|
||||
#include "ast/BlockNode/ListItem.h"
|
||||
|
||||
struct List : public BlockNode {
|
||||
std::vector<std::unique_ptr<ListItem>> children;
|
||||
namespace ast {
|
||||
struct List : public BlockNode {
|
||||
std::vector<std::unique_ptr<ListItem>> children;
|
||||
|
||||
NodeKind getKind() const override {
|
||||
return NodeKind::List;
|
||||
}
|
||||
|
||||
void repr(std::ostream &os, int indent) const override {
|
||||
os << getIndent(indent) << toString(getKind()) << '\n';
|
||||
for (const std::unique_ptr<ListItem> &child : this->children) {
|
||||
child->repr(os, indent + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
NodeKind getKind() const override;
|
||||
void repr(std::ostream &os, int indent) const override;
|
||||
};
|
||||
}
|
||||
@@ -2,17 +2,11 @@
|
||||
|
||||
#include "ast/BlockNode/BlockNode.h"
|
||||
|
||||
struct ListItem : public BlockNode {
|
||||
std::vector<std::unique_ptr<BlockNode>> children;
|
||||
namespace ast {
|
||||
struct ListItem : public BlockNode {
|
||||
std::vector<std::unique_ptr<BlockNode>> children;
|
||||
|
||||
NodeKind getKind() const override {
|
||||
return NodeKind::ListItem;
|
||||
}
|
||||
|
||||
void repr(std::ostream &os, int indent) const override {
|
||||
os << getIndent(indent) << toString(getKind()) << '\n';
|
||||
for (const std::unique_ptr<BlockNode> &child : this->children) {
|
||||
child->repr(os, indent + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
NodeKind getKind() const override;
|
||||
void repr(std::ostream &os, int indent) const override;
|
||||
};
|
||||
}
|
||||
@@ -3,17 +3,11 @@
|
||||
#include "ast/BlockNode/BlockNode.h"
|
||||
#include "ast/InlineNode/InlineNode.h"
|
||||
|
||||
struct Paragraph : public BlockNode {
|
||||
std::vector<std::unique_ptr<InlineNode>> children;
|
||||
|
||||
NodeKind getKind() const override {
|
||||
return NodeKind::Paragraph;
|
||||
}
|
||||
|
||||
void repr(std::ostream &os, int indent) const override {
|
||||
os << getIndent(indent) << toString(getKind()) << '\n';
|
||||
for (const std::unique_ptr<InlineNode> &child : children) {
|
||||
child->repr(os, indent + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
namespace ast {
|
||||
struct Paragraph : public BlockNode {
|
||||
std::vector<std::unique_ptr<InlineNode>> children;
|
||||
|
||||
NodeKind getKind() const override;
|
||||
void repr(std::ostream &os, int indent) const override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user