mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-23 23:38:45 +00:00
statement node added
This commit is contained in:
parent
b4ce56b5f7
commit
6b74398f8c
7 changed files with 108 additions and 60 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue