mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 23:48:43 +00:00
parametrized_type, parametrized_typeclass, function argument, array type fixes
This commit is contained in:
parent
0dc8880c58
commit
d13faf104d
9 changed files with 32 additions and 153 deletions
|
|
@ -126,17 +126,12 @@ private:
|
|||
|
||||
// Typeclass
|
||||
|
||||
void Visit(TypeclassExpression* node) override;
|
||||
void Visit(ParametrizedTypeclass* node) override;
|
||||
|
||||
void Visit(TypeclassSubExpression& node) override; // variant
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
void Visit(ParametrizedType* node) override;
|
||||
|
||||
void Visit(TypeSubExpression& node) override; // variant
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
void Visit(ExtendedName* node) override;
|
||||
|
|
|
|||
|
|
@ -69,12 +69,12 @@ using ImportSymbol = AnyIdentifier; // can be extended name
|
|||
|
||||
struct FunctionDefinition;
|
||||
struct TypeDefinition;
|
||||
struct AnnotatedAbstractType;
|
||||
struct AnyAnnotatedType;
|
||||
|
||||
// TypeIdentifier <-> AbstractTypeIdentifier <-> std::string
|
||||
using AnnotatedType = AnnotatedAbstractType;
|
||||
using AnnotatedType = AnyAnnotatedType;
|
||||
|
||||
using AnyAnnotatedType = AnnotatedType;
|
||||
using AnnotatedAbstractType = AnyAnnotatedType;
|
||||
|
||||
// Flow control -----------------
|
||||
|
||||
|
|
@ -225,25 +225,19 @@ struct ExtendedScopedAnyType;
|
|||
// Typeclass
|
||||
|
||||
struct ParametrizedTypeclass;
|
||||
struct TypeclassExpression;
|
||||
|
||||
using TypeclassSubExpression = std::variant<
|
||||
std::unique_ptr<TypeclassIdentifier>,
|
||||
std::unique_ptr<ParametrizedTypeclass>>;
|
||||
// TypeclassSubExpression -> ParametrizedTypeclass
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
struct ParametrizedType;
|
||||
|
||||
using TypeSubExpression = std::variant<
|
||||
std::unique_ptr<AnyTypeIdentifier>,
|
||||
std::unique_ptr<ParametrizedType>>;
|
||||
// TypeSubExpression -> ParametrizedType
|
||||
|
||||
//
|
||||
|
||||
using FunctionArgument = std::variant<
|
||||
SubExpressionToken,
|
||||
TypeSubExpression>;
|
||||
std::unique_ptr<TypeExpression>>;
|
||||
|
||||
// Comments [IGNORE] -----------------
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
|
@ -377,9 +371,9 @@ struct TypeDefinition {
|
|||
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
||||
};
|
||||
|
||||
struct AnnotatedAbstractType {
|
||||
AbstractTypeIdentifier type;
|
||||
std::vector<std::unique_ptr<TypeclassExpression>> typeclasses;
|
||||
struct AnyAnnotatedType {
|
||||
AnyTypeIdentifier type;
|
||||
std::vector<std::unique_ptr<ParametrizedTypeclass>> typeclasses;
|
||||
};
|
||||
|
||||
// ----------------- Flow control -----------------
|
||||
|
|
@ -552,9 +546,16 @@ struct VariantType {
|
|||
std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors;
|
||||
};
|
||||
|
||||
struct ParametrizedType {
|
||||
AnyTypeIdentifier type;
|
||||
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
||||
|
||||
std::optional<utils::IdType> type_id_; // std::nullopt, if it is namespace without type
|
||||
};
|
||||
|
||||
struct TypeExpression {
|
||||
std::vector<TypeSubExpression> path;
|
||||
TypeSubExpression type;
|
||||
std::vector<ParametrizedType> path;
|
||||
ParametrizedType type;
|
||||
|
||||
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
||||
|
||||
|
|
@ -569,24 +570,11 @@ struct ExtendedScopedAnyType {
|
|||
|
||||
// Typeclass -----------------
|
||||
|
||||
struct TypeclassExpression {
|
||||
TypeclassSubExpression typeclass;
|
||||
|
||||
utils::IdType typeclass_id_;
|
||||
};
|
||||
|
||||
struct ParametrizedTypeclass {
|
||||
TypeclassIdentifier typeclass;
|
||||
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
||||
};
|
||||
|
||||
// Typeclass & Type -----------------
|
||||
|
||||
struct ParametrizedType {
|
||||
AnyTypeIdentifier type;
|
||||
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
||||
|
||||
std::optional<utils::IdType> type_id_; // std::nullopt, if it is namespace without type
|
||||
utils::IdType typeclass_id_;
|
||||
};
|
||||
|
||||
// ----------------- Comments [IGNORE] -----------------
|
||||
|
|
|
|||
|
|
@ -107,18 +107,13 @@ const std::string ExtendedScopedAnyType = "extended_scoped_any_type";
|
|||
|
||||
// Typeclass
|
||||
|
||||
const std::string TypeclassExpression = "typeclass_expression";
|
||||
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
||||
|
||||
const std::string TypeclassSubExpression = "typeclass_subexpression";
|
||||
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
const std::string ParametrizedType = "parametrized_type";
|
||||
|
||||
const std::string TypeSubExpression = "type_subexpression";
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
const std::string ExtendedName = "extended_name";
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ private:
|
|||
|
||||
// Typeclass
|
||||
|
||||
void Visit(TypeclassExpression* node) override;
|
||||
void Visit(ParametrizedTypeclass* node) override;
|
||||
|
||||
// Typeclass & Type
|
||||
|
|
|
|||
|
|
@ -123,17 +123,12 @@ protected:
|
|||
|
||||
// Typeclass
|
||||
|
||||
virtual void Visit(TypeclassExpression* node);
|
||||
virtual void Visit(ParametrizedTypeclass* node);
|
||||
|
||||
virtual void Visit(TypeclassSubExpression& node); // variant
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
virtual void Visit(ParametrizedType* node);
|
||||
|
||||
virtual void Visit(TypeSubExpression& node); // variant
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
virtual void Visit(ExtendedName* node);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 8021bf5b433c7b3d5179deba98af60faf47d4457
|
||||
Subproject commit 1875ec1f091eaa96d62cc5ceee4c0adc7bb6d4a9
|
||||
|
|
@ -416,7 +416,7 @@ void BuildVisitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
node->typeclasses[i] = std::make_unique<TypeclassExpression>();
|
||||
node->typeclasses[i] = std::make_unique<ParametrizedTypeclass>();
|
||||
Visit(node->typeclasses[i].get());
|
||||
}
|
||||
}
|
||||
|
|
@ -915,9 +915,9 @@ void BuildVisitor::Visit(FunctionArgument& node) {
|
|||
if (current_node_type == parser::tokens::SubExpressionToken) {
|
||||
node = SubExpressionToken();
|
||||
Visit(std::get<SubExpressionToken>(node));
|
||||
} else if (current_node_type == parser::tokens::TypeSubExpression) {
|
||||
node = TypeSubExpression();
|
||||
Visit(std::get<TypeSubExpression>(node));
|
||||
} else if (current_node_type == parser::tokens::TypeExpression) {
|
||||
node = std::make_unique<TypeExpression>();
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
|
@ -1288,7 +1288,7 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
Visit(node->type);
|
||||
Visit(&node->type);
|
||||
++excluded_child_count;
|
||||
|
||||
current_node_ = current_node_.NextSibling();
|
||||
|
|
@ -1310,7 +1310,7 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
|
||||
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
Visit(node->path[i]);
|
||||
Visit(&node->path[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1368,35 +1368,6 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
|
||||
// Typeclass
|
||||
|
||||
void BuildVisitor::Visit(TypeclassExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("typeclass");
|
||||
Visit(node->typeclass);
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeclassSubExpression& node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.NthNamedChild(0);
|
||||
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type == parser::tokens::TypeclassIdentifier) {
|
||||
node = std::make_unique<TypeclassIdentifier>();
|
||||
Visit(std::get<std::unique_ptr<TypeclassIdentifier>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::ParametrizedTypeclass) {
|
||||
node = std::make_unique<ParametrizedTypeclass>();
|
||||
Visit(std::get<std::unique_ptr<ParametrizedTypeclass>>(node).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
|
|
@ -1419,28 +1390,6 @@ void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
|||
|
||||
// Typeclass & Type -----------------
|
||||
|
||||
void BuildVisitor::Visit(TypeSubExpression& node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.NthNamedChild(0);
|
||||
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type == parser::tokens::TypeIdentifier) {
|
||||
node = std::make_unique<TypeIdentifier>();
|
||||
Visit(std::get<std::unique_ptr<TypeIdentifier>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::AbstractTypeIdentifier) {
|
||||
node = std::make_unique<AbstractTypeIdentifier>();
|
||||
Visit(std::get<std::unique_ptr<AbstractTypeIdentifier>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::ParametrizedType) {
|
||||
node = std::make_unique<ParametrizedType>();
|
||||
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(ParametrizedType* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
|
|
|||
|
|
@ -632,10 +632,10 @@ void PrintVisitor::Visit(TypeExpression* node) {
|
|||
|
||||
out_ << "] (";
|
||||
for (auto& type : node->path) {
|
||||
Visitor::Visit(type);
|
||||
Visit(&type);
|
||||
out_ << "::";
|
||||
}
|
||||
Visitor::Visit(node->type);
|
||||
Visit(&node->type);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
|
|
@ -658,12 +658,6 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
|
||||
// Typeclass
|
||||
|
||||
void PrintVisitor::Visit(TypeclassExpression* node) {
|
||||
out_ << "[TypeclassExpression] (";
|
||||
Visitor::Visit(node->typeclass);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(ParametrizedTypeclass* node) {
|
||||
out_ << "[ParametrizedTypeclass] (";
|
||||
Visit(&node->typeclass);
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ void Visitor::Visit(FunctionArgument& node) {
|
|||
Visit(std::get<SubExpressionToken>(node));
|
||||
break;
|
||||
case 1:
|
||||
Visit(std::get<TypeSubExpression>(node));
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node).get());
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
|
|
@ -307,38 +307,6 @@ void Visitor::Visit(AnyType& node) {
|
|||
}
|
||||
}
|
||||
|
||||
// Typeclass
|
||||
|
||||
void Visitor::Visit(TypeclassSubExpression& node) {
|
||||
switch (node.index()) {
|
||||
case 0:
|
||||
Visit(std::get<std::unique_ptr<TypeclassIdentifier>>(node).get());
|
||||
break;
|
||||
case 1:
|
||||
Visit(std::get<std::unique_ptr<ParametrizedTypeclass>>(node).get());
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
void Visitor::Visit(TypeSubExpression& node) {
|
||||
switch (node.index()) {
|
||||
case 0:
|
||||
Visit(std::get<std::unique_ptr<AnyTypeIdentifier>>(node).get());
|
||||
break;
|
||||
case 1:
|
||||
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
void Visitor::Visit(Literal& node) {
|
||||
|
|
@ -697,9 +665,9 @@ void Visitor::Visit(VariantType* node) {
|
|||
|
||||
void Visitor::Visit(TypeExpression* node) {
|
||||
for (auto& type : node->path) {
|
||||
Visit(type);
|
||||
Visit(&type);
|
||||
}
|
||||
Visit(node->type);
|
||||
Visit(&node->type);
|
||||
}
|
||||
|
||||
void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||
|
|
@ -708,10 +676,6 @@ void Visitor::Visit(ExtendedScopedAnyType* node) {
|
|||
|
||||
// Typeclass
|
||||
|
||||
void Visitor::Visit(TypeclassExpression* node) {
|
||||
Visit(node->typeclass);
|
||||
}
|
||||
|
||||
void Visitor::Visit(ParametrizedTypeclass* node) {
|
||||
Visit(&node->typeclass);
|
||||
for (auto& parameter : node->parameters) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue