#pragma once #include #include #include #include #include namespace interpreter::tokens { // ----------------- 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 ----------------- struct SourceFile; struct Sources; // Namespaces, partitions ----------------- struct Partition; struct Namespace; // Definitions ----------------- struct ImportStatement; struct AliasDefinitionStatement; struct VariableDefinitionStatement; struct FunctionDeclaration; struct FunctionDefinitionStatement; struct TypeDefinitionStatement; struct AbstractTypeDefinitionStatement; struct TypeclassDefinitionStatement; using SourceStatement = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // Definition parts using ImportSymbol = AnyIdentifier; struct FunctionDefinition; struct TypeDefinition; struct DefinitionParameter; // Flow control ----------------- struct Match; struct Condition; struct DoWhileLoop; struct WhileLoop; struct ForLoop; struct LoopLoop; using FlowControl = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // Statements, expressions, blocks, etc. ----------------- struct Block; // struct NameExpression; struct ScopedStatement; using SubExpressionToken = std::variant< std::unique_ptr, std::unique_ptr>; // struct FunctionCallExpression; struct BinaryOperatorExpression; struct ArrayExpression; struct ReferenceExpression; using SubExpression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // enum class LoopControlExpression { Break, Continue, }; // struct ReturnExpression; using PrefixedExpression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; // struct LambdaFunction; struct TypeConstructor; struct UnaryOperatorExpression; using Expression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // struct TupleExpression; struct VariantExpression; using SuperExpression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // struct ScopedStatement; // Operators struct BinaryOperatorExpression; struct UnaryOperatorExpression; struct ReferenceExpression; // Other expressions struct FunctionCallExpression; struct TupleExpression; struct VariantExpression; struct ReturnExpression; struct TypeConstructor; struct LambdaFunction; struct ArrayExpression; // Name struct NameExpression; struct TupleName; struct VariantName; struct AnnotatedName; // // ScopedAnyName <-> AnyName using AnyName = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; using ScopedAnyName = AnyName; // Type, typeclass, etc. ----------------- // Type struct FunctionType; struct TupleType; struct VariantType; struct AnnotatedType; struct ParametrizedType; struct TypeExpression; using Constructor = std::string; // // ScopedAnyType <-> AnyType using AnyType = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; using ScopedAnyType = AnyType; struct ExtendedScopedAnyType; // Typeclass struct ParametrizedTypeclass; struct TypeclassExpression; using TypeclassUsage = std::variant< std::unique_ptr, std::unique_ptr>; // Typeclass & Type using TypeParameter = std::variant< std::unique_ptr, std::unique_ptr>; using TypeSubExpression = std::variant< std::unique_ptr, std::unique_ptr>; // using FunctionArgument = std::variant< SubExpressionToken, TypeSubExpression>; // Comments [IGNORE] ----------------- // Identifiers, constants, etc. ----------------- struct ExtendedName { std::string name; }; struct FloatNumberLiteral; struct NumberLiteral; struct StringLiteral; struct CharLiteral; using Literal = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // using NameSubExpression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; enum class ReferenceType { Reference, UniqueReference, }; //////////////////////////////////////////////////////////////////////////////////////////// // ----------------- Sources ----------------- struct SourceFile { std::vector> statements; }; struct Sources { std::vector statements; }; // ----------------- Namespaces, partittions ----------------- struct Namespace { enum Modifier { Const, Var }; std::optional modifier; std::optional name; TypeIdentifier type; std::unique_ptr scope; }; struct Partition { enum PartitionName { Test, Interface, Core, Lib, Module, Exe, }; PartitionName name; std::unique_ptr scope; }; // ----------------- Definitions ----------------- struct ImportStatement { std::optional name; std::string module_name; std::vector symbols; }; struct AliasDefinitionStatement { enum {Alias, Type, Let} modifier; TypeIdentifier type; std::vector parameters; std::unique_ptr value; }; struct VariableDefinitionStatement { enum { Var, Const } modifier; enum { Move, Assign } assignment_modifier; AnyName name; SuperExpression value; }; struct FunctionDeclaration { NameOrOperatorIdentifier name; std::vector> parameters; std::unique_ptr type; }; struct FunctionDefinitionStatement { bool is_inline; std::unique_ptr definition; SuperExpression value; }; struct TypeDefinitionStatement { enum { Struct, Class } modifier; std::unique_ptr definition; AnyType value; }; struct AbstractTypeDefinitionStatement { enum { Basic, Abstract } modifier; std::unique_ptr type; }; struct TypeclassDefinitionStatement { std::unique_ptr definition; std::vector> requirements; }; // Definition parts ----------------- struct FunctionDefinition { enum { Operator, Function } modifier; NameOrOperatorIdentifier name; std::vector> parameters; std::vector arguments; }; struct TypeDefinition { std::unique_ptr type; std::vector> parameters; }; struct DefinitionParameter { AbstractTypeIdentifier type; std::vector typeclasses; }; // ----------------- Flow control ----------------- struct MatchCase { Expression value; std::optional condition; std::optional statement; }; struct Match { Expression value; std::vector matches; }; struct Condition { std::vector conditions; // if, elif std::vector statements; // if, elif, else }; struct DoWhileLoop { Expression condition; Expression statement; }; struct WhileLoop { Expression condition; Expression statement; }; struct ForLoop { AnyName variable; Expression interval; Expression statement; }; struct LoopLoop { Expression statement; }; // ----------------- Statements, expressions, blocks, etc. ----------------- using BlockStatement = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; struct Block { std::vector statements; }; struct ScopedStatement { SuperExpression statement; }; // Operators ----------------- struct BinaryOperatorExpression { OperatorIdentifier operator_name; SubExpression left_expression; SubExpression right_expression; }; struct UnaryOperatorExpression { OperatorIdentifier operator_name; Expression expression; }; struct ReferenceExpression { std::vector references; std::unique_ptr expression; }; // Other Expressions ----------------- struct FunctionCallExpression { std::unique_ptr name; std::vector arguments; }; struct TupleExpression { std::vector expressions; }; struct VariantExpression { std::vector expressions; }; struct ReturnExpression { Expression expression; }; struct TypeConstructor { enum AssignmentModifier { Move, Assign }; std::unique_ptr type; std::vector> parameters; }; struct LambdaFunction { std::vector> parameters; std::vector arguments; Expression expression; }; struct ArrayExpression { std::vector elements; }; // Name ----------------- struct NameExpression { std::vector namespaces; std::vector expressions; }; struct TupleName { std::vector names; }; struct VariantName { std::vector names; }; struct AnnotatedName { NameIdentifier name; std::optional type; }; // ----------------- Type, typeclass, etc. ----------------- // Type ----------------- struct FunctionType { std::vector types; }; struct TupleType { std::optional type; std::vector, std::unique_ptr>> entities; }; struct VariantType { std::optional type; std::vector>> constructors; }; struct AnnotatedType { std::unique_ptr type_expression; std::vector annotations; }; struct ParametrizedType { std::unique_ptr type_expression; std::vector parameters; }; struct TypeExpression { std::vector namespaces; AnyTypeIdentifier type; std::optional array_size; // if array; 0 - dynamic size }; struct ExtendedScopedAnyType { std::vector references; AnyType type; }; // Typeclass ----------------- struct ParametrizedTypeclass { std::unique_ptr typeclass_expression; std::vector parameters; }; struct TypeclassExpression { std::vector namespaces; TypeclassIdentifier typeclass; }; // ----------------- Comments [IGNORE] ----------------- // ----------------- Identifiers, constants, etc. ----------------- struct FloatNumberLiteral { double value; }; struct NumberLiteral { int64_t value; }; struct StringLiteral { std::string value; }; struct CharLiteral { char value; }; } // namespace interpereter::tokens