mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-09 00:18:44 +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
|
// Typeclass
|
||||||
|
|
||||||
void Visit(TypeclassExpression* node) override;
|
|
||||||
void Visit(ParametrizedTypeclass* node) override;
|
void Visit(ParametrizedTypeclass* node) override;
|
||||||
|
|
||||||
void Visit(TypeclassSubExpression& node) override; // variant
|
|
||||||
|
|
||||||
// Typeclass & Type
|
// Typeclass & Type
|
||||||
|
|
||||||
void Visit(ParametrizedType* node) override;
|
void Visit(ParametrizedType* node) override;
|
||||||
|
|
||||||
void Visit(TypeSubExpression& node) override; // variant
|
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visit(ExtendedName* node) override;
|
void Visit(ExtendedName* node) override;
|
||||||
|
|
|
||||||
|
|
@ -69,12 +69,12 @@ using ImportSymbol = AnyIdentifier; // can be extended name
|
||||||
|
|
||||||
struct FunctionDefinition;
|
struct FunctionDefinition;
|
||||||
struct TypeDefinition;
|
struct TypeDefinition;
|
||||||
struct AnnotatedAbstractType;
|
struct AnyAnnotatedType;
|
||||||
|
|
||||||
// TypeIdentifier <-> AbstractTypeIdentifier <-> std::string
|
// TypeIdentifier <-> AbstractTypeIdentifier <-> std::string
|
||||||
using AnnotatedType = AnnotatedAbstractType;
|
using AnnotatedType = AnyAnnotatedType;
|
||||||
|
|
||||||
using AnyAnnotatedType = AnnotatedType;
|
using AnnotatedAbstractType = AnyAnnotatedType;
|
||||||
|
|
||||||
// Flow control -----------------
|
// Flow control -----------------
|
||||||
|
|
||||||
|
|
@ -225,25 +225,19 @@ struct ExtendedScopedAnyType;
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
struct ParametrizedTypeclass;
|
struct ParametrizedTypeclass;
|
||||||
struct TypeclassExpression;
|
|
||||||
|
|
||||||
using TypeclassSubExpression = std::variant<
|
// TypeclassSubExpression -> ParametrizedTypeclass
|
||||||
std::unique_ptr<TypeclassIdentifier>,
|
|
||||||
std::unique_ptr<ParametrizedTypeclass>>;
|
|
||||||
|
|
||||||
// Typeclass & Type
|
// Typeclass & Type
|
||||||
|
|
||||||
struct ParametrizedType;
|
struct ParametrizedType;
|
||||||
|
// TypeSubExpression -> ParametrizedType
|
||||||
using TypeSubExpression = std::variant<
|
|
||||||
std::unique_ptr<AnyTypeIdentifier>,
|
|
||||||
std::unique_ptr<ParametrizedType>>;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
using FunctionArgument = std::variant<
|
using FunctionArgument = std::variant<
|
||||||
SubExpressionToken,
|
SubExpressionToken,
|
||||||
TypeSubExpression>;
|
std::unique_ptr<TypeExpression>>;
|
||||||
|
|
||||||
// Comments [IGNORE] -----------------
|
// Comments [IGNORE] -----------------
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
@ -377,9 +371,9 @@ struct TypeDefinition {
|
||||||
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AnnotatedAbstractType {
|
struct AnyAnnotatedType {
|
||||||
AbstractTypeIdentifier type;
|
AnyTypeIdentifier type;
|
||||||
std::vector<std::unique_ptr<TypeclassExpression>> typeclasses;
|
std::vector<std::unique_ptr<ParametrizedTypeclass>> typeclasses;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------- Flow control -----------------
|
// ----------------- Flow control -----------------
|
||||||
|
|
@ -552,9 +546,16 @@ struct VariantType {
|
||||||
std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors;
|
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 {
|
struct TypeExpression {
|
||||||
std::vector<TypeSubExpression> path;
|
std::vector<ParametrizedType> path;
|
||||||
TypeSubExpression type;
|
ParametrizedType type;
|
||||||
|
|
||||||
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
||||||
|
|
||||||
|
|
@ -569,24 +570,11 @@ struct ExtendedScopedAnyType {
|
||||||
|
|
||||||
// Typeclass -----------------
|
// Typeclass -----------------
|
||||||
|
|
||||||
struct TypeclassExpression {
|
|
||||||
TypeclassSubExpression typeclass;
|
|
||||||
|
|
||||||
utils::IdType typeclass_id_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ParametrizedTypeclass {
|
struct ParametrizedTypeclass {
|
||||||
TypeclassIdentifier typeclass;
|
TypeclassIdentifier typeclass;
|
||||||
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
||||||
};
|
|
||||||
|
|
||||||
// Typeclass & Type -----------------
|
utils::IdType typeclass_id_;
|
||||||
|
|
||||||
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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------- Comments [IGNORE] -----------------
|
// ----------------- Comments [IGNORE] -----------------
|
||||||
|
|
|
||||||
|
|
@ -107,18 +107,13 @@ const std::string ExtendedScopedAnyType = "extended_scoped_any_type";
|
||||||
|
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
const std::string TypeclassExpression = "typeclass_expression";
|
|
||||||
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
||||||
|
|
||||||
const std::string TypeclassSubExpression = "typeclass_subexpression";
|
|
||||||
|
|
||||||
|
|
||||||
// Typeclass & Type
|
// Typeclass & Type
|
||||||
|
|
||||||
const std::string ParametrizedType = "parametrized_type";
|
const std::string ParametrizedType = "parametrized_type";
|
||||||
|
|
||||||
const std::string TypeSubExpression = "type_subexpression";
|
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
const std::string ExtendedName = "extended_name";
|
const std::string ExtendedName = "extended_name";
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ private:
|
||||||
|
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
void Visit(TypeclassExpression* node) override;
|
|
||||||
void Visit(ParametrizedTypeclass* node) override;
|
void Visit(ParametrizedTypeclass* node) override;
|
||||||
|
|
||||||
// Typeclass & Type
|
// Typeclass & Type
|
||||||
|
|
|
||||||
|
|
@ -123,17 +123,12 @@ protected:
|
||||||
|
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
virtual void Visit(TypeclassExpression* node);
|
|
||||||
virtual void Visit(ParametrizedTypeclass* node);
|
virtual void Visit(ParametrizedTypeclass* node);
|
||||||
|
|
||||||
virtual void Visit(TypeclassSubExpression& node); // variant
|
|
||||||
|
|
||||||
// Typeclass & Type
|
// Typeclass & Type
|
||||||
|
|
||||||
virtual void Visit(ParametrizedType* node);
|
virtual void Visit(ParametrizedType* node);
|
||||||
|
|
||||||
virtual void Visit(TypeSubExpression& node); // variant
|
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
virtual void Visit(ExtendedName* node);
|
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) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
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());
|
Visit(node->typeclasses[i].get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -915,9 +915,9 @@ void BuildVisitor::Visit(FunctionArgument& node) {
|
||||||
if (current_node_type == parser::tokens::SubExpressionToken) {
|
if (current_node_type == parser::tokens::SubExpressionToken) {
|
||||||
node = SubExpressionToken();
|
node = SubExpressionToken();
|
||||||
Visit(std::get<SubExpressionToken>(node));
|
Visit(std::get<SubExpressionToken>(node));
|
||||||
} else if (current_node_type == parser::tokens::TypeSubExpression) {
|
} else if (current_node_type == parser::tokens::TypeExpression) {
|
||||||
node = TypeSubExpression();
|
node = std::make_unique<TypeExpression>();
|
||||||
Visit(std::get<TypeSubExpression>(node));
|
Visit(std::get<std::unique_ptr<TypeExpression>>(node).get());
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -1288,7 +1288,7 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("type");
|
current_node_ = parse_node.ChildByFieldName("type");
|
||||||
Visit(node->type);
|
Visit(&node->type);
|
||||||
++excluded_child_count;
|
++excluded_child_count;
|
||||||
|
|
||||||
current_node_ = current_node_.NextSibling();
|
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) {
|
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
|
||||||
current_node_ = parse_node.NthNamedChild(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
|
// 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) {
|
void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
|
|
@ -1419,28 +1390,6 @@ void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
||||||
|
|
||||||
// Typeclass & Type -----------------
|
// 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) {
|
void BuildVisitor::Visit(ParametrizedType* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
|
||||||
|
|
@ -632,10 +632,10 @@ void PrintVisitor::Visit(TypeExpression* node) {
|
||||||
|
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
for (auto& type : node->path) {
|
for (auto& type : node->path) {
|
||||||
Visitor::Visit(type);
|
Visit(&type);
|
||||||
out_ << "::";
|
out_ << "::";
|
||||||
}
|
}
|
||||||
Visitor::Visit(node->type);
|
Visit(&node->type);
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -658,12 +658,6 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
void PrintVisitor::Visit(TypeclassExpression* node) {
|
|
||||||
out_ << "[TypeclassExpression] (";
|
|
||||||
Visitor::Visit(node->typeclass);
|
|
||||||
out_ << ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintVisitor::Visit(ParametrizedTypeclass* node) {
|
void PrintVisitor::Visit(ParametrizedTypeclass* node) {
|
||||||
out_ << "[ParametrizedTypeclass] (";
|
out_ << "[ParametrizedTypeclass] (";
|
||||||
Visit(&node->typeclass);
|
Visit(&node->typeclass);
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ void Visitor::Visit(FunctionArgument& node) {
|
||||||
Visit(std::get<SubExpressionToken>(node));
|
Visit(std::get<SubExpressionToken>(node));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(std::get<TypeSubExpression>(node));
|
Visit(std::get<std::unique_ptr<TypeExpression>>(node).get());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// 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. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visitor::Visit(Literal& node) {
|
void Visitor::Visit(Literal& node) {
|
||||||
|
|
@ -697,9 +665,9 @@ void Visitor::Visit(VariantType* node) {
|
||||||
|
|
||||||
void Visitor::Visit(TypeExpression* node) {
|
void Visitor::Visit(TypeExpression* node) {
|
||||||
for (auto& type : node->path) {
|
for (auto& type : node->path) {
|
||||||
Visit(type);
|
Visit(&type);
|
||||||
}
|
}
|
||||||
Visit(node->type);
|
Visit(&node->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visitor::Visit(ExtendedScopedAnyType* node) {
|
void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
@ -708,10 +676,6 @@ void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
void Visitor::Visit(TypeclassExpression* node) {
|
|
||||||
Visit(node->typeclass);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Visitor::Visit(ParametrizedTypeclass* node) {
|
void Visitor::Visit(ParametrizedTypeclass* node) {
|
||||||
Visit(&node->typeclass);
|
Visit(&node->typeclass);
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue