mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 15:08:45 +00:00
build_visitor fixed, going to test it
This commit is contained in:
parent
5bf0c1bf48
commit
c34523bd4f
23 changed files with 45468 additions and 45273 deletions
|
|
@ -20,8 +20,8 @@ add_executable(lang_interpreter src/main.cpp
|
|||
src/visitor.cpp
|
||||
src/build_visitor.cpp
|
||||
src/print_visitor.cpp
|
||||
src/find_symbols_visitor.cpp
|
||||
src/global_info.cpp
|
||||
#src/find_symbols_visitor.cpp
|
||||
#src/global_info.cpp
|
||||
src/parser.c
|
||||
include/parser.h
|
||||
tree-sitter/lib/src/lib.c)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
// for clangd
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "visitor.hpp"
|
||||
#include "parse_tree.hpp"
|
||||
|
||||
|
|
@ -47,6 +48,8 @@ private:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void Visit(TypeConstructorPatternParameter* node) override;
|
||||
void Visit(TypeConstructorPattern* node) override;
|
||||
void Visit(MatchCase* node) override;
|
||||
void Visit(Match* node) override;
|
||||
void Visit(Condition* node) override;
|
||||
|
|
@ -55,6 +58,8 @@ private:
|
|||
void Visit(ForLoop* node) override;
|
||||
void Visit(LoopLoop* node) override;
|
||||
|
||||
void Visit(PatternToken& node) override; // variant
|
||||
void Visit(Pattern& node) override; // variant
|
||||
void Visit(FlowControl& node) override; // variant
|
||||
|
||||
// Statements, expressions, blocks, etc. -----------------
|
||||
|
|
@ -87,6 +92,7 @@ private:
|
|||
void Visit(TupleExpression* node) override;
|
||||
void Visit(VariantExpression* node) override;
|
||||
void Visit(ReturnExpression* node) override;
|
||||
void Visit(TypeConstructorParameter* node) override;
|
||||
void Visit(TypeConstructor* node) override;
|
||||
void Visit(LambdaFunction* node) override;
|
||||
void Visit(ArrayExpression* node) override;
|
||||
|
|
@ -109,7 +115,6 @@ private:
|
|||
void Visit(FunctionType* node) override;
|
||||
void Visit(TupleType* node) override;
|
||||
void Visit(VariantType* node) override;
|
||||
void Visit(ParametrizedType* node) override;
|
||||
void Visit(TypeExpression* node) override;
|
||||
|
||||
void Visit(AnyType& node) override; // variant
|
||||
|
|
@ -118,14 +123,15 @@ private:
|
|||
|
||||
// Typeclass
|
||||
|
||||
void Visit(ParametrizedTypeclass* node) override;
|
||||
void Visit(TypeclassExpression* node) override;
|
||||
void Visit(ParametrizedTypeclass* node) override;
|
||||
|
||||
void Visit(TypeclassUsage& node) override; // variant
|
||||
void Visit(TypeclassSubExpression& node) override; // variant
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
void Visit(TypeParameter& node) override; // variant
|
||||
void Visit(ParametrizedType* node) override;
|
||||
|
||||
void Visit(TypeSubExpression& node) override; // variant
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
// for clangd
|
||||
#include "utils.hpp"
|
||||
#include "types_info.hpp"
|
||||
|
||||
namespace interpreter::tokens {
|
||||
|
||||
|
|
@ -69,6 +68,7 @@ using AnyAnnotatedType = AnnotatedType;
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
struct TypeConstructorPatternParameter;
|
||||
struct TypeConstructorPattern;
|
||||
|
||||
struct Match;
|
||||
|
|
@ -167,6 +167,7 @@ struct FunctionCallExpression;
|
|||
struct TupleExpression;
|
||||
struct VariantExpression;
|
||||
struct ReturnExpression;
|
||||
struct TypeConstructorParameter;
|
||||
struct TypeConstructor;
|
||||
struct LambdaFunction;
|
||||
struct ArrayExpression;
|
||||
|
|
@ -376,9 +377,14 @@ struct AnnotatedAbstractType {
|
|||
|
||||
// ----------------- Flow control -----------------
|
||||
|
||||
struct TypeConstructorPatternParameter {
|
||||
std::optional<ExtendedName> name;
|
||||
PatternToken value;
|
||||
};
|
||||
|
||||
struct TypeConstructorPattern {
|
||||
TypeIdentifier constructor;
|
||||
std::vector<std::pair<std::optional<ExtendedName>, PatternToken>> parameters;
|
||||
std::vector<TypeConstructorPatternParameter> parameters;
|
||||
};
|
||||
|
||||
struct MatchCase {
|
||||
|
|
@ -459,8 +465,8 @@ struct AccessExpression {
|
|||
// Other Expressions -----------------
|
||||
|
||||
struct FunctionCallExpression {
|
||||
std::variant<std::unique_ptr<SubExpressionToken>,
|
||||
std::unique_ptr<TypeExpression>> prefix;
|
||||
std::optional<std::variant<std::unique_ptr<SubExpressionToken>,
|
||||
std::unique_ptr<TypeExpression>>> prefix;
|
||||
ExtendedName name;
|
||||
std::vector<FunctionArgument> arguments;
|
||||
};
|
||||
|
|
@ -477,10 +483,16 @@ struct ReturnExpression {
|
|||
Expression expression;
|
||||
};
|
||||
|
||||
struct TypeConstructor {
|
||||
struct TypeConstructorParameter {
|
||||
enum AssignmentModifier { Move, Assign };
|
||||
std::optional<ExtendedName> name;
|
||||
std::optional<AssignmentModifier> asignment_modifier;
|
||||
PatternToken value;
|
||||
};
|
||||
|
||||
struct TypeConstructor {
|
||||
std::unique_ptr<TypeExpression> constructor;
|
||||
std::vector<std::pair<std::optional<std::pair<ExtendedName, AssignmentModifier>>, SubExpression>> parameters;
|
||||
std::vector<TypeConstructorParameter> parameters;
|
||||
};
|
||||
|
||||
struct LambdaFunction {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ const std::string AnnotatedType = "annotated_type";
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
const std::string TypeConstructorPattern = "type_constructor_pattern";
|
||||
const std::string PatternToken = "pattern_token";
|
||||
const std::string Pattern = "pattern";
|
||||
const std::string MatchCase = "match_case";
|
||||
const std::string Match = "match";
|
||||
const std::string Condition = "condition";
|
||||
|
|
@ -93,7 +96,6 @@ const std::string ScopedAnyName = "scoped_any_name";
|
|||
const std::string FunctionType = "function_type";
|
||||
const std::string TupleType = "tuple_type";
|
||||
const std::string VariantType = "variant_type";
|
||||
const std::string ParametrizedType = "parametrized_type";
|
||||
const std::string TypeExpression = "type_expression";
|
||||
const std::string Constructor = "constructor";
|
||||
const std::string AnyType = "any_type";
|
||||
|
|
@ -102,13 +104,16 @@ const std::string ExtendedScopedAnyType = "extended_scoped_any_type";
|
|||
|
||||
// Typeclass
|
||||
|
||||
const std::string TypeclassUsage = "typeclass_usage";
|
||||
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
||||
const std::string TypeclassExpression = "typeclass_expression";
|
||||
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
||||
|
||||
const std::string TypeclassSubExpression = "typeclass_subexpression";
|
||||
|
||||
|
||||
// Typeclass & Type
|
||||
|
||||
const std::string TypeParameter = "type_parameter";
|
||||
const std::string ParametrizedType = "parametrized_type";
|
||||
|
||||
const std::string TypeSubExpression = "type_subexpression";
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ private:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void Visit(TypeConstructorPatternParameter* node) override;
|
||||
void Visit(TypeConstructorPattern* node) override;
|
||||
void Visit(MatchCase* node) override;
|
||||
void Visit(Match* node) override;
|
||||
|
|
@ -70,6 +71,7 @@ private:
|
|||
void Visit(TupleExpression* node) override;
|
||||
void Visit(VariantExpression* node) override;
|
||||
void Visit(ReturnExpression* node) override;
|
||||
void Visit(TypeConstructorParameter* node) override;
|
||||
void Visit(TypeConstructor* node) override;
|
||||
void Visit(LambdaFunction* node) override;
|
||||
void Visit(ArrayExpression* node) override;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ protected:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
virtual void Visit(TypeConstructorPatternParameter* node);
|
||||
virtual void Visit(TypeConstructorPattern* node);
|
||||
virtual void Visit(MatchCase* node);
|
||||
virtual void Visit(Match* node);
|
||||
|
|
@ -79,7 +80,7 @@ protected:
|
|||
virtual void Visit(ReferenceExpression* node);
|
||||
virtual void Visit(AccessExpression* node);
|
||||
|
||||
// Simple Expressions
|
||||
// Other expressions
|
||||
|
||||
virtual void Visit(FunctionCallExpression* node);
|
||||
|
||||
|
|
@ -88,6 +89,7 @@ protected:
|
|||
virtual void Visit(TupleExpression* node);
|
||||
virtual void Visit(VariantExpression* node);
|
||||
virtual void Visit(ReturnExpression* node);
|
||||
virtual void Visit(TypeConstructorParameter* node);
|
||||
virtual void Visit(TypeConstructor* node);
|
||||
virtual void Visit(LambdaFunction* node);
|
||||
virtual void Visit(ArrayExpression* node);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ void BuildVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("value");
|
||||
node->value = std::make_unique<ParametrizedType>();
|
||||
node->value = std::make_unique<TypeExpression>();
|
||||
Visit(node->value.get());
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
@ -194,7 +194,7 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
void BuildVisitor::Visit(FunctionDeclaration* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
|
|
@ -330,7 +330,7 @@ void BuildVisitor::Visit(SourceStatement& node) {
|
|||
void BuildVisitor::Visit(FunctionDefinition* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
||||
|
||||
if (parse_node.NthChild(0).GetValue() == "(") {
|
||||
node->modifier = FunctionDefinition::Operator;
|
||||
|
|
@ -395,7 +395,7 @@ void BuildVisitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
Visit(node->typeclasses[i]);
|
||||
Visit(node->typeclasses[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -404,6 +404,87 @@ void BuildVisitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void BuildVisitor::Visit(TypeConstructorPatternParameter* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
current_node_ = parse_node.ChildByFieldName("name"),
|
||||
|
||||
node->name.emplace();
|
||||
Visit(&node->name.value());
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("value"),
|
||||
Visit(node->value);
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeConstructorPattern* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
node->constructor = parse_node.ChildByFieldName("constructor").GetValue();
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
node->parameters.resize(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
Visit(&node->parameters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
|
||||
void BuildVisitor::Visit(PatternToken& 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::ExtendedName) { // optimize ??
|
||||
node = std::make_unique<ExtendedName>();
|
||||
Visit(std::get<std::unique_ptr<ExtendedName>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::Literal) {
|
||||
node = std::make_unique<Literal>();
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
} else if (current_node_type == parser::tokens::TypeConstructorPattern) {
|
||||
node = std::make_unique<TypeConstructorPattern>();
|
||||
Visit(std::get<std::unique_ptr<TypeConstructorPattern>>(node).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(Pattern& 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::TypeConstructorPattern) { // optimize ??
|
||||
node = std::make_unique<TypeConstructorPattern>();
|
||||
Visit(std::get<std::unique_ptr<TypeConstructorPattern>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::PatternToken) {
|
||||
node = std::make_unique<PatternToken>();
|
||||
Visit(*std::get<std::unique_ptr<PatternToken>>(node));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(MatchCase* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
|
|
@ -635,9 +716,6 @@ void BuildVisitor::Visit(SubExpression& node) {
|
|||
} else if (current_node_type == parser::tokens::SubExpressionToken) {
|
||||
node = std::make_unique<SubExpressionToken>();
|
||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node));
|
||||
} else if (current_node_type == parser::tokens::ArrayExpression) {
|
||||
node = std::make_unique<ArrayExpression>();
|
||||
Visit(std::get<std::unique_ptr<ArrayExpression>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::ReferenceExpression) {
|
||||
node = std::make_unique<ReferenceExpression>();
|
||||
Visit(std::get<std::unique_ptr<ReferenceExpression>>(node).get());
|
||||
|
|
@ -716,6 +794,9 @@ void BuildVisitor::Visit(SuperExpression& node) {
|
|||
} else if (current_node_type == parser::tokens::VariantExpression) {
|
||||
node = std::make_unique<VariantExpression>();
|
||||
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::ArrayExpression) {
|
||||
node = std::make_unique<ArrayExpression>();
|
||||
Visit(std::get<std::unique_ptr<ArrayExpression>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::Expression) {
|
||||
node = std::make_unique<Expression>();
|
||||
Visit(*std::get<std::unique_ptr<Expression>>(node));
|
||||
|
|
@ -823,20 +904,38 @@ void BuildVisitor::Visit(FunctionArgument& node) {
|
|||
void BuildVisitor::Visit(FunctionCallExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
size_t excluded_child_count = 0;
|
||||
|
||||
current_node_ = parse_node.NthNamedChild(0);
|
||||
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type == parser::tokens::SubExpressionToken) {
|
||||
node->prefix = std::make_unique<SubExpressionToken>();
|
||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix.value()));
|
||||
++excluded_child_count;
|
||||
} else if (current_node_type == parser::tokens::TypeExpression) {
|
||||
node->prefix = std::make_unique<TypeExpression>();
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix.value()).get());
|
||||
++excluded_child_count;
|
||||
} else {
|
||||
// no prefix
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
node->name = std::make_unique<NameExpression>();
|
||||
Visit(node->name.get());
|
||||
Visit(&node->name);
|
||||
++excluded_child_count;
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
// if (child_count > 1) { // always true (repeat1)
|
||||
node->arguments.resize(child_count - 1);
|
||||
if (child_count > excluded_child_count) { // always true (repeat1)
|
||||
node->arguments.resize(child_count - excluded_child_count);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + excluded_child_count);
|
||||
Visit(node->arguments[i]);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
|
@ -880,31 +979,45 @@ void BuildVisitor::Visit(ReturnExpression* node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeConstructor* node) {
|
||||
void BuildVisitor::Visit(TypeConstructorParameter* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
node->type = std::make_unique<ParametrizedType>();
|
||||
Visit(node->type.get());
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
size_t parameter_count = (parse_node.NamedChildCount() - 1) / 2;
|
||||
|
||||
node->parameters.resize(parameter_count);
|
||||
|
||||
for (size_t i = 0; i < parameter_count * 2; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
|
||||
if (i % 2 == 0) {
|
||||
Visit(&std::get<0>(node->parameters[i / 2]));
|
||||
if (child_count > 1) {
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
node->name.emplace();
|
||||
Visit(&node->name.value());
|
||||
|
||||
std::string assignment_modifier = current_node_.NextSibling().GetValue();
|
||||
if (assignment_modifier == "=") {
|
||||
std::get<1>(node->parameters[i / 2]) = TypeConstructor::Assign;
|
||||
node->asignment_modifier = TypeConstructorParameter::Assign;
|
||||
} else if (assignment_modifier == "<-") {
|
||||
std::get<1>(node->parameters[i / 2]) = TypeConstructor::Move;
|
||||
node->asignment_modifier = TypeConstructorParameter::Move;
|
||||
}
|
||||
} else {
|
||||
Visit(std::get<2>(node->parameters[i / 2]));
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("value");
|
||||
Visit(node->value);
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeConstructor* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("constructor");
|
||||
node->constructor = std::make_unique<TypeExpression>();
|
||||
Visit(node->constructor.get());
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
node->parameters.resize(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
Visit(&node->parameters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -976,23 +1089,10 @@ void BuildVisitor::Visit(NameExpression* node) {
|
|||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
bool namespaces_ended = false;
|
||||
|
||||
node->names.resize(child_count);
|
||||
for (size_t i = 0; i < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type != parser::tokens::TypeSubExpression) {
|
||||
namespaces_ended = true;
|
||||
}
|
||||
|
||||
if (!namespaces_ended) {
|
||||
node->namespaces.emplace_back();
|
||||
Visit(node->namespaces.back());
|
||||
} else {
|
||||
node->expressions.emplace_back();
|
||||
Visit(&node->expressions.back());
|
||||
}
|
||||
Visit(&node->names[i]);
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
@ -1037,7 +1137,7 @@ void BuildVisitor::Visit(AnnotatedName* node) {
|
|||
|
||||
if (parse_node.NamedChildCount() > 1) {
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
node->type = std::make_unique<ParametrizedType>();
|
||||
node->type.emplace();
|
||||
Visit(node->type.value());
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
@ -1156,27 +1256,6 @@ void BuildVisitor::Visit(VariantType* node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(ParametrizedType* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type_expression");
|
||||
node->type_expression = std::make_unique<TypeExpression>();
|
||||
Visit(node->type_expression.get());
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
node->parameters.resize(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
Visit(node->parameters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
|
|
@ -1185,7 +1264,7 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
node->type = current_node_.GetValue();
|
||||
Visit(node->type);
|
||||
++excluded_child_count;
|
||||
|
||||
current_node_ = current_node_.NextSibling();
|
||||
|
|
@ -1203,11 +1282,11 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
}
|
||||
|
||||
if (child_count > excluded_child_count) {
|
||||
node->namespaces.resize(child_count - excluded_child_count);
|
||||
node->path.resize(child_count - excluded_child_count);
|
||||
|
||||
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
Visit(node->namespaces[i]);
|
||||
Visit(node->path[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1222,8 +1301,8 @@ void BuildVisitor::Visit(AnyType& node) {
|
|||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type == parser::tokens::ParametrizedType) {
|
||||
node = std::make_unique<ParametrizedType>();
|
||||
Visit(std::get<std::unique_ptr<ParametrizedType>>(node).get());
|
||||
node = std::make_unique<TypeExpression>();
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::TupleType) {
|
||||
node = std::make_unique<TupleType>();
|
||||
Visit(std::get<std::unique_ptr<TupleType>>(node).get());
|
||||
|
|
@ -1265,16 +1344,36 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
|
||||
// Typeclass
|
||||
|
||||
void BuildVisitor::Visit(TypeclassUsage& node) {
|
||||
void BuildVisitor::Visit(TypeclassExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
//
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
//
|
||||
// if (child_count > 1) {
|
||||
// node->path.resize(child_count - 1);
|
||||
//
|
||||
// for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
// current_node_ = parse_node.NthNamedChild(i);
|
||||
// Visit(node->path[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
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::TypeclassExpression) {
|
||||
node = std::make_unique<TypeclassExpression>();
|
||||
Visit(std::get<std::unique_ptr<TypeclassExpression>>(node).get());
|
||||
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());
|
||||
|
|
@ -1288,9 +1387,7 @@ void BuildVisitor::Visit(TypeclassUsage& node) {
|
|||
void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("typeclass_expression");
|
||||
node->typeclass_expression = std::make_unique<TypeclassExpression>();
|
||||
Visit(node->typeclass_expression.get());
|
||||
node->typeclass = parse_node.ChildByFieldName("typeclass").GetValue();
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
|
|
@ -1299,54 +1396,16 @@ void BuildVisitor::Visit(ParametrizedTypeclass* node) {
|
|||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
Visit(node->parameters[i]);
|
||||
node->parameters[i] = std::make_unique<TypeExpression>();
|
||||
Visit(node->parameters[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(TypeclassExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
node->namespaces.resize(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
Visit(node->namespaces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
node->typeclass = parse_node.ChildByFieldName("typeclass").GetValue();
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
// Typeclass & Type -----------------
|
||||
|
||||
void BuildVisitor::Visit(TypeParameter& 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::TypeExpression) {
|
||||
node = std::make_unique<TypeExpression>();
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(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(TypeSubExpression& node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
|
|
@ -1370,6 +1429,26 @@ void BuildVisitor::Visit(TypeSubExpression& node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(ParametrizedType* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
node->type = parse_node.ChildByFieldName("type").GetValue();
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
node->parameters.resize(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
node->parameters[i] = std::make_unique<TypeExpression>();
|
||||
Visit(node->parameters[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
void BuildVisitor::Visit(ExtendedName* node) {
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ int main(int argc, char** argv) { // TODO, only test version
|
|||
std::make_unique<interpreter::tokens::SourceFile>();
|
||||
|
||||
interpreter::BuildVisitor build_visitor(parse_tree);
|
||||
interpreter::PrintVisitor print_visitor(std::cout);
|
||||
// interpreter::PrintVisitor print_visitor(std::cout);
|
||||
|
||||
build_visitor.VisitSourceFile(source_file.get());
|
||||
print_visitor.VisitSourceFile(source_file.get());
|
||||
// print_visitor.VisitSourceFile(source_file.get());
|
||||
}
|
||||
|
|
|
|||
90118
src/parser.c
90118
src/parser.c
File diff suppressed because it is too large
Load diff
|
|
@ -262,6 +262,16 @@ void PrintVisitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void PrintVisitor::Visit(TypeConstructorPatternParameter* node) {
|
||||
out_ << "[TypeConstructorPatternParameter ";
|
||||
if (node->name.has_value()) {
|
||||
Visit(&node->name.value());
|
||||
out_ << " = ";
|
||||
}
|
||||
Visitor::Visit(node->value);
|
||||
out_ << "]";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(TypeConstructorPattern* node) {
|
||||
out_ << "[TypeConstructorPattern ";
|
||||
Visit(&node->constructor);
|
||||
|
|
@ -274,11 +284,7 @@ void PrintVisitor::Visit(TypeConstructorPattern* node) {
|
|||
is_first = false;
|
||||
}
|
||||
out_ << '(';
|
||||
if (parameter.first.has_value()) {
|
||||
Visit(¶meter.first.value());
|
||||
out_ << " = ";
|
||||
}
|
||||
Visitor::Visit(parameter.second);
|
||||
Visit(¶meter);
|
||||
}
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
|
@ -434,17 +440,19 @@ void PrintVisitor::Visit(AccessExpression* node) {
|
|||
// Other Expressions
|
||||
|
||||
void PrintVisitor::Visit(FunctionCallExpression* node) {
|
||||
out_ << "[FunctionCall (";
|
||||
out_ << "[FunctionCall ";
|
||||
|
||||
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix)) {
|
||||
Visitor::Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TypeExpression>>(node->prefix)) {
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix).get());
|
||||
if (node->prefix.has_value()) {
|
||||
out_ << '(';
|
||||
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix.value())) {
|
||||
Visitor::Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix.value()));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TypeExpression>>(node->prefix.value())) {
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix.value()).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
out_ << ").";
|
||||
}
|
||||
|
||||
Visit(&node->name);
|
||||
|
||||
|
|
@ -480,6 +488,23 @@ void PrintVisitor::Visit(ReturnExpression* node) {
|
|||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(TypeConstructorParameter* node) {
|
||||
out_ << "[TypeConstructorParameter ";
|
||||
if (node->name.has_value()) {
|
||||
Visit(&node->name.value());
|
||||
switch (node->asignment_modifier.value()) {
|
||||
case TypeConstructorParameter::Assign:
|
||||
out_ << " = ";
|
||||
break;
|
||||
case TypeConstructorParameter::Move:
|
||||
out_ << " <- ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
Visitor::Visit(node->value);
|
||||
out_ << "]";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(TypeConstructor* node) {
|
||||
out_ << "[TypeConstructor ";
|
||||
Visit(node->constructor.get());
|
||||
|
|
@ -492,18 +517,7 @@ void PrintVisitor::Visit(TypeConstructor* node) {
|
|||
is_first = false;
|
||||
}
|
||||
out_ << '(';
|
||||
if (parameter.first.has_value()) {
|
||||
Visit(¶meter.first.value().first);
|
||||
switch (parameter.first.value().second) {
|
||||
case TypeConstructor::Assign:
|
||||
out_ << " = ";
|
||||
break;
|
||||
case TypeConstructor::Move:
|
||||
out_ << " <- ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
Visitor::Visit(parameter.second);
|
||||
Visit(¶meter);
|
||||
}
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -448,13 +448,17 @@ void Visitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void Visitor::Visit(TypeConstructorPatternParameter* node) {
|
||||
if (node->name.has_value()) {
|
||||
Visit(&node->name.value());
|
||||
}
|
||||
Visit(node->value);
|
||||
}
|
||||
|
||||
void Visitor::Visit(TypeConstructorPattern* node) {
|
||||
Visit(&node->constructor);
|
||||
for (auto& parameter : node->parameters) {
|
||||
if (parameter.first.has_value()) {
|
||||
Visit(¶meter.first.value());
|
||||
}
|
||||
Visit(parameter.second);
|
||||
Visit(¶meter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -543,13 +547,15 @@ void Visitor::Visit(AccessExpression* node) {
|
|||
// Other Expressions
|
||||
|
||||
void Visitor::Visit(FunctionCallExpression* node) {
|
||||
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix)) {
|
||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TypeExpression>>(node->prefix)) {
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix).get());
|
||||
if (node->prefix.has_value()) {
|
||||
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix.value())) {
|
||||
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix.value()));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TypeExpression>>(node->prefix.value())) {
|
||||
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix.value()).get());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
}
|
||||
|
||||
Visit(&node->name);
|
||||
for (auto& argument : node->arguments) {
|
||||
|
|
@ -573,13 +579,17 @@ void Visitor::Visit(ReturnExpression* node) {
|
|||
Visit(node->expression);
|
||||
}
|
||||
|
||||
void Visitor::Visit(TypeConstructorParameter* node) {
|
||||
if (node->name.has_value()) {
|
||||
Visit(&node->name.value());
|
||||
}
|
||||
Visit(node->value);
|
||||
}
|
||||
|
||||
void Visitor::Visit(TypeConstructor* node) {
|
||||
Visit(node->constructor.get());
|
||||
for (auto& parameter : node->parameters) {
|
||||
if (parameter.first.has_value()) {
|
||||
Visit(¶meter.first.value().first);
|
||||
}
|
||||
Visit(parameter.second);
|
||||
Visit(¶meter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
decl test_arrays : Unit -> Unit
|
||||
def test_arrays = {
|
||||
var arr1 = [1; 2; 3]
|
||||
const arr2 = []
|
||||
var arr3 = []
|
||||
var arr1 = ,1 ,2 ,3
|
||||
const arr2 = Int._array 32
|
||||
var arr3 = String._array 11
|
||||
const arr4 = 'a'..'z'
|
||||
const n = 100
|
||||
var @arr5 = @$Int_n
|
||||
var @arr5 <- Int.@_new_array 10
|
||||
|
||||
var @arr6 = @$Int_n
|
||||
var @arr6_pointer = @arr6
|
||||
var @arr6 <- String.@_new_array 10
|
||||
var ~arr6_reference = ~arr6
|
||||
|
||||
const elem1 = arr1.1
|
||||
var elem2 = arr1.1
|
||||
const ~ref1 = ~arr1.1
|
||||
var ~ref2 = ~arr1.1
|
||||
; ~arr1.1 = 123
|
||||
const elem1 = arr1:0
|
||||
var elem2 = arr1:2
|
||||
const ~ref1 = ~arr1:1
|
||||
var ~ref2 = ~arr1:3
|
||||
; arr1:1 = 123
|
||||
|
||||
; ref1 = arr1.2 // set value
|
||||
; ref1 = arr1:2 // set value
|
||||
; ~ref1 = ~ref2 // set reference
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Employee =
|
|||
& salary : Int
|
||||
| Programmer
|
||||
& skills : Float
|
||||
& current_task : Optional Task
|
||||
& current_task : (Optional Task)
|
||||
& salary : Int)
|
||||
|
||||
|
||||
|
|
@ -56,5 +56,4 @@ class Bag =
|
|||
& weight_g : Int
|
||||
& weight_g : Int
|
||||
| Big)
|
||||
& other_things : Array Something
|
||||
|
||||
& other_things : (Array Something)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ namespace Employee {
|
|||
& name = "John"
|
||||
& role =
|
||||
($Manager
|
||||
& name = "John"
|
||||
& "John"
|
||||
& productivity =
|
||||
($Productivity.High
|
||||
($Productivity::High
|
||||
& duration = 10.3
|
||||
& sleep_on_work = ($Productivity.SleepOnWork.No))
|
||||
& sleep_on_work = ($Productivity::SleepOnWork::No))
|
||||
& salary = 123)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ def flow_control_test = {
|
|||
return {}
|
||||
}
|
||||
|
||||
while (a > 0) && (!array.is_empty) do {
|
||||
while (a > 0) && (!array.is_empty ()) do {
|
||||
; --a
|
||||
; array.pop
|
||||
; array->pop
|
||||
}
|
||||
|
||||
while x < 10 do
|
||||
|
|
|
|||
|
|
@ -5,39 +5,40 @@ decl fib : Int -> Int
|
|||
def fib : n =
|
||||
match n with
|
||||
| 0 | 1 -> 1
|
||||
| _ -> fib (n - 1) + fib n
|
||||
| n ? n > 1 -> fib (n - 1) + fib n
|
||||
| _ -> error "n must be positive"
|
||||
|
||||
decl fact : Int -> Int
|
||||
def fact : n =
|
||||
match n with
|
||||
| 0 -> 1
|
||||
| n -> n * fact (n - 1)
|
||||
| n ? n > 0 -> n * fact (n - 1)
|
||||
| _ -> error "n must be positive"
|
||||
|
||||
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
|
||||
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> (Array 'H)
|
||||
def find_prefix_hashes 'H : str = {
|
||||
var hashes = (Array 'H).new (str.size + 1)
|
||||
var hashes = (Array 'H).new (str.size () + 1)
|
||||
|
||||
; hashes.0 = 'H.of str.0
|
||||
for i in 1..hashes.size do {
|
||||
; hashes.i = hashes.(i - 1).clone
|
||||
; hashes.i.append str.i
|
||||
; hashes:0 = 'H.of str:0
|
||||
for i in 1..hashes.size () do {
|
||||
; hashes:i = hashes:(i - 1)
|
||||
; hashes:i.append str:i
|
||||
}
|
||||
|
||||
return hashes
|
||||
}
|
||||
|
||||
alias Hash = AccHash Char
|
||||
alias Hash = (AccHash Char)
|
||||
|
||||
decl find_substring : String -> String -> Array Index
|
||||
decl find_substring : String -> String -> (Array Index)
|
||||
def find_substring : str substr = {
|
||||
|
||||
var result = (Array Index).empty
|
||||
var result = (Array Index).empty ()
|
||||
|
||||
const str_hashes = find_prefix_hashes Hash str
|
||||
const substr_hash = Hash.of substr
|
||||
|
||||
for i in 0..(str_hashes.size - substr.size) do {
|
||||
const part_hash = Hash.diff str_hashes.(i + substr.size) str_hashes.i
|
||||
for i in 0..(str_hashes.size () - substr.size ()) do {
|
||||
const part_hash = Hash.diff str_hashes:(i + substr->size ()) str_hashes:i
|
||||
|
||||
if part_hash == substr_hash then {
|
||||
; result.push i
|
||||
|
|
@ -48,8 +49,7 @@ def find_substring : str substr = {
|
|||
}
|
||||
|
||||
decl is_empty : Unit -> Bool
|
||||
def is_empty =
|
||||
return 0
|
||||
def is_empty = 0
|
||||
|
||||
decl do_something : Unit -> Unit
|
||||
def do_something =
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
decl test_lambdas : Unit -> Unit
|
||||
def test_lambdas = {
|
||||
const lambda1 = \x -> x * x
|
||||
const lambda2 = \x -> x.hash
|
||||
const lambda2 = \x -> x.hash ()
|
||||
const lambda3 = \x y -> x + y
|
||||
|
||||
const lambda4 = \x -> {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ def fruit_cost : fruit = {
|
|||
|
||||
def amount_to_string : x is_zero_separated = {
|
||||
const ans = match x with
|
||||
| 0 ? is_zero_separated -> "Zero"
|
||||
| 0 ? is_zero_separated () -> "Zero"
|
||||
| 0 | 1 | 2 | 3 | 4 -> "Few"
|
||||
| x ? (5..9).contains x -> "Several"
|
||||
| x ? (10..19).contains x -> "Pack"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ struct StructWithRef =
|
|||
|
||||
decl test_memory : Unit -> Unit
|
||||
def test_memory = {
|
||||
const @unique_ref1 <- @(5)
|
||||
var @unique_ref2 <- @(Array.of 1 2 3)
|
||||
const @unique_ref1 <- Int.@_new 5
|
||||
var @unique_ref2 <- Array.@of 1 2 3
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,6 @@ partition INTERFACE { // or .interface.lang filename
|
|||
decl something : Unit -> Unit
|
||||
}
|
||||
|
||||
partition CORE { // or .core.lang filename
|
||||
decl something : Unit -> Unit
|
||||
}
|
||||
|
||||
partition LIB { // or .lib.lang filename
|
||||
decl something : Unit -> Unit
|
||||
}
|
||||
|
||||
partition MODULE { // or .module.lang filename
|
||||
decl something : Unit -> Unit
|
||||
}
|
||||
|
||||
partition EXE { // or .exe.lang filename
|
||||
partition CODE { // or .core.lang filename
|
||||
decl something : Unit -> Unit
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,5 @@ def test_tuples = {
|
|||
var tuple1 = & "a" & 2 & "hello"
|
||||
const & t1 & t2 & t3 = f x
|
||||
|
||||
; tuple1.0 = "b"
|
||||
|
||||
; tuple1:0 = "b"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ alias T1 = Int
|
|||
abstract (T2 : #A #B #C)
|
||||
|
||||
// Used to pre-compile module for some types
|
||||
let T2 = Int
|
||||
let T2 = Float
|
||||
let T2 = Complex
|
||||
// let T2 = Int
|
||||
// let T2 = Float
|
||||
// let T2 = Complex
|
||||
|
|
|
|||
|
|
@ -3,16 +3,13 @@ def test_variants = {
|
|||
var variant1 = | 'a' | 2 | "hello"
|
||||
var | val | err = f x
|
||||
|
||||
; val -> "something" // open variant as value in expr
|
||||
; val -?> "something" // open variant as value in expr
|
||||
|
||||
; val -!> "nothing" // open variant as None in expr
|
||||
|
||||
match variant1 with
|
||||
| 'a' -> "something"
|
||||
| 2 -> "something"
|
||||
| "hello" -> "something"
|
||||
| a -> "Something"
|
||||
| String.of str -> "something"
|
||||
| Int.of i -> "someting"
|
||||
| 2 -> "nothing"
|
||||
| "hello" -> "nothing"
|
||||
| 11 -> "nothing"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue