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

@ -1 +1 @@
Subproject commit 24015fd8df34dfb1c4c3b1d1622b261d01cb5a4c
Subproject commit b71b732797ce7fc203322b5ce2b1bbd9333bfb51

View file

@ -15,11 +15,6 @@
</list>
<list name="keywords">
<item>import</item>
<item>out</item>
<item>in</item>
<item>ref</item>
<item>or_out</item>
<item>or_in</item>
<item>let</item>
<item>var</item>
<item>lambda</item>
@ -27,6 +22,12 @@
<item>test</item>
<item>example</item>
</list>
<list name="references">
<item>out</item>
<item>in</item>
<item>ref</item>
<item>const</item>
</list>
<list name="constants">
<item>null</item>
<item>true</item>
@ -39,11 +40,12 @@
<DetectSpaces/>
<keyword String="controlflow" attribute="Control Flow" context="#stay"/>
<keyword String="keywords" attribute="Keyword" context="#stay"/>
<keyword String="references" attribute="Reference" context="#stay"/>
<keyword String="constants" attribute="Constant" context="#stay"/>
<Detect2Chars char="/" char1="/" attribute="Comment" context="Comment"/>
<RegExpr String="^\: [^\n]*" attribute="Documentation" context="#stay"/>
<RegExpr String="^\@[^\n]*" attribute="Documentation" context="#stay"/>
<RegExpr String="^\@[a-z_][a-z0-9_]* " attribute="Annotation" context="AnnotationDocumentation"/>
<Detect2Chars char="(" char1=")" attribute="Constant" context="#stay"/>
@ -51,14 +53,16 @@
<RegExpr String="\@[a-z_][a-z0-9_]*(?![a-z0-9_])" attribute="Annotation" context="#stay"/>
<RegExpr String="((\:\=)|(\=\:)|\%|\\|\$|(\:\:)|(\|?\-\>)|(&lt;\-\|?)|(&lt;\>)|^)(?![a\+\\\-\*/%\^\!\?\|&amp;,&lt;>=\.])" attribute="Keyword" context="#stay"/>
<RegExpr String="((\:\=)|(\=\:)|\%|\\|\$|(\:\:)|^)(?![a\+\\\-\*/%\^\!\?&amp;,&lt;>=\.])" attribute="Keyword" context="#stay"/>
<RegExpr String="((\-\>)|(&lt;\-)|(&lt;\>)|(\-\-))(?![a\+\\\-\*/%\^\!\?&amp;,&lt;>=\.])" attribute="Reference" context="#stay"/>
<RegExpr String="(\@|\:|(\?\?)|(\!\!)|(\=\>)|(\!\!\=\>))(?![a\+\\\-\*/%\^\!\?\|&amp;,&lt;>=\.])" attribute="Control Flow" context="#stay"/>
<RegExpr String="\b[0-9]+\.[0-9]+\b" attribute="Float" context="#stay"/>
<RegExpr String="''([^\\\/]|(\\.))''" attribute="Character" context="#stay"/>
<RegExpr String="(\.+)|([\+\\\-\*/%\^\!\?\|&amp;,&lt;>=]+\.?\.?\.?)" attribute="Operator" context="#stay"/>
<RegExpr String="(\|)|((?&lt;![a\+\\\-\*/%\^\!\?\|&amp;,&lt;>=\.])((\.+)|([\+\\\-\*/%\^\!\?\|&amp;,&lt;>=]+\.?\.?\.?)))" attribute="Operator" context="#stay"/>
<RegExpr String="([a-z_][a-z0-9_]*\.)*(([a-z_][a-z0-9_]*)|_)(?![a-z0-9_])" attribute="Name" context="#stay"/>
@ -91,7 +95,6 @@
</context>
<context attribute="Comment" lineEndContext="#pop" name="Comment">
<LineContinue attribute="Comment" context="#stay"/>
<DetectSpaces />
<IncludeRules context="##Comments" />
<DetectIdentifier />
@ -103,11 +106,15 @@
<IncludeRules context="##Comments" />
<DetectIdentifier />
</context>
<context attribute="Documentation" lineEndContext="#pop" name="AnnotationDocumentation">
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Control Flow" defStyleNum="dsControlFlow" spellChecking="false"/>
<itemData name="Keyword" defStyleNum="dsKeyword" spellChecking="false"/>
<itemData name="Reference" defStyleNum="dsOperator" spellChecking="false"/>
<itemData name="Type" defStyleNum="dsDataType" spellChecking="false"/>
<itemData name="ArgumentTypeOrName" defStyleNum="dsBuiltIn" spellChecking="false"/>
<itemData name="Constructor" defStyleNum="dsConstant" spellChecking="false"/>
@ -122,7 +129,7 @@
<itemData name="String" defStyleNum="dsString"/>
<itemData name="Escape" defStyleNum="dsSpecialChar"/>
<itemData name="Character" defStyleNum="dsChar"/>
<itemData name="Operator" defStyleNum="dsFunction"/>
<itemData name="Operator" defStyleNum="dsNormal"/>
<itemData name="Symbol" defStyleNum="dsFunction"/>
<itemData name="Error" defStyleNum="dsError"/>
</itemDatas>

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_)) {

View file

@ -0,0 +1,3 @@
#include "expression_type_check.hpp"
namespace type_check {} // namespace type_check

View file

@ -1,4 +1,6 @@
#include "name_tree.hpp"
#include "error_handling.hpp"
#include "statement_nodes.hpp"
namespace names {
@ -17,18 +19,18 @@ bool NameTree::insert(const std::string &path, nodes::Statement &&statement) {
return true;
}
bool NameTree::insert(const std::string &path,
const nodes::Statement &statement) {
nodes::CombineResult NameTree::insert_combine(const std::string &path,
nodes::Statement &&statement) {
auto name_ids = slice_path_to_name_ids(path);
size_t node_id = add_node(get_root(), name_ids);
if (nodes_[node_id].get_statement().has_value()) {
return false;
if (!nodes_[node_id].get_statement().has_value()) {
nodes_[node_id].set_statement(std::move(statement));
return nodes::CombineResult::OK;
}
nodes_[node_id].set_statement(statement);
return true;
return nodes_[node_id].get_statement().value()->combine(std::move(statement));
}
std::optional<nodes::Statement *> NameTree::find(const std::string &path) {
@ -64,6 +66,41 @@ NameTree::find(const std::string &path) const {
return std::nullopt;
}
void NameTree::print(printers::Printer &printer) const {
nodes_[get_root()].print(nodes_, printer);
}
// TODO
void NameTree::add_statement_children_to_tree() {
for (auto &node : nodes_) {
if (!node.get_statement().has_value()) {
continue;
}
switch (node.get_statement().value()->get_any()->index()) {
case 0: // Import
// TODO: link imported symbols, if named import, otherwise link imported
// symbols to root
break;
case 1: // FunctionDefinition
// TODO: link to result type
break;
case 2: // TypeDefinition
// TODO: link methods + link children to types + connect to typeclasses
break;
case 3: // TypeclassDefinition
// TODO: link methods + connect typeclasses
break;
case 4: // EmptyLines
break;
default:
error_handling::handle_general_error(
"Unexpected statement type in name tree");
break;
}
}
}
// --- private
size_t NameTree::add_node(size_t current_node,

View file

@ -84,7 +84,7 @@ nodes::Statement build_statement(parser::ParseTree::Node parser_node,
->get();
break;
case tokens::Type::EMPTY_LINES:
statement = build_empty_lines(parser_node);
statement = nodes::Statement(build_empty_lines(parser_node));
break;
default:
error_handling::handle_parsing_error("Unexprected statement node type",
@ -97,7 +97,8 @@ nodes::Statement build_statement(parser::ParseTree::Node parser_node,
if (statement_name.has_value()) {
// TODO: combine statements with same name
if (!name_tree.insert(statement_name.value(), statement.value())) {
auto statement_copy = statement.value();
if (!name_tree.insert(statement_name.value(), std::move(statement_copy))) {
error_handling::handle_parsing_error(
"Two or more statements in file have the same name", parser_node);
}

View file

@ -216,7 +216,7 @@ parse_number : Unit! = {
}
: example of or_in and or_out usage for template operators (tuple input and tuple output)
( & ) |-> 'a |-> 'b <-| 'x <-| 'y = ('a := 'x) && ('b := 'y);
( & ) --|-> 'a --|-> 'b <-|-- 'x <-|-- 'y = ('a := 'x) && ('b := 'y);
: function, that return result ('!' not used on calls)
: useful when tuples returned