#pragma once #include #include #include #include #include // for clangd #include "utils.hpp" namespace interpreter::tokens { struct BaseNode { std::pair start_position; std::pair end_position; std::optional type_; }; // ----------------- 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; // Namespaces, partitions ----------------- struct Namespace; struct NamespaceSources; // Definitions ----------------- struct ImportStatement; struct AliasDefinitionStatement; struct VariableDefinitionStatement; struct FunctionDeclaration; struct FunctionDefinitionStatement; struct TypeDefinitionStatement; struct AbstractTypeDefinitionStatement; struct TypeclassDefinitionStatement; struct PartitionStatement; // using NamespaceStatement = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // using SourceStatement = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // // Definition parts using ImportSymbol = AnyIdentifier; // can be extended name struct FunctionDefinition; struct TypeDefinition; struct AnyAnnotatedType; // TypeIdentifier <-> AbstractTypeIdentifier <-> std::string using AnnotatedType = AnyAnnotatedType; using AnnotatedAbstractType = AnyAnnotatedType; // Flow control ----------------- struct TypeConstructorPatternParameter; struct TypeConstructorPattern; 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 FloatNumberLiteral; struct NumberLiteral; struct StringLiteral; struct CharLiteral; struct UnitLiteral; using Literal = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; // struct NameExpression; struct ScopedStatement; struct AccessExpression; using SubExpressionToken = std::variant< std::unique_ptr, std::unique_ptr, 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>; // 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, std::unique_ptr>; // struct ScopedStatement; // Operators struct BinaryOperatorExpression; struct UnaryOperatorExpression; struct ReferenceExpression; // Other expressions struct FunctionCallExpression; struct TupleExpression; struct VariantExpression; struct ReturnExpression; struct TypeConstructorParameter; struct TypeConstructor; struct LambdaFunction; struct ArrayExpression; // Name struct PartitionName { BaseNode base; std::vector path; NameIdentifier 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 TypeExpression; 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; // TypeclassSubExpression -> ParametrizedTypeclass // Typeclass & Type struct ParametrizedType; // Comments [IGNORE] ----------------- // Identifiers, constants, etc. ----------------- struct ExtendedName { BaseNode base; std::string name; }; using Pattern = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; using ScopedPattern = Pattern; //////////////////////////////////////////////////////////////////////////////////////////// // ----------------- Sources ----------------- struct SourceFile { BaseNode base; std::vector statements; }; // ----------------- Namespaces, partittions ----------------- struct NamespaceSources { BaseNode base; std::vector statements; }; struct Namespace { BaseNode base; std::optional modifier; // modifier => variable namespace TypeIdentifier type; NamespaceSources scope; std::optional link_type_id_; std::optional link_typeclass_id_; }; // ----------------- Definitions ----------------- struct ImportStatement { BaseNode base; std::optional name; std::string module_name; std::vector symbols; }; struct AliasDefinitionStatement { BaseNode base; utils::AliasModifier modifier; TypeIdentifier type; std::vector parameters; std::unique_ptr value; utils::IdType type_id_; }; struct VariableDefinitionStatement { BaseNode base; utils::IsConstModifier modifier; utils::AssignmentModifier assignment_modifier; AnyName name; SuperExpression value; }; struct FunctionDeclaration { BaseNode base; bool is_in_interface = false; ExtendedName name; std::vector> parameters; std::unique_ptr type; utils::IdType function_id_; }; struct FunctionDefinitionStatement { BaseNode base; std::unique_ptr definition; SuperExpression value; utils::IdType function_id_; }; struct TypeDefinitionStatement { BaseNode base; bool is_in_interface = false; utils::ClassModifier modifier; std::unique_ptr definition; AnyType value; utils::IdType type_id_; }; struct AbstractTypeDefinitionStatement { BaseNode base; utils::AbstractTypeModifier modifier; std::unique_ptr type; utils::IdType type_graph_id_; utils::IdType type_id_; }; struct TypeclassDefinitionStatement { BaseNode base; std::unique_ptr definition; std::vector> requirements; utils::IdType typeclass_id_; }; struct PartitionStatement { BaseNode base; utils::PartitionModifier modifier; PartitionName name; SuperExpression value; utils::IdType executable_id_; }; // Definition parts ----------------- struct FunctionDefinition { BaseNode base; utils::FunctionTypeModifier modifier; ExtendedName name; std::vector arguments; }; struct TypeDefinition { BaseNode base; std::unique_ptr type; std::vector> parameters; }; struct AnyAnnotatedType { BaseNode base; AnyTypeIdentifier type; std::vector> typeclasses; }; // ----------------- Flow control ----------------- struct TypeConstructorPatternParameter { BaseNode base; std::optional name; ScopedPattern value; }; struct TypeConstructorPattern { BaseNode base; std::unique_ptr constructor; std::vector parameters; }; struct MatchCase { BaseNode base; Pattern value; std::optional condition; std::optional statement; }; struct Match { BaseNode base; Expression value; std::vector matches; }; struct Condition { BaseNode base; std::vector conditions; // if, elif std::vector statements; // if, elif, else }; struct DoWhileLoop { BaseNode base; Expression condition; Expression statement; }; struct WhileLoop { BaseNode base; Expression condition; Expression statement; }; struct ForLoop { BaseNode base; utils::IsConstModifier variable_modifier; AnyName variable; Expression interval; Expression statement; }; struct LoopLoop { BaseNode base; Expression statement; }; // ----------------- Statements, expressions, blocks, etc. ----------------- using BlockStatement = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr, std::unique_ptr>; struct Block { BaseNode base; std::vector statements; }; struct ScopedStatement { BaseNode base; SuperExpression statement; }; // Operators ----------------- struct BinaryOperatorExpression { BaseNode base; OperatorIdentifier operator_name; SubExpression left_expression; SubExpression right_expression; }; struct UnaryOperatorExpression { BaseNode base; OperatorIdentifier operator_name; Expression expression; }; struct ReferenceExpression { BaseNode base; std::vector references; std::unique_ptr expression; }; struct AccessExpression { BaseNode base; std::unique_ptr name; SubExpressionToken id; }; // Other Expressions ----------------- struct FunctionCallExpression { BaseNode base; std::optional, std::unique_ptr>> prefix; ExtendedName name; std::vector> parameters; std::vector arguments; }; struct TupleExpression { BaseNode base; std::vector expressions; }; struct VariantExpression { BaseNode base; std::vector expressions; }; struct ReturnExpression { BaseNode base; Expression expression; }; struct TypeConstructorParameter { BaseNode base; std::optional name; std::optional asignment_modifier; SubExpression value; }; struct TypeConstructor { BaseNode base; std::unique_ptr constructor; std::vector parameters; }; struct LambdaFunction { BaseNode base; std::vector> parameters; std::vector arguments; Expression expression; std::vector argument_graph_ids_; utils::IdType return_type_graph_id_; }; struct ArrayExpression { BaseNode base; std::vector elements; }; // Name ----------------- struct NameExpression { BaseNode base; std::vector names; }; struct TupleName { BaseNode base; std::vector names; }; struct VariantName { BaseNode base; std::vector names; }; struct AnnotatedName { BaseNode base; NameIdentifier name; std::optional type; }; // ----------------- Type, typeclass, etc. ----------------- // Type ----------------- struct FunctionType { BaseNode base; std::vector types; }; struct TupleType { BaseNode base; std::optional type; std::vector, std::unique_ptr>> entities; }; struct VariantType { BaseNode base; std::optional type; std::vector>> constructors; }; struct ParametrizedType { BaseNode base; AnyTypeIdentifier type; std::vector> parameters; std::optional type_id_; // std::nullopt, if it is namespace without type }; struct TypeExpression { BaseNode base; std::vector path; ParametrizedType type; std::optional array_size; // if array; 0 - dynamic size std::optional type_id_; std::optional constructor_id_; }; struct ExtendedScopedAnyType { BaseNode base; std::vector references; AnyType type; }; // Typeclass ----------------- struct ParametrizedTypeclass { BaseNode base; TypeclassIdentifier typeclass; std::vector> parameters; utils::IdType typeclass_id_; }; // ----------------- Comments [IGNORE] ----------------- // ----------------- Identifiers, constants, etc. ----------------- struct FloatNumberLiteral { BaseNode base; double value; }; struct NumberLiteral { BaseNode base; int64_t value; }; struct StringLiteral { BaseNode base; std::string value; }; struct CharLiteral { BaseNode base; char value; }; struct UnitLiteral { BaseNode base; }; } // namespace interpereter::tokens