#pragma once #include #include #include #include #include // for clangd #include "utils.hpp" 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; // can be extended name struct FunctionDefinition; struct TypeDefinition; struct AnnotatedAbstractType; // TypeIdentifier <-> AbstractTypeIdentifier <-> std::string using AnnotatedType = AnnotatedAbstractType; using AnyAnnotatedType = AnnotatedType; // 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; using Literal = std::variant< 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 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; struct TypeclassExpression; using TypeclassSubExpression = std::variant< std::unique_ptr, std::unique_ptr>; // Typeclass & Type struct ParametrizedType; 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; }; using PatternToken = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; using Pattern = std::variant< std::unique_ptr, std::unique_ptr>; //////////////////////////////////////////////////////////////////////////////////////////// // ----------------- 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; std::optional type_id_; }; 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; std::vector parameter_graph_ids_; utils::IdType type_id_; }; struct VariableDefinitionStatement { enum { Var, Const } modifier; enum { Move, Assign } assignment_modifier; AnyName name; SuperExpression value; }; struct FunctionDeclaration { ExtendedName name; std::vector> parameters; std::unique_ptr type; utils::IdType function_id_; }; struct FunctionDefinitionStatement { bool is_inline; std::unique_ptr definition; SuperExpression value; utils::IdType function_id_; std::vector argument_graph_ids_; utils::IdType return_type_graph_id_; }; struct TypeDefinitionStatement { enum { Struct, Class } modifier; std::unique_ptr definition; AnyType value; utils::IdType type_id_; }; struct AbstractTypeDefinitionStatement { enum { Basic, Abstract } modifier; std::unique_ptr type; utils::IdType type_graph_id_; utils::IdType type_id_; }; struct TypeclassDefinitionStatement { std::unique_ptr definition; std::vector> requirements; utils::IdType typeclass_id_; }; // Definition parts ----------------- struct FunctionDefinition { enum { Operator, Function } modifier; ExtendedName name; std::vector> parameters; std::vector arguments; }; struct TypeDefinition { std::unique_ptr type; std::vector> parameters; }; struct AnnotatedAbstractType { AbstractTypeIdentifier type; std::vector> typeclasses; utils::IdType type_graph_id_; }; // ----------------- Flow control ----------------- struct TypeConstructorPatternParameter { std::optional name; PatternToken value; }; struct TypeConstructorPattern { TypeIdentifier constructor; std::vector parameters; }; struct MatchCase { Pattern 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; }; struct AccessExpression { std::unique_ptr name; SubExpressionToken id; }; // Other Expressions ----------------- struct FunctionCallExpression { std::optional, std::unique_ptr>> prefix; ExtendedName name; std::vector arguments; }; struct TupleExpression { std::vector expressions; }; struct VariantExpression { std::vector expressions; }; struct ReturnExpression { Expression expression; }; struct TypeConstructorParameter { enum AssignmentModifier { Move, Assign }; std::optional name; std::optional asignment_modifier; PatternToken value; }; struct TypeConstructor { std::unique_ptr constructor; std::vector parameters; }; struct LambdaFunction { std::vector> parameters; std::vector arguments; Expression expression; std::vector argument_graph_ids_; utils::IdType return_type_graph_id_; }; struct ArrayExpression { std::vector elements; }; // Name ----------------- struct NameExpression { std::vector names; }; 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 TypeExpression { std::vector path; TypeSubExpression type; std::optional array_size; // if array; 0 - dynamic size utils::IdType type_id_; }; struct ExtendedScopedAnyType { std::vector references; AnyType type; }; // Typeclass ----------------- struct TypeclassExpression { std::vector path; TypeclassSubExpression typeclass; utils::IdType type_id_; }; struct ParametrizedTypeclass { TypeclassIdentifier typeclass; std::vector> parameters; }; // Typeclass & Type ----------------- struct ParametrizedType { AnyTypeIdentifier type; std::vector> parameters; }; // ----------------- 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