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-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
|
|
|
struct Sources;
|
|
|
|
|
|
2023-04-02 15:10:32 +03:00
|
|
|
// Namespaces, partitions -----------------
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
struct Partition;
|
|
|
|
|
struct Namespace;
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
using SourceStatement = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<ImportStatement>,
|
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>,
|
|
|
|
|
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
|
|
|
|
std::unique_ptr<TypeclassDefinitionStatement>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<Namespace>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
// Definition parts
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
using ImportSymbol = AnyIdentifier;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinition;
|
|
|
|
|
struct TypeDefinition;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct DefinitionParameter;
|
|
|
|
|
|
|
|
|
|
// Flow control -----------------
|
|
|
|
|
|
|
|
|
|
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-09 13:43:01 +03:00
|
|
|
struct NameExpression;
|
2023-03-26 15:20:53 +03:00
|
|
|
struct ScopedStatement;
|
|
|
|
|
using SubExpressionToken = std::variant<
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<NameExpression>,
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<ScopedStatement>>;
|
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<ArrayExpression>,
|
|
|
|
|
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>,
|
|
|
|
|
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-04-09 14:13:47 +03:00
|
|
|
//
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeExpression;
|
|
|
|
|
using FunctionArgument = std::variant<
|
|
|
|
|
SubExpressionToken,
|
|
|
|
|
std::unique_ptr<TypeExpression>>;
|
2023-04-09 14:13:47 +03:00
|
|
|
//
|
2023-04-09 13:43:01 +03:00
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
struct TupleExpression;
|
|
|
|
|
struct VariantExpression;
|
|
|
|
|
struct ReturnExpression;
|
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-09 13:43:01 +03:00
|
|
|
struct AnnotatedType;
|
|
|
|
|
struct ParametrizedType;
|
|
|
|
|
struct TypeExpression;
|
|
|
|
|
|
|
|
|
|
using Constructor = std::string;
|
|
|
|
|
|
|
|
|
|
// // ScopedAnyType <-> AnyType
|
2023-03-26 15:20:53 +03:00
|
|
|
using AnyType = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<ParametrizedType>,
|
|
|
|
|
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;
|
|
|
|
|
struct TypeclassExpression;
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
using TypeclassUsage = std::variant<
|
|
|
|
|
std::unique_ptr<TypeclassExpression>,
|
|
|
|
|
std::unique_ptr<ParametrizedTypeclass>>;
|
|
|
|
|
|
|
|
|
|
// Typeclass & Type
|
|
|
|
|
|
|
|
|
|
using TypeParameter = std::variant<
|
|
|
|
|
std::unique_ptr<TypeExpression>,
|
|
|
|
|
std::unique_ptr<ParametrizedType>>;
|
|
|
|
|
|
|
|
|
|
using TypeSubExpression = std::variant<
|
|
|
|
|
std::unique_ptr<AnyTypeIdentifier>,
|
|
|
|
|
std::unique_ptr<ParametrizedType>>;
|
|
|
|
|
|
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-03-26 15:20:53 +03:00
|
|
|
struct FloatNumberLiteral;
|
|
|
|
|
struct NumberLiteral;
|
|
|
|
|
struct StringLiteral;
|
|
|
|
|
struct CharLiteral;
|
|
|
|
|
|
|
|
|
|
using Literal = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<FloatNumberLiteral>,
|
|
|
|
|
std::unique_ptr<NumberLiteral>,
|
|
|
|
|
std::unique_ptr<StringLiteral>,
|
|
|
|
|
std::unique_ptr<CharLiteral>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
using NameSubExpression = std::variant<
|
2023-03-26 23:15:42 +03:00
|
|
|
std::unique_ptr<NameIdentifier>,
|
|
|
|
|
std::unique_ptr<Literal>,
|
|
|
|
|
std::unique_ptr<SuperExpression>>;
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
enum class ReferenceType {
|
|
|
|
|
Reference,
|
|
|
|
|
UniqueReference,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
// ----------------- Sources -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct SourceFile {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<std::variant<SourceStatement, Partition>> statements;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct Sources {
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<SourceStatement> statements;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Namespaces, partittions -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct Namespace {
|
2023-04-09 18:49:52 +03:00
|
|
|
enum Modifier { Const, Var };
|
|
|
|
|
std::optional<Modifier> modifier;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::optional<ExtendedName> name;
|
|
|
|
|
TypeIdentifier type;
|
|
|
|
|
std::unique_ptr<Sources> scope;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Partition {
|
|
|
|
|
enum PartitionName {
|
2023-03-26 15:20:53 +03:00
|
|
|
Test,
|
|
|
|
|
Interface,
|
|
|
|
|
Core,
|
|
|
|
|
Lib,
|
2023-04-09 13:43:01 +03:00
|
|
|
Module,
|
2023-03-26 15:20:53 +03:00
|
|
|
Exe,
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
PartitionName name;
|
2023-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<Sources> scope;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- 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-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<ParametrizedType> value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct VariableDefinitionStatement {
|
|
|
|
|
enum { Var, Const } modifier;
|
|
|
|
|
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-03-29 11:42:00 +03:00
|
|
|
NameOrOperatorIdentifier name;
|
2023-03-26 23:15:42 +03:00
|
|
|
std::vector<std::unique_ptr<DefinitionParameter>> parameters;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::unique_ptr<FunctionType> type;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinitionStatement {
|
|
|
|
|
std::unique_ptr<FunctionDefinition> definition;
|
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 TypeDefinitionStatement {
|
|
|
|
|
enum { Struct, Class } modifier;
|
|
|
|
|
std::unique_ptr<TypeDefinition> definition;
|
|
|
|
|
AnyType value;
|
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-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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Definition parts -----------------
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct FunctionDefinition {
|
|
|
|
|
enum { Operator, Function } modifier;
|
|
|
|
|
NameOrOperatorIdentifier name;
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<std::unique_ptr<DefinitionParameter>> parameters;
|
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;
|
|
|
|
|
std::vector<std::unique_ptr<DefinitionParameter>> parameters;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct DefinitionParameter {
|
2023-03-26 23:15:42 +03:00
|
|
|
AbstractTypeIdentifier type;
|
2023-04-09 16:01:07 +03:00
|
|
|
std::vector<TypeclassUsage> typeclasses;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- Flow control -----------------
|
|
|
|
|
|
|
|
|
|
struct MatchCase {
|
2023-03-26 23:15:42 +03:00
|
|
|
Expression value;
|
|
|
|
|
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 {
|
|
|
|
|
std::vector<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-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 {
|
|
|
|
|
std::unique_ptr<NameExpression> 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-09 13:43:01 +03:00
|
|
|
struct TypeConstructor {
|
|
|
|
|
std::unique_ptr<ParametrizedType> type;
|
|
|
|
|
std::vector<std::pair<ExtendedName, SubExpression>> parameters;
|
|
|
|
|
};
|
2023-03-26 15:20:53 +03:00
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct LambdaFunction {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<std::unique_ptr<DefinitionParameter>> parameters;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::vector<ExtendedName> arguments;
|
2023-03-27 03:10:04 +03:00
|
|
|
Expression expression;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ArrayExpression {
|
|
|
|
|
std::vector<Expression> elements;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
// Name -----------------
|
|
|
|
|
|
|
|
|
|
struct NameExpression {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::vector<TypeSubExpression> namespaces;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::vector<NameSubExpression> expressions;
|
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-04-09 13:43:01 +03:00
|
|
|
struct AnnotatedType {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<TypeExpression> type_expression;
|
2023-04-09 16:01:07 +03:00
|
|
|
std::vector<TypeclassUsage> annotations;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ParametrizedType {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<TypeExpression> type_expression;
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<TypeParameter> parameters;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeExpression {
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<TypeSubExpression> namespaces;
|
2023-03-26 15:20:53 +03:00
|
|
|
AnyTypeIdentifier type;
|
2023-04-09 13:43:01 +03:00
|
|
|
std::optional<size_t> ArraySize; // if array; 0 - dynamic size
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct ExtendedScopedAnyType {
|
|
|
|
|
std::vector<ReferenceType> references;
|
|
|
|
|
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-09 13:43:01 +03:00
|
|
|
struct ParametrizedTypeclass {
|
2023-03-26 15:20:53 +03:00
|
|
|
std::unique_ptr<TypeclassExpression> typeclass_expression;
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<TypeParameter> parameters;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
2023-04-09 13:43:01 +03:00
|
|
|
struct TypeclassExpression {
|
2023-03-27 03:10:04 +03:00
|
|
|
std::vector<TypeSubExpression> namespaces;
|
2023-03-26 15:20:53 +03:00
|
|
|
TypeclassIdentifier typeclass;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------- 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-02 15:10:32 +03:00
|
|
|
} // namespace interpereter::tokens
|