#pragma once #include #include #include #include // for clangd #include "node.hpp" namespace interpreter { namespace 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; // TODO partitions struct Sources; // Namespaces, partittions ----------------- struct Partition; struct Namespace; // Definitions ----------------- struct ImportStatement; struct UsageDefinition; struct AliasDefinition; struct VariableDefinition; struct FunctionDeclaration; struct FunctionDefinition; struct AliasTypeDefinition; // | Parts of type definition struct TypeDefinition; // | struct TypeclassDefinition; using SourceStatement = std::variant< ImportStatement, UsageDefinition, AliasDefinition, VariableDefinition, // ?? FunctionDeclaration, FunctionDefinition, AliasTypeDefinition, TypeDefinition, TypeclassDefinition, Namespace>; // Definition parts struct ParametrizedType; struct TupleType; struct VariantType; struct ParametrizedTypeclass; using FunctionDeclarationType = std::variant< ParametrizedType, TupleType, VariantType, ParametrizedTypeclass>; struct DefinedName; struct DefinedAnnotatedName; struct DefinedType; struct DefinedTypeclass; struct DefinitionParameter; struct DefinitionArgument; // Flow control ----------------- struct Match; struct Condition; struct WhileLoop; // WhileLoop <-> DoWhileLoop struct ForLoop; struct LoopLoop; using FlowControl = std::variant< Match, Condition, WhileLoop, ForLoop, LoopLoop>; // Statements, expressions, blocks, etc. ----------------- struct Block; // struct NameExpression; struct ScopedStatement; using SubExpressionToken = std::variant< NameExpression, ScopedStatement>; // struct FunctionCallExpression; struct BinaryOperatorExpression; using SubExpression = std::variant< FunctionCallExpression, BinaryOperatorExpression, SubExpressionToken>; // struct ReturnExpression; enum class LoopControlExpression { Break, Continue, }; using PrefixedExpression = std::variant< ReturnExpression, LoopControlExpression, Block>; // struct LambdaFunction; struct TypeConstructor; struct UnaryOperatorExpression; using Expression = std::variant< LambdaFunction, TypeConstructor, PrefixedExpression, UnaryOperatorExpression, SubExpression>; // struct TupleExpression; struct VariantExpression; using SuperExpression = std::variant< FlowControl, TupleExpression, VariantExpression, Expression>; // struct ScopedStatement; // ?? scoped statement is _superexpression ?? // Operators struct BinaryOperatorExpression; struct UnaryOperatorExpression; // Simple Expressions struct FunctionCallExpression; struct TupleExpression; struct VariantExpression; struct ReturnExpression; // Lambda struct LambdaFunction; // Name struct NameSuperExpression; struct NameExpression; struct TupleName; struct VariantName; struct AnnotatedName; using AnyName = std::variant< AnnotatedName, TupleName, VariantName>; // Type struct TypeConstructor; // // TypeOrAnyType <-> AnyType struct TupleType; struct VariantType; struct VariantType; using AnyType = std::variant< ParametrizedType, TupleType, VariantType>; // // TypeIdentifierDefinition <-> some '.' + TypeIdentifier using TypeIdentifierDefinition = std::string; struct AnnotatedType; // // TypeAnnotations - inplace ?? struct ParametrizedType; struct TypeExpression; using TypeSubExpression = std::variant< AnyTypeIdentifier, ParametrizedType>; // Typeclass struct AnnotatedTypeclass; struct ParametrizedTypeclass; struct TypeclassExpression; // Comments [IGNORE] ----------------- // Identifiers, constants, etc. ----------------- struct FloatNumberLiteral; struct NumberLiteral; struct StringLiteral; struct CharLiteral; using Literal = std::variant< FloatNumberLiteral, NumberLiteral, StringLiteral, CharLiteral>; // using NameSubSuperExpression = std::variant< NameIdentifier, Literal, SuperExpression>; // ----------------- Sources ----------------- struct SourceFile : public Node { std::vector> statements; }; struct Sources : public Node { std::vector statemets; }; // ----------------- Namespaces, partittions ----------------- struct Partition : public Node { enum class PartitionType { Test, Interface, Core, Lib, Module, // rename ?? Exe, }; PartitionType type; std::unique_ptr scope; }; struct Namespace : public Node { std::unique_ptr> name; // TODO add const / var specification std::unique_ptr scope; }; // ----------------- Definitions ----------------- struct ImportStatement : public Node { std::string module_name; std::vector symbols; // TODO parametric import support }; struct UsageDefinition : public Node { TypeIdentifier module_identifier; std::unique_ptr import_statement; }; struct AliasDefinition : public Node { std::unique_ptr name; std::unique_ptr value; }; struct VariableDefinition : public Node { NameIdentifier name; std::unique_ptr value; }; struct FunctionDeclaration : public Node { NameIdentifier name; std::vector> argument_types; }; struct FunctionDefintion : public Node { std::unique_ptr name; std::unique_ptr value; }; struct AliasTypeDefinition : public Node { std::unique_ptr name; std::unique_ptr value; }; struct TypeDefinition : public Node { std::unique_ptr name; std::unique_ptr value; }; struct TypeclassDefinition : public Node { std::unique_ptr name; std::vector> requirements; }; // Definition parts ----------------- struct DefinedName : public Node { bool is_operator = false; // other format ?? NameOrOperatorIdentifier name; // function name or operator std::vector> parameters; std::vector> arguments; }; struct DefinedAnnotatedName : public Node { NameIdentifier name; std::unique_ptr> type; }; struct DefinedType : public Node { std::unique_ptr type; std::vector> parameters; std::vector> arguments; }; struct DefinedTypeclass : public Node { std::unique_ptr typeclass; std::vector> parameters; std::vector> arguments; }; struct DefinitionParameter : public Node { AbstractTypeIdentifier abstract_type; std::vector> typeclasses; }; struct DefinitionArgument : public Node { NameIdentifier name; std::vector> types; }; // ----------------- Flow control ----------------- struct MatchCase { std::unique_ptr value; std::unique_ptr condition; std::unique_ptr statement; }; struct Match : public Node { std::unique_ptr value; std::vector matches; }; struct Condition : public Node { std::vector> conditions; // if, elif std::vector> stetemets; // if, elif, else }; struct WhileLoop : public Node { // WhileLoop <-> DoWhileLoop std::unique_ptr condition; std::unique_ptr statement; }; struct ForLoop : public Node { std::unique_ptr variable; std::unique_ptr interval; std::unique_ptr statement; }; struct LoopLoop : public Node { std::unique_ptr statement; }; // ----------------- Statements, expressions, blocks, etc. ----------------- using BlockStatement = std::variant< Expression, AliasDefinition, VariableDefinition, FlowControl, PrefixedExpression>; struct Block : public Node { std::vector> statements; }; struct ScopedStatement : public Node { std::unique_ptr statement; }; // Operators ----------------- struct BinaryOperatorExpression : public Node { OperatorIdentifier operator_name; std::unique_ptr left_expression; std::unique_ptr right_expression; }; struct UnaryOperatorExpression : public Node { // TODO fix prescendence OperatorIdentifier operator_name; std::unique_ptr expression; }; // Simple Expressions ----------------- using FunctionArgument = std::variant; struct FunctionCallExpression : public Node { std::unique_ptr name; std::vector> arguments; }; struct TupleExpression : public Node { std::vector> expressions; }; struct VariantExpression : public Node { std::vector> expressions; }; struct ReturnExpression : public Node { std::unique_ptr expression; }; // Lambda ----------------- struct LambdaFunction : public Node { std::vector> parameters; std::vector> arguments; std::unique_ptr expression; }; // Name ----------------- struct NameSuperExpression : public Node { std::vector> namespaces; std::vector> expressions; // last is not SuperExpression }; struct NameExpression : public Node { std::vector namespaces; std::vector names; }; struct TupleName : public Node { std::vector> names; }; struct VariantName : public Node { std::vector> names; }; struct AnnotatedName : public Node { NameIdentifier name; std::unique_ptr type; // optional }; // TODO ?? mark all optional fields ?? // Type ----------------- struct TypeConstructor : public Node { std::unique_ptr type; std::vector>> parameters; }; struct TupleType : public Node { TypeIdentifierDefinition type; // optional std::vector>> entities; // NameIdentifier is optional }; struct VariantType : public Node { TypeIdentifierDefinition type; // optional std::vector>> constructors; }; struct AnnotatedType : public Node { std::unique_ptr type_expression; std::vector> annotations; }; using TypeParameter = std::variant; struct ParametrizedType : public Node { std::unique_ptr type_expression; std::vector> parameters; }; struct TypeExpression : public Node { std::vector> namespaces; AnyTypeIdentifier type; }; // Typeclass ----------------- struct AnnotatedTypeclass : public Node { std::unique_ptr typeclass_expression; std::vector> annotations; }; struct ParametrizedTypeclass : public Node { std::unique_ptr typeclass_expression; std::vector> parameters; }; struct TypeclassExpression : public Node { std::vector> namespaces; TypeclassIdentifier typeclass; }; // ----------------- Comments [IGNORE] ----------------- // ----------------- Identifiers, constants, etc. ----------------- struct FloatNumberLiteral : public Node { double value; }; struct NumberLiteral : public Node { int64_t value; }; struct StringLiteral : public Node { std::string value; }; struct CharLiteral : public Node { char value; }; } // namespace tokens } // namespace interpereter