highlighting improvements

This commit is contained in:
ProgramSnail 2023-07-31 13:52:03 +03:00
parent 195a26f9b7
commit bf7fe1f821
9 changed files with 139 additions and 22 deletions

View file

@ -0,0 +1,46 @@
#pragma once
#include "expression_nodes.hpp"
// IN PROGRESS
namespace type_check {
void type_check_expression(const nodes::Expression &expression);
// --- flow control
void type_check_case(const nodes::Match::Case &expression);
void type_check_match(const nodes::Match &expression);
void type_check_condition(const nodes::Condition &expression);
void type_check_loop(const nodes::Loop &expression);
// --- containers
void type_check_container(const nodes::Container &expression);
// --- modifiers
void type_check_return(const nodes::Return &expression);
void type_check_name_definition(const nodes::NameDefinition &expression);
void type_check_access(const nodes::Access &expression);
void type_check_loop_control(const nodes::LoopControl &expression);
void type_check_modifier_expression(
const nodes::ModifierExpression &expression);
// --- other
void type_check_name_expression(const nodes::NameExpression &expression);
void type_check_constructor(const nodes::Constructor &expression);
void type_check_lambda(const nodes::Lambda &expression);
} // namespace type_check

View file

@ -1,5 +1,6 @@
#pragma once
#include "basic_printers.hpp"
#include "statement_nodes.hpp"
#include "tree_sitter_wrapper.hpp"
@ -19,12 +20,20 @@ public:
bool insert(const std::string &path, nodes::Statement &&statement);
bool insert(const std::string &path, const nodes::Statement &statement);
// bool insert(const std::string &path, const nodes::Statement &statement);
nodes::CombineResult insert_combine(const std::string &path,
nodes::Statement &&statement);
std::optional<nodes::Statement *> find(const std::string &path);
std::optional<const nodes::Statement *> find(const std::string &path) const;
void print(printers::Printer &printer) const;
// TODO
void add_statement_children_to_tree();
private:
struct Node {
public:
@ -76,6 +85,20 @@ private:
return true;
}
void print(const std::vector<Node> &nodes,
printers::Printer &printer) const {
printer.print("Node - has statement: ");
printer.print(statement_.has_value() ? "true" : "false");
printer.indent();
for (auto &iter : children_) {
printer.new_indent_line();
printer.print(std::to_string(iter.first) + " -> ");
nodes[iter.second].print(nodes, printer);
}
printer.deindent();
printer.new_indent_line();
}
private:
std::unordered_map<size_t, size_t> children_;
std::optional<nodes::Statement> statement_;

View file

@ -473,7 +473,7 @@ public:
Statement &operator=(const Statement &) = default;
template <typename T>
Statement(T &&statement) : expression_(std::forward<T>(statement)) {}
explicit Statement(T &&statement) : expression_(std::forward<T>(statement)) {}
template <typename T> std::optional<T *> get() {
if (std::holds_alternative<T>(expression_)) {