statement node added

This commit is contained in:
ProgramSnail 2023-07-26 14:21:33 +03:00
parent b4ce56b5f7
commit 6b74398f8c
7 changed files with 108 additions and 60 deletions

View file

@ -536,7 +536,6 @@ public:
private:
std::variant<
// --- flow control
Match, Condition, Loop,
@ -563,9 +562,7 @@ private:
Literal,
// --- empty lines
EmptyLines
>
EmptyLines>
expression_;
bool is_scoped_ = false;

View file

@ -3,17 +3,18 @@
#include "statement_nodes.hpp"
#include "tree_sitter_wrapper.hpp"
#include <vector>
namespace builders {
// IN PROGRESS: return type, etc.
void build_source_file(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
std::vector<nodes::Statement>
build_source_file(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
// IN PROGRESS: return type, etc.
void build_statement(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
nodes::Statement build_statement(parser::ParseTree::Node parser_node,
nodes::ExpressionStorage &expression_storage,
nodes::TypeStorage &type_storage);
nodes::Import build_import(parser::ParseTree::Node parser_node);

View file

@ -385,4 +385,33 @@ private:
std::vector<FunctionDefinition> methods_;
};
class Statement {
public:
template <typename T>
Statement(T &&statement) : expression_(std::forward<T>(statement)) {}
template <typename T> std::optional<T *> get() {
if (std::holds_alternative<T>(expression_)) {
return &std::get<T>(expression_);
}
return std::nullopt;
}
template <typename T> std::optional<const T *> get() const {
if (std::holds_alternative<T>(expression_)) {
return &std::get<T>(expression_);
}
return std::nullopt;
}
auto get_any() { return &expression_; }
auto get_any() const { return &expression_; }
private:
std::variant<Import, TypeDefinition, FunctionDefinition, TypeclassDefinition,
EmptyLines>
expression_;
};
} // namespace nodes

View file

@ -3,11 +3,14 @@
#include "basic_printers.hpp"
#include "statement_nodes.hpp"
#include <vector>
namespace printers {
// void print_source_file(Printer &printer); // TODO
void print_source_file(const std::vector<nodes::Statement> &statements,
Printer &printer);
// void print_statement(Printer &printer); // TODO
void print_statement(const nodes::Statement &statements, Printer &printer);
void print_import(const nodes::Import &statement, Printer &printer);