2023-03-26 15:20:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <variant>
|
2023-03-26 23:15:42 +03:00
|
|
|
#include <optional>
|
2023-03-26 15:20:53 +03:00
|
|
|
#include <memory>
|
|
|
|
|
|
2023-04-17 12:09:02 +03:00
|
|
|
// for clangd
|
|
|
|
|
#include "utils.hpp"
|
|
|
|
|
|
2023-04-02 15:10:32 +03:00
|
|
|
namespace interpreter::tokens {
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// ----------------- Declarations -----------------
|
|
|
|
|
|
|
|
|
|
using AnyIdentifier = std::string;
|
|
|
|
|
using NameOrOperatorIdentifier = std::string;
|
|
|
|
|
using NameIdentifier = std::string;
|
|
|
|
|
using AnyTypeIdentifier = std::string;
|
|
|
|
|
using TypeIdentifier = std::string;
|
|
|
|
|
using AbstractTypeIdentifier = std::string;
|
|
|
|
|
using OperatorIdentifier = std::string;
|
|
|
|
|
using TypeclassIdentifier = std::string;
|
|
|
|
|
|
|
|
|
|
// Sources -----------------
|
|
|
|
|
|
2023-03-26 16:19:30 +03:00
|
|
|
struct SourceFile;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-02 15:10:32 +03:00
|
|
|
// Namespaces, partitions -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
struct Partition;
|
2023-04-29 13:44:34 +03:00
|
|
|
struct PartitionSources;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct Namespace;
|
2023-04-29 13:44:34 +03:00
|
|
|
struct NamespaceSources;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Definitions -----------------
|
|
|
|
|
|
|
|
|
|
struct ImportStatement;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct AliasDefinitionStatement;
|
|
|
|
|
struct VariableDefinitionStatement;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct FunctionDeclaration;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinitionStatement;
|
|
|
|
|
struct TypeDefinitionStatement;
|
|
|
|
|
struct AbstractTypeDefinitionStatement;
|
|
|
|
|
struct TypeclassDefinitionStatement;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-29 13:44:34 +03:00
|
|
|
//
|
|
|
|
|
using NamespaceStatement = std::variant<
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<AliasDefinitionStatement>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<FunctionDeclaration>,
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<FunctionDefinitionStatement>,
|
|
|
|
|
std::unique_ptr<TypeDefinitionStatement>,
|
2023-04-29 13:44:34 +03:00
|
|
|
std::unique_ptr<Namespace>>;
|
|
|
|
|
//
|
|
|
|
|
using PartitionStatement = std::variant<
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
|
|
|
|
std::unique_ptr<TypeclassDefinitionStatement>,
|
2023-04-29 13:44:34 +03:00
|
|
|
std::unique_ptr<NamespaceStatement>>;
|
|
|
|
|
//
|
|
|
|
|
using SourceStatement = std::variant<
|
|
|
|
|
std::unique_ptr<ImportStatement>,
|
|
|
|
|
std::unique_ptr<Partition>,
|
|
|
|
|
std::unique_ptr<PartitionStatement>>;
|
|
|
|
|
//
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Definition parts
|
|
|
|
|
|
2023-04-25 13:22:23 +03:00
|
|
|
using ImportSymbol = AnyIdentifier; // can be extended name
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinition;
|
|
|
|
|
struct TypeDefinition;
|
2023-05-02 17:30:57 +03:00
|
|
|
struct AnyAnnotatedType;
|
2023-04-12 13:31:39 +03:00
|
|
|
|
|
|
|
|
// TypeIdentifier <-> AbstractTypeIdentifier <-> std::string
|
2023-05-02 17:30:57 +03:00
|
|
|
using AnnotatedType = AnyAnnotatedType;
|
2023-04-12 13:31:39 +03:00
|
|
|
|
2023-05-02 17:30:57 +03:00
|
|
|
using AnnotatedAbstractType = AnyAnnotatedType;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Flow control -----------------
|
|
|
|
|
|
2023-04-25 21:21:36 +03:00
|
|
|
struct TypeConstructorPatternParameter;
|
2023-04-25 13:22:23 +03:00
|
|
|
struct TypeConstructorPattern;
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
struct Match;
|
|
|
|
|
struct Condition;
|
2023-03-26 16:19:30 +03:00
|
|
|
struct DoWhileLoop;
|
|
|
|
|
struct WhileLoop;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct ForLoop;
|
|
|
|
|
struct LoopLoop;
|
|
|
|
|
|
|
|
|
|
using FlowControl = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<Match>,
|
|
|
|
|
std::unique_ptr<Condition>,
|
|
|
|
|
std::unique_ptr<DoWhileLoop>,
|
|
|
|
|
std::unique_ptr<WhileLoop>,
|
|
|
|
|
std::unique_ptr<ForLoop>,
|
|
|
|
|
std::unique_ptr<LoopLoop>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Statements, expressions, blocks, etc. -----------------
|
|
|
|
|
|
|
|
|
|
struct Block;
|
|
|
|
|
|
2023-04-21 14:27:55 +03:00
|
|
|
struct FloatNumberLiteral;
|
|
|
|
|
struct NumberLiteral;
|
|
|
|
|
struct StringLiteral;
|
|
|
|
|
struct CharLiteral;
|
2023-04-26 01:02:53 +03:00
|
|
|
struct UnitLiteral;
|
2023-04-21 14:27:55 +03:00
|
|
|
|
|
|
|
|
using Literal = std::variant<
|
|
|
|
|
std::unique_ptr<FloatNumberLiteral>,
|
|
|
|
|
std::unique_ptr<NumberLiteral>,
|
|
|
|
|
std::unique_ptr<StringLiteral>,
|
2023-04-26 01:02:53 +03:00
|
|
|
std::unique_ptr<CharLiteral>,
|
|
|
|
|
std::unique_ptr<UnitLiteral>>;
|
2023-04-21 14:27:55 +03:00
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
2023-04-09 13:43:01 +03:00
|
|
|
struct NameExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct ScopedStatement;
|
2023-04-21 14:27:55 +03:00
|
|
|
struct AccessExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
using SubExpressionToken = std::variant<
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<NameExpression>,
|
2023-04-21 14:27:55 +03:00
|
|
|
std::unique_ptr<ScopedStatement>,
|
|
|
|
|
std::unique_ptr<AccessExpression>,
|
|
|
|
|
std::unique_ptr<Literal>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
|
|
|
|
struct FunctionCallExpression;
|
|
|
|
|
struct BinaryOperatorExpression;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ArrayExpression;
|
|
|
|
|
struct ReferenceExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
using SubExpression = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<FunctionCallExpression>,
|
|
|
|
|
std::unique_ptr<BinaryOperatorExpression>,
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<SubExpressionToken>,
|
|
|
|
|
std::unique_ptr<ReferenceExpression>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
2023-04-09 13:43:01 +03:00
|
|
|
enum class LoopControlExpression {
|
|
|
|
|
Break,
|
|
|
|
|
Continue,
|
|
|
|
|
};
|
2023-04-09 14:13:47 +03:00
|
|
|
//
|
2023-03-26 15:20:53 +03:00
|
|
|
struct ReturnExpression;
|
|
|
|
|
using PrefixedExpression = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<ReturnExpression>,
|
|
|
|
|
std::unique_ptr<LoopControlExpression>,
|
|
|
|
|
std::unique_ptr<Block>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
|
|
|
|
struct LambdaFunction;
|
|
|
|
|
struct TypeConstructor;
|
|
|
|
|
struct UnaryOperatorExpression;
|
|
|
|
|
using Expression = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<LambdaFunction>,
|
|
|
|
|
std::unique_ptr<TypeConstructor>,
|
|
|
|
|
std::unique_ptr<PrefixedExpression>,
|
|
|
|
|
std::unique_ptr<UnaryOperatorExpression>,
|
|
|
|
|
std::unique_ptr<SubExpression>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
|
|
|
|
struct TupleExpression;
|
|
|
|
|
struct VariantExpression;
|
|
|
|
|
using SuperExpression = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<FlowControl>,
|
|
|
|
|
std::unique_ptr<TupleExpression>,
|
|
|
|
|
std::unique_ptr<VariantExpression>,
|
2023-04-25 13:22:23 +03:00
|
|
|
std::unique_ptr<ArrayExpression>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<Expression>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
//
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ScopedStatement;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Operators
|
|
|
|
|
|
|
|
|
|
struct BinaryOperatorExpression;
|
|
|
|
|
struct UnaryOperatorExpression;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ReferenceExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-10 01:48:07 +03:00
|
|
|
// Other expressions
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
struct FunctionCallExpression;
|
2023-04-09 13:43:01 +03:00
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
struct TupleExpression;
|
|
|
|
|
struct VariantExpression;
|
|
|
|
|
struct ReturnExpression;
|
2023-04-25 21:21:36 +03:00
|
|
|
struct TypeConstructorParameter;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeConstructor;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct LambdaFunction;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ArrayExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Name
|
|
|
|
|
|
|
|
|
|
struct NameExpression;
|
|
|
|
|
struct TupleName;
|
|
|
|
|
struct VariantName;
|
|
|
|
|
struct AnnotatedName;
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// // ScopedAnyName <-> AnyName
|
2023-03-26 15:20:53 +03:00
|
|
|
using AnyName = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<AnnotatedName>,
|
|
|
|
|
std::unique_ptr<TupleName>,
|
|
|
|
|
std::unique_ptr<VariantName>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
using ScopedAnyName = AnyName;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// Type, typeclass, etc. -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// Type
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionType;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct TupleType;
|
|
|
|
|
struct VariantType;
|
2023-04-25 13:22:23 +03:00
|
|
|
struct TypeExpression;
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeExpression;
|
|
|
|
|
|
|
|
|
|
using Constructor = std::string;
|
|
|
|
|
|
|
|
|
|
// // ScopedAnyType <-> AnyType
|
2023-03-26 15:20:53 +03:00
|
|
|
using AnyType = std::variant<
|
2023-04-25 13:22:23 +03:00
|
|
|
std::unique_ptr<TypeExpression>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<TupleType>,
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<VariantType>,
|
|
|
|
|
std::unique_ptr<FunctionType>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
using ScopedAnyType = AnyType;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ExtendedScopedAnyType;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Typeclass
|
|
|
|
|
|
|
|
|
|
struct ParametrizedTypeclass;
|
|
|
|
|
|
2023-05-02 17:30:57 +03:00
|
|
|
// TypeclassSubExpression -> ParametrizedTypeclass
|
2023-04-09 13:43:01 +03:00
|
|
|
|
|
|
|
|
// Typeclass & Type
|
|
|
|
|
|
2023-04-25 13:22:23 +03:00
|
|
|
struct ParametrizedType;
|
2023-05-02 17:30:57 +03:00
|
|
|
// TypeSubExpression -> ParametrizedType
|
2023-04-09 13:43:01 +03:00
|
|
|
|
2023-04-11 13:49:22 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
using FunctionArgument = std::variant<
|
|
|
|
|
SubExpressionToken,
|
2023-05-02 17:30:57 +03:00
|
|
|
std::unique_ptr<TypeExpression>>;
|
2023-04-11 13:49:22 +03:00
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
// Comments [IGNORE] -----------------
|
|
|
|
|
// Identifiers, constants, etc. -----------------
|
|
|
|
|
|
2023-04-09 18:49:52 +03:00
|
|
|
struct ExtendedName {
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
2023-04-09 13:43:01 +03:00
|
|
|
|
2023-04-25 13:22:23 +03:00
|
|
|
using PatternToken = std::variant<
|
|
|
|
|
std::unique_ptr<ExtendedName>,
|
|
|
|
|
std::unique_ptr<Literal>,
|
|
|
|
|
std::unique_ptr<TypeConstructorPattern>>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Pattern = std::variant<
|
|
|
|
|
std::unique_ptr<TypeConstructorPattern>,
|
|
|
|
|
std::unique_ptr<PatternToken>>;
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
// ----------------- Sources -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct SourceFile {
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<SourceStatement> statements;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Namespaces, partittions -----------------
|
|
|
|
|
|
2023-04-29 13:44:34 +03:00
|
|
|
struct PartitionSources {
|
|
|
|
|
std::vector<PartitionStatement> statements;
|
2023-04-09 13:43:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Partition {
|
|
|
|
|
enum PartitionName {
|
2023-03-26 15:20:53 +03:00
|
|
|
Test,
|
|
|
|
|
Interface,
|
2023-04-26 01:02:53 +03:00
|
|
|
Code,
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
PartitionName name;
|
2023-04-29 13:44:34 +03:00
|
|
|
PartitionSources scope;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NamespaceSources {
|
|
|
|
|
std::vector<NamespaceStatement> statements;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Namespace {
|
|
|
|
|
enum Modifier { Const, Var };
|
|
|
|
|
std::optional<Modifier> modifier; // modifier => variable namespace
|
|
|
|
|
TypeIdentifier type;
|
|
|
|
|
NamespaceSources scope;
|
|
|
|
|
|
2023-05-02 15:18:08 +03:00
|
|
|
std::optional<utils::IdType> link_type_id_;
|
|
|
|
|
std::optional<utils::IdType> link_typeclass_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Definitions -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ImportStatement {
|
|
|
|
|
std::optional<TypeIdentifier> name;
|
2023-03-26 15:20:53 +03:00
|
|
|
std::string module_name;
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<ImportSymbol> symbols;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct AliasDefinitionStatement {
|
2023-04-09 16:01:07 +03:00
|
|
|
enum {Alias, Type, Let} modifier;
|
2023-04-09 13:43:01 +03:00
|
|
|
TypeIdentifier type;
|
|
|
|
|
std::vector<AbstractTypeIdentifier> parameters;
|
2023-04-25 13:22:23 +03:00
|
|
|
std::unique_ptr<TypeExpression> value;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
|
|
|
|
utils::IdType type_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct VariableDefinitionStatement {
|
|
|
|
|
enum { Var, Const } modifier;
|
2023-04-11 13:49:22 +03:00
|
|
|
enum { Move, Assign } assignment_modifier;
|
2023-04-09 13:43:01 +03:00
|
|
|
AnyName name;
|
2023-03-26 23:15:42 +03:00
|
|
|
SuperExpression value;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDeclaration {
|
2023-04-25 13:22:23 +03:00
|
|
|
ExtendedName name;
|
2023-04-12 13:31:39 +03:00
|
|
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<FunctionType> type;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
|
|
|
|
utils::IdType function_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinitionStatement {
|
2023-04-11 13:49:22 +03:00
|
|
|
bool is_inline;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<FunctionDefinition> definition;
|
2023-03-26 23:15:42 +03:00
|
|
|
SuperExpression value;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
|
|
|
|
utils::IdType function_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeDefinitionStatement {
|
|
|
|
|
enum { Struct, Class } modifier;
|
|
|
|
|
std::unique_ptr<TypeDefinition> definition;
|
|
|
|
|
AnyType value;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
|
|
|
|
utils::IdType type_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct AbstractTypeDefinitionStatement {
|
|
|
|
|
enum { Basic, Abstract } modifier;
|
2023-04-09 18:49:52 +03:00
|
|
|
std::unique_ptr<AnnotatedType> type;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
2023-04-17 18:56:58 +03:00
|
|
|
utils::IdType type_graph_id_;
|
2023-04-17 12:09:02 +03:00
|
|
|
utils::IdType type_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeclassDefinitionStatement {
|
|
|
|
|
std::unique_ptr<TypeDefinition> definition;
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<std::unique_ptr<FunctionDeclaration>> requirements;
|
2023-04-17 12:09:02 +03:00
|
|
|
|
|
|
|
|
utils::IdType typeclass_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Definition parts -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinition {
|
|
|
|
|
enum { Operator, Function } modifier;
|
2023-04-25 13:22:23 +03:00
|
|
|
ExtendedName name;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::vector<ExtendedName> arguments;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeDefinition {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<AnnotatedType> type;
|
2023-04-12 13:31:39 +03:00
|
|
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-05-02 17:30:57 +03:00
|
|
|
struct AnyAnnotatedType {
|
|
|
|
|
AnyTypeIdentifier type;
|
|
|
|
|
std::vector<std::unique_ptr<ParametrizedTypeclass>> typeclasses;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Flow control -----------------
|
|
|
|
|
|
2023-04-25 21:21:36 +03:00
|
|
|
struct TypeConstructorPatternParameter {
|
|
|
|
|
std::optional<ExtendedName> name;
|
|
|
|
|
PatternToken value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-25 13:22:23 +03:00
|
|
|
struct TypeConstructorPattern {
|
2023-04-29 09:33:59 +03:00
|
|
|
std::unique_ptr<TypeExpression> constructor;
|
2023-04-25 21:21:36 +03:00
|
|
|
std::vector<TypeConstructorPatternParameter> parameters;
|
2023-04-25 13:22:23 +03:00
|
|
|
};
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
struct MatchCase {
|
2023-04-25 13:22:23 +03:00
|
|
|
Pattern value;
|
2023-03-26 23:15:42 +03:00
|
|
|
std::optional<Expression> condition;
|
|
|
|
|
std::optional<Expression> statement;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct Match {
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression value;
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<MatchCase> matches;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct Condition {
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<Expression> conditions; // if, elif
|
|
|
|
|
std::vector<Expression> statements; // if, elif, else
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct DoWhileLoop {
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression condition;
|
|
|
|
|
Expression statement;
|
2023-03-26 16:19:30 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct WhileLoop {
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression condition;
|
|
|
|
|
Expression statement;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ForLoop {
|
2023-03-26 23:15:42 +03:00
|
|
|
AnyName variable;
|
|
|
|
|
Expression interval;
|
|
|
|
|
Expression statement;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct LoopLoop {
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression statement;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Statements, expressions, blocks, etc. -----------------
|
|
|
|
|
|
|
|
|
|
using BlockStatement = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<Expression>,
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<VariableDefinitionStatement>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<FlowControl>,
|
|
|
|
|
std::unique_ptr<PrefixedExpression>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct Block {
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<BlockStatement> statements;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ScopedStatement {
|
2023-03-26 23:15:42 +03:00
|
|
|
SuperExpression statement;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Operators -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct BinaryOperatorExpression {
|
2023-03-26 15:20:53 +03:00
|
|
|
OperatorIdentifier operator_name;
|
2023-03-26 23:15:42 +03:00
|
|
|
SubExpression left_expression;
|
|
|
|
|
SubExpression right_expression;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct UnaryOperatorExpression {
|
2023-03-26 15:20:53 +03:00
|
|
|
OperatorIdentifier operator_name;
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression expression;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ReferenceExpression {
|
2023-04-21 14:27:55 +03:00
|
|
|
std::vector<utils::ReferenceType> references;
|
2023-04-09 16:01:07 +03:00
|
|
|
std::unique_ptr<ScopedStatement> expression;
|
2023-04-09 14:13:47 +03:00
|
|
|
};
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-21 14:27:55 +03:00
|
|
|
struct AccessExpression {
|
|
|
|
|
std::unique_ptr<NameExpression> name;
|
|
|
|
|
SubExpressionToken id;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 16:01:07 +03:00
|
|
|
// Other Expressions -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionCallExpression {
|
2023-04-25 21:21:36 +03:00
|
|
|
std::optional<std::variant<std::unique_ptr<SubExpressionToken>,
|
|
|
|
|
std::unique_ptr<TypeExpression>>> prefix;
|
2023-04-25 13:22:23 +03:00
|
|
|
ExtendedName name;
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<FunctionArgument> arguments;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TupleExpression {
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<SubExpression> expressions;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct VariantExpression {
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<SubExpression> expressions;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ReturnExpression {
|
2023-03-27 03:10:04 +03:00
|
|
|
Expression expression;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-25 21:21:36 +03:00
|
|
|
struct TypeConstructorParameter {
|
2023-04-11 13:49:22 +03:00
|
|
|
enum AssignmentModifier { Move, Assign };
|
2023-04-25 21:21:36 +03:00
|
|
|
std::optional<ExtendedName> name;
|
|
|
|
|
std::optional<AssignmentModifier> asignment_modifier;
|
2023-04-26 01:02:53 +03:00
|
|
|
SubExpression value;
|
2023-04-25 21:21:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct TypeConstructor {
|
2023-04-25 13:22:23 +03:00
|
|
|
std::unique_ptr<TypeExpression> constructor;
|
2023-04-25 21:21:36 +03:00
|
|
|
std::vector<TypeConstructorParameter> parameters;
|
2023-04-09 13:43:01 +03:00
|
|
|
};
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct LambdaFunction {
|
2023-04-12 13:31:39 +03:00
|
|
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::vector<ExtendedName> arguments;
|
2023-03-27 03:10:04 +03:00
|
|
|
Expression expression;
|
2023-04-22 19:30:16 +03:00
|
|
|
|
|
|
|
|
std::vector<utils::IdType> argument_graph_ids_;
|
|
|
|
|
utils::IdType return_type_graph_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ArrayExpression {
|
2023-04-25 13:22:23 +03:00
|
|
|
std::vector<SubExpression> elements;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// Name -----------------
|
|
|
|
|
|
|
|
|
|
struct NameExpression {
|
2023-04-25 13:22:23 +03:00
|
|
|
std::vector<ExtendedName> names;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TupleName {
|
2023-04-09 16:01:07 +03:00
|
|
|
std::vector<ScopedAnyName> names;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct VariantName {
|
2023-04-09 16:01:07 +03:00
|
|
|
std::vector<ScopedAnyName> names;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct AnnotatedName {
|
2023-03-26 15:20:53 +03:00
|
|
|
NameIdentifier name;
|
2023-04-09 16:01:07 +03:00
|
|
|
std::optional<ScopedAnyType> type;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 16:01:07 +03:00
|
|
|
// ----------------- Type, typeclass, etc. -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Type -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionType {
|
|
|
|
|
std::vector<ScopedAnyType> types;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TupleType {
|
|
|
|
|
std::optional<Constructor> type;
|
2023-04-09 16:01:07 +03:00
|
|
|
std::vector<std::pair<std::optional<ExtendedName>, std::unique_ptr<ExtendedScopedAnyType>>> entities;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct VariantType {
|
|
|
|
|
std::optional<Constructor> type;
|
|
|
|
|
std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-05-02 17:30:57 +03:00
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeExpression {
|
2023-05-02 17:30:57 +03:00
|
|
|
std::vector<ParametrizedType> path;
|
|
|
|
|
ParametrizedType type;
|
2023-04-25 15:10:48 +03:00
|
|
|
|
2023-04-11 13:49:22 +03:00
|
|
|
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
2023-05-02 16:51:47 +03:00
|
|
|
|
|
|
|
|
std::optional<utils::IdType> type_id_;
|
|
|
|
|
std::optional<utils::IdType> constructor_id_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ExtendedScopedAnyType {
|
2023-04-21 14:27:55 +03:00
|
|
|
std::vector<utils::ReferenceType> references;
|
2023-04-09 13:43:01 +03:00
|
|
|
AnyType type;
|
2023-04-09 14:13:47 +03:00
|
|
|
};
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// Typeclass -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-25 13:22:23 +03:00
|
|
|
struct ParametrizedTypeclass {
|
2023-05-02 17:30:57 +03:00
|
|
|
TypeclassIdentifier typeclass;
|
2023-04-25 14:52:38 +03:00
|
|
|
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
2023-05-02 16:16:55 +03:00
|
|
|
|
2023-05-02 17:30:57 +03:00
|
|
|
utils::IdType typeclass_id_;
|
2023-04-25 13:22:23 +03:00
|
|
|
};
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
// ----------------- Comments [IGNORE] -----------------
|
|
|
|
|
// ----------------- Identifiers, constants, etc. -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FloatNumberLiteral {
|
2023-03-26 15:20:53 +03:00
|
|
|
double value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct NumberLiteral {
|
2023-03-26 15:20:53 +03:00
|
|
|
int64_t value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct StringLiteral {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::string value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct CharLiteral {
|
2023-03-26 15:20:53 +03:00
|
|
|
char value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-26 01:02:53 +03:00
|
|
|
struct UnitLiteral {};
|
|
|
|
|
|
2023-04-02 15:10:32 +03:00
|
|
|
} // namespace interpereter::tokens
|