diff --git a/include/interpreter_tree.hpp b/include/interpreter_tree.hpp index 08d3ad2..5046e10 100644 --- a/include/interpreter_tree.hpp +++ b/include/interpreter_tree.hpp @@ -36,45 +36,31 @@ struct Namespace; // Definitions ----------------- struct ImportStatement; -struct UsageDefinition; -struct AliasDefinition; -struct VariableDefinition; +struct AliasDefinitionStatement; +struct VariableDefinitionStatement; struct FunctionDeclaration; -struct FunctionDefinition; -struct AliasTypeDefinition; -struct TypeDefinition; -struct TypeclassDefinition; +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, - std::unique_ptr, - std::unique_ptr, + std::unique_ptr, + std::unique_ptr, + std::unique_ptr, + std::unique_ptr, std::unique_ptr>; // Definition parts -struct ParametrizedType; -struct TupleType; -struct VariantType; -struct ParametrizedTypeclass; -using FunctionDeclarationType = std::variant< - std::unique_ptr, - std::unique_ptr, - std::unique_ptr, - std::unique_ptr>; +using ImportSymbol = AnyIdentifier; -struct DefinedName; -struct DefinedAnnotatedName; -struct DefinedType; -struct DefinedTypeclass; +struct FunctionDefinition; +struct TypeDefinition; struct DefinitionParameter; -struct DefinitionArgument; // Flow control ----------------- @@ -99,30 +85,34 @@ struct Block; // -struct NameSuperExpression; +struct NameExpression; struct ScopedStatement; -enum class LoopControlExpression { - Break, - Continue, -}; - using SubExpressionToken = std::variant< - 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, + std::unique_ptr, + std::unique_ptr>; // +enum class LoopControlExpression { + Break, + Continue, +}; + struct ReturnExpression; using PrefixedExpression = std::variant< @@ -156,73 +146,95 @@ using SuperExpression = std::variant< // -struct ScopedStatement; // ?? scoped statement is _superexpression ?? +struct ScopedStatement; // Operators struct BinaryOperatorExpression; struct UnaryOperatorExpression; +struct ReferenceExpression; -// Simple Expressions +// Other Expressions struct FunctionCallExpression; + +struct TypeExpression; +using FunctionArgument = std::variant< + SubExpressionToken, + std::unique_ptr>; + struct TupleExpression; struct VariantExpression; struct ReturnExpression; -// Lambda - +struct TypeConstructor; struct LambdaFunction; +struct ArrayExpression; // Name -struct NameSuperExpression; 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 TypeConstructor; - -// // TypeOrAnyType <-> AnyType - +struct FunctionType; struct TupleType; struct VariantType; -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, + std::unique_ptr>; -// // TypeIdentifierDefinition <-> some '.' + TypeIdentifier -using TypeIdentifierDefinition = std::string; +using ScopedAnyType = AnyType; -struct AnnotatedType; -// // TypeAnnotations - inplace ?? -struct ParametrizedType; -struct TypeExpression; +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>; -// Typeclass - -struct AnnotatedTypeclass; -struct ParametrizedTypeclass; -struct TypeclassExpression; - // Comments [IGNORE] ----------------- // Identifiers, constants, etc. ----------------- +using ExtendedName = std::string; + struct FloatNumberLiteral; struct NumberLiteral; struct StringLiteral; @@ -236,143 +248,115 @@ using Literal = std::variant< // -using NameSubSuperExpression = std::variant< +using NameSubExpression = std::variant< std::unique_ptr, std::unique_ptr, std::unique_ptr>; +enum class ReferenceType { + Reference, + UniqueReference, +}; + +//////////////////////////////////////////////////////////////////////////////////////////// + // ----------------- Sources ----------------- -struct SourceFile : public Node { +struct SourceFile { std::vector> statements; }; -struct Sources : public Node { +struct Sources { std::vector statements; }; // ----------------- Namespaces, partittions ----------------- -struct Partition : public Node { - enum PartitionType { +struct Namespace { + bool is_const; + std::optional name; + TypeIdentifier type; + std::unique_ptr scope; +}; + +struct Partition { + enum PartitionName { Test, Interface, Core, Lib, - Module, // rename ?? + Module, Exe, }; - PartitionType type; - std::unique_ptr scope; -}; - -struct Namespace : public Node { - bool is_const; - std::variant< - std::unique_ptr, - std::unique_ptr> name; - // TODO add const / var specification + PartitionName name; std::unique_ptr scope; }; // ----------------- Definitions ----------------- -struct TypeclassExpression; -struct TypeExpression; -struct NameExpression; - -using ImportSymbol = std::variant< - std::unique_ptr, - std::unique_ptr, - std::unique_ptr>; - -// - -struct ImportStatement : public Node { +struct ImportStatement { + std::optional name; std::string module_name; std::vector symbols; }; -struct UsageDefinition : public Node { - TypeIdentifier name; // rename ?? - std::unique_ptr import_statement; -}; - -struct AliasDefinition : public Node { - std::unique_ptr type; +struct AliasDefinitionStatement { + TypeIdentifier type; + std::vector parameters; std::unique_ptr value; }; -struct VariableDefinition : public Node { - bool is_const; // default value ?? - NameIdentifier name; +struct VariableDefinitionStatement { + enum { Var, Const } modifier; + AnyName name; SuperExpression value; }; -struct FunctionDeclaration : public Node { +struct FunctionDeclaration { NameOrOperatorIdentifier name; std::vector> parameters; - std::vector argument_types; + std::unique_ptr type; }; -struct FunctionDefinition : public Node { - std::unique_ptr name; +struct FunctionDefinitionStatement { + std::unique_ptr definition; SuperExpression value; }; -struct AliasTypeDefinition : public Node { - std::unique_ptr type; - std::unique_ptr value; -}; - -struct TypeDefinition : public Node { - bool is_class; // class vs struct - std::unique_ptr type; +struct TypeDefinitionStatement { + enum { Struct, Class } modifier; + std::unique_ptr definition; AnyType value; }; -struct TypeclassDefinition : public Node { - std::unique_ptr typeclass; +struct AbstractTypeDefinitionStatement { + enum { Basic, Abstract } modifier; + std::unique_ptr definition; +}; + +struct TypeclassDefinitionStatement { + std::unique_ptr definition; std::vector> requirements; }; // Definition parts ----------------- -struct DefinedName : public Node { - bool is_operator = false; // other format ?? - NameOrOperatorIdentifier name; // function name or operator +struct FunctionDefinition { + enum { Operator, Function } modifier; + NameOrOperatorIdentifier name; std::vector> parameters; - std::vector> arguments; + std::vector arguments; }; -struct DefinedAnnotatedName : public Node { - NameIdentifier name; - std::variant< - std::unique_ptr, - std::unique_ptr> type; -}; - -struct DefinedType : public Node { +struct TypeDefinition { 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 { +struct DefinitionParameter { AbstractTypeIdentifier type; - std::vector> typeclasses; -}; - -struct DefinitionArgument : public Node { - NameIdentifier name; - std::vector> types; // TODO: one type + std::vector> typeclasses; }; // ----------------- Flow control ----------------- @@ -383,33 +367,33 @@ struct MatchCase { std::optional statement; }; -struct Match : public Node { +struct Match { Expression value; std::vector matches; }; -struct Condition : public Node { +struct Condition { std::vector conditions; // if, elif std::vector statements; // if, elif, else }; -struct DoWhileLoop : public Node { +struct DoWhileLoop { Expression condition; Expression statement; }; -struct WhileLoop : public Node { +struct WhileLoop { Expression condition; Expression statement; }; -struct ForLoop : public Node { +struct ForLoop { AnyName variable; Expression interval; Expression statement; }; -struct LoopLoop : public Node { +struct LoopLoop { Expression statement; }; @@ -417,140 +401,137 @@ struct LoopLoop : public Node { using BlockStatement = std::variant< std::unique_ptr, - std::unique_ptr, - std::unique_ptr, + std::unique_ptr, std::unique_ptr, std::unique_ptr>; -struct Block : public Node { +struct Block { std::vector statements; }; -struct ScopedStatement : public Node { +struct ScopedStatement { SuperExpression statement; }; // Operators ----------------- -struct BinaryOperatorExpression : public Node { +struct BinaryOperatorExpression { OperatorIdentifier operator_name; SubExpression left_expression; SubExpression right_expression; }; -struct UnaryOperatorExpression : public Node { // TODO fix prescendence +struct UnaryOperatorExpression { OperatorIdentifier operator_name; Expression expression; }; +struct ReferenceExpression { + std::vector references; + ScopedStatement expression; +} + // Simple Expressions ----------------- -using FunctionArgument = std::variant< - std::unique_ptr, - std::unique_ptr>; - -struct FunctionCallExpression : public Node { - std::unique_ptr name; +struct FunctionCallExpression { + std::unique_ptr name; std::vector arguments; }; -struct TupleExpression : public Node { +struct TupleExpression { std::vector expressions; }; -struct VariantExpression : public Node { +struct VariantExpression { std::vector expressions; }; -struct ReturnExpression : public Node { +struct ReturnExpression { Expression expression; }; -// Lambda ----------------- +struct TypeConstructor { + std::unique_ptr type; + std::vector> parameters; +}; -struct LambdaFunction : public Node { +struct LambdaFunction { std::vector> parameters; - std::vector> arguments; + std::vector arguments; Expression expression; }; +struct ArrayExpression { + std::vector elements; +}; + // Name ----------------- -struct NameSuperExpression : public Node { +struct NameExpression { std::vector namespaces; - std::vector expressions; + std::vector expressions; }; -struct NameExpression : public Node { - std::vector namespaces; - std::vector names; +struct TupleName { + std::vector> names; }; -struct TupleName : public Node { - std::vector> names; +struct VariantName { + std::vector> names; }; -struct VariantName : public Node { - std::vector> names; -}; - -struct AnnotatedName : public Node { +struct AnnotatedName { NameIdentifier name; - std::optional> type; // optional + std::optional> type; }; // TODO ?? mark all optional fields ?? // Type ----------------- -struct TypeConstructor : public Node { - std::unique_ptr type; - std::vector> parameters; +struct FunctionType { + std::vector types; }; -struct TupleType : public Node { - std::optional type; - std::vector, AnyType>> entities; +struct TupleType { + std::optional type; + std::vector, ExtendedScopedAnyType>> entities; }; -struct VariantType : public Node { - std::optional type; - std::vector>> constructors; +struct VariantType { + std::optional type; + std::vector>> constructors; }; -struct AnnotatedType : public Node { +struct AnnotatedType { std::unique_ptr type_expression; - std::vector> annotations; + std::vector> annotations; }; -using TypeParameter = std::variant< - std::unique_ptr, - std::unique_ptr, - std::unique_ptr>; - -struct ParametrizedType : public Node { +struct ParametrizedType { std::unique_ptr type_expression; std::vector parameters; }; -struct TypeExpression : public Node { +struct TypeExpression { std::vector namespaces; AnyTypeIdentifier type; + std::optional ArraySize; // if array; 0 - dynamic size }; +struct ExtendedScopedAnyType { + std::vector references; + AnyType type; +} + // Typeclass ----------------- -struct AnnotatedTypeclass : public Node { - std::unique_ptr typeclass_expression; - std::vector> annotations; -}; - -struct ParametrizedTypeclass : public Node { +struct ParametrizedTypeclass { std::unique_ptr typeclass_expression; std::vector parameters; }; -struct TypeclassExpression : public Node { +struct TypeclassExpression { std::vector namespaces; TypeclassIdentifier typeclass; }; @@ -558,19 +539,19 @@ struct TypeclassExpression : public Node { // ----------------- Comments [IGNORE] ----------------- // ----------------- Identifiers, constants, etc. ----------------- -struct FloatNumberLiteral : public Node { +struct FloatNumberLiteral { double value; }; -struct NumberLiteral : public Node { +struct NumberLiteral { int64_t value; }; -struct StringLiteral : public Node { +struct StringLiteral { std::string value; }; -struct CharLiteral : public Node { +struct CharLiteral { char value; }; diff --git a/include/parse_token_types.hpp b/include/parse_token_types.hpp index adcdc30..fe825b3 100644 --- a/include/parse_token_types.hpp +++ b/include/parse_token_types.hpp @@ -8,124 +8,116 @@ namespace parser::tokens { const std::string SourceFile = "source_file"; const std::string Sources = "sources"; +const std::string SourceStatement = "source_statement"; // Namespaces, partitions ----------------- -const std::string Partition = "partition"; const std::string Namespace = "namespace"; +const std::string Partition = "partition"; +const std::string PartitionName = "partition_name"; // Definitions ----------------- const std::string ImportStatement = "import_statement"; -const std::string UsageDefinition = "usage_definition"; -const std::string AliasDefinition = "alias_definition"; -const std::string VariableDefinition = "variable_definition"; +const std::string AliasDefinitionStatement = "alias_definition_statement"; +const std::string VariableDefinitionStatement = "variable_definition_statement"; const std::string FunctionDeclaration = "function_declaration"; -const std::string FunctionDefinition = "function_definition"; -const std::string AliasTypeDefinition = "alias_type_definition"; -const std::string TypeDefinition = "type_definition"; -const std::string TypeclassDefinition = "typeclass_definition"; - -const std::string SourceStatement = "source_statement"; -const std::string ImportSymbol = "import_symbol"; +const std::string FunctionDefinitionStatement = "function_definition_statement"; +const std::string TypeDefinitionStatement = "type_definition_statement"; +const std::string AbstractTypeDefinitionStatement = "abstract_type_definition_statement"; +const std::string TypeclassDefinitionStatement = "typeclass_definition_statement"; // Definition parts -const std::string DefinedName = "defined_name"; -const std::string DefinedAnnotatedName = "defined_annotated_name"; -const std::string DefinedType = "defined_type"; -const std::string DefinedTypeclass = "defined_typeclass"; +const std::string ImportSymbol = "import_symbol"; +const std::string FunctionDefinition = "function_definition"; +const std::string TypeDefinition = "type_definition"; const std::string DefinitionParameter = "definition_parameter"; -const std::string DefinitionArgument = "definition_argument"; - -const std::string FunctionDeclarationType = "function_declaration_type"; // Flow control ----------------- +const std::string MatchCase = "match_case"; const std::string Match = "match"; const std::string Condition = "condition"; const std::string DoWhileLoop = "do_while_loop"; const std::string WhileLoop = "while_loop"; const std::string ForLoop = "for_loop"; const std::string LoopLoop = "loop_loop"; - const std::string FlowControl = "flow_control"; // Statements, expressions, blocks, etc. ----------------- +const std::string BlockStatement = "block_statement"; const std::string Block = "block"; -const std::string ScopedStatement = "scoped_statement"; - -const std::string LoopControlExpression = "loop_control_expression"; - const std::string SubExpressionToken = "subexpression_token"; const std::string SubExpression = "subexpression"; const std::string PrefixedExpression = "prefixed_expression"; const std::string Expression = "expression"; const std::string SuperExpression = "superexpression"; - -const std::string BlockStatement = "block_statement"; +const std::string ScopedStatement = "scoped_statement"; // Operators const std::string BinaryOperatorExpression = "binary_operator_expression"; const std::string UnaryOperatorExpression = "unary_operator_expression"; +const std::string ReferenceExpression = "reference_expression"; -// Simple Expressions +// Other expressions +const std::string FunctionArgument = "function_argument"; const std::string FunctionCallExpression = "function_call_expression"; const std::string TupleExpression = "tuple_expression"; const std::string VariantExpression = "variant_expression"; const std::string ReturnExpression = "return_expression"; - -const std::string FunctionArgument = "function_argument"; - -// Lambda - +const std::string TypeConstructor = "type_constructor"; const std::string LambdaFunction = "lambda_function"; +const std::string ArrayExpression = "array_expression"; +const std::string LoopControlExpression = "loop_control_expression"; // Name -const std::string NameSuperExpression = "name_superexpression"; const std::string NameExpression = "name_expression"; const std::string TupleName = "tuple_name"; const std::string VariantName = "variant_name"; const std::string AnnotatedName = "annotated_name"; - +const std::string NameSubExpression = "name_subexpression"; const std::string AnyName = "any_name"; +const std::string ScopedAnyName = "scoped_any_name"; + +// Type, typeclass, etc. ----------------- // Type -const std::string TypeConstructor = "type_constructor"; +const std::string FunctionType = "function_type"; const std::string TupleType = "tuple_type"; const std::string VariantType = "variant_type"; const std::string AnnotatedType = "annotated_type"; const std::string ParametrizedType = "parametrized_type"; const std::string TypeExpression = "type_expression"; - +const std::string Constructor = "constructor"; const std::string AnyType = "any_type"; -const std::string TypeSubExpression = "type_subexpression"; - -const std::string TypeParameter = "type_parameter"; +const std::string ScopedAnyType = "scoped_any_type"; +const std::string ExtendedScopedAnyType = "extended_scoped_any_type"; // Typeclass -const std::string AnnotatedTypeclass = "annotated_typeclass"; +const std::string TypeclassUsage = "typeclass_usage"; const std::string ParametrizedTypeclass = "parametrized_typeclass"; const std::string TypeclassExpression = "typeclass_expression"; +// Typeclass & Type + +const std::string TypeParameter = "type_parameter"; +const std::string TypeSubExpression = "type_subexpression"; + // Identifiers, constants, etc. ----------------- -const std::string TypeIdentifierDefinition = "type_identifier_definition"; - +const std::string ExtendedName = "extended_name"; const std::string TypeclassIdentifier = "typeclass_identifier"; const std::string NameIdentifier = "name_identifier"; const std::string TypeIdentifier = "type_identifier"; const std::string AbstractTypeIdentifier = "abstract_type_identifier"; - -const std::string OperatorIdentifier = "operator_identifier"; - -// +const std::string OperatorIdentifier = "operator"; const std::string FloatNumberLiteral = "float_number_literal"; const std::string NumberLiteral = "number_literal"; @@ -134,6 +126,4 @@ const std::string CharLiteral = "char_literal"; const std::string Literal = "literal"; -const std::string NameSubSuperExpression = "name_subsuperexpression"; - } // namespace parser::tokens