type structure change, mostly done

This commit is contained in:
ProgramSnail 2023-08-08 12:48:36 +03:00
parent 522dd16f79
commit a7c1e3f658
9 changed files with 183 additions and 66 deletions

View file

@ -479,7 +479,18 @@ build_name_expression(parser::ParseTree::Node parser_node,
auto current_node = name_node.previous_named_sibling();
if (!current_node.is_null()) {
if (tokens::string_to_type(current_node.get_type()) == tokens::Type::TYPE) {
if (tokens::string_to_type(current_node.get_type()) ==
tokens::Type::VARIANT_TYPE ||
tokens::string_to_type(current_node.get_type()) ==
tokens::Type::TUPLE_TYPE ||
tokens::string_to_type(current_node.get_type()) ==
tokens::Type::ARRAY_TYPE ||
tokens::string_to_type(current_node.get_type()) ==
tokens::Type::REFERENCE_TYPE ||
tokens::string_to_type(current_node.get_type()) ==
tokens::Type::MODIFIED_TYPE ||
tokens::string_to_type(current_node.get_type()) ==
tokens::Type::SIMPLE_TYPE) {
prefix_node = current_node;
} else {
is_point_call = true;

View file

@ -209,6 +209,11 @@ nodes::TypeDefinition build_type_definition(parser::ParseTree::Node parser_node,
arguments.push_back(build_identifier(current_node));
break;
case tokens::Type::VARIANT_TYPE:
case tokens::Type::TUPLE_TYPE:
case tokens::Type::ARRAY_TYPE:
case tokens::Type::REFERENCE_TYPE:
case tokens::Type::MODIFIED_TYPE:
case tokens::Type::SIMPLE_TYPE:
if (type_node.has_value()) {
error_handling::handle_parsing_error(
"More then one type node in type definition", parser_node);
@ -246,22 +251,17 @@ nodes::TypeDefinition build_type_definition(parser::ParseTree::Node parser_node,
std::unordered_set<std::string> annotations;
// collect annotations from type
if (type.has_value()) {
for (size_t i = 0; i < type.value().size(); ++i) {
// TODO: deal with annotations
auto constructor_annotations = type.value().get(i)->get_all_annotations();
for (auto &annotation : constructor_annotations) {
annotations.insert(annotation);
}
}
type.value().get()->collect_annotations_recursively(
std::insert_iterator<std::unordered_set<std::string>>(
annotations, annotations.begin()));
}
return nodes::TypeDefinition(
build_node(parser_node),
build_symbol_docs(description_node, annotation_nodes, annotations),
is_on_heap, std::move(name), std::move(typeclasses), std::move(arguments),
std::move(type));
type);
}
// definition_info? annotation_info* (constraint ';')* '.'? (simple_name

View file

@ -1,10 +1,11 @@
#include "type_builders.hpp"
#include "basic_builders.hpp"
#include "basic_nodes.hpp"
#include "builtin_identifiers.hpp"
#include "builtin_types.hpp"
#include "error_handling.hpp"
#include "tokens.hpp"
#include "type_nodes.hpp"
#include "types.hpp"
namespace builders {
@ -39,41 +40,47 @@ nodes::TypeProxy build_type(parser::ParseTree::Node parser_node,
exit(1); // unreachable
}
// '|'? annotation? type ('|' annotation? type)+
nodes::TypeProxy build_variant_type(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage) {
nodes::TypeProxy
build_buildin_container_type(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage,
const std::string &type_name) {
std::vector<nodes::TypeProxy> parameters;
std::optional<std::string> current_annotation;
auto current_node = parser_node.nth_named_child(0);
;
while (!current_node.is_null()) {
parameters.push_back(build_type(current_node, type_storage));
if (tokens::string_to_type(current_node.get_type()) ==
tokens::Type::ANNOTATION_IDENTIFIER) {
current_annotation = build_annotation(current_node);
} else {
parameters.push_back(build_type(current_node, type_storage));
if (current_annotation.has_value()) {
parameters.back().get()->set_annotation(current_annotation.value());
}
}
current_node = current_node.next_named_sibling();
}
return type_storage.add_type(nodes::Type(
build_node(parser_node),
nodes::Identifier(build_node(parser_node), nodes::Identifier::SIMPLE_TYPE,
builtin::VARIANT_IDENTIFIER),
std::move(parameters), false));
return type_storage.add_type(
nodes::Type(build_node(parser_node),
nodes::Identifier(build_node(parser_node),
nodes::Identifier::SIMPLE_TYPE, type_name),
std::move(parameters), false));
}
// '|'? annotation? type ('|' annotation? type)+
nodes::TypeProxy build_variant_type(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage) {
return build_buildin_container_type(parser_node, type_storage,
builtin::VARIANT_IDENTIFIER);
}
// '&'? annotation? type ('&' annotation? type)+
nodes::TypeProxy build_tuple_type(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage) {
std::vector<nodes::TypeProxy> parameters;
auto current_node = parser_node.nth_named_child(0);
while (!current_node.is_null()) {
parameters.push_back(build_type(current_node, type_storage));
current_node = current_node.next_named_sibling();
}
return type_storage.add_type(nodes::Type(
build_node(parser_node),
nodes::Identifier(build_node(parser_node), nodes::Identifier::SIMPLE_TYPE,
builtin::TUPLE_IDENTIFIER),
std::move(parameters), false));
return build_buildin_container_type(parser_node, type_storage,
builtin::TUPLE_IDENTIFIER);
}
// '[[' type ']]'

View file

@ -11,6 +11,11 @@ void print_type(const nodes::Type &type, printers::Printer &printer) {
printer.print("^");
}
if (type.get_annotation().has_value()) {
print_annotation(*type.get_annotation().value(), printer);
printer.space();
}
print_identifier(*type.get_name(), printer);
if (type.get_parametrs_size() > 0) {