refactored ast, started lexer

This commit is contained in:
2026-05-18 20:19:17 +03:00
parent 24750ddcbe
commit eb85acf224
29 changed files with 315 additions and 181 deletions
+5 -3
View File
@@ -5,6 +5,8 @@
#include <vector>
#include <string>
struct BlockNode : public Node {
virtual ~BlockNode() = default;
};
namespace ast {
struct BlockNode : public Node {
virtual ~BlockNode() = default;
};
}
+8 -11
View File
@@ -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;
};
}
+8 -14
View File
@@ -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;
};
}
+7 -13
View File
@@ -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;
};
}
+7 -13
View File
@@ -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;
};
}
+8 -14
View File
@@ -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;
};
}