diff --git a/lib/include/artichoke/Parser/AST/AST.hpp b/lib/include/artichoke/Parser/AST/AST.hpp new file mode 100644 index 0000000..a53c54f --- /dev/null +++ b/lib/include/artichoke/Parser/AST/AST.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main declaration node types */ + struct CompilationUnit; + + } // namespace nodes + + /* Public Aliases */ + using CompilationUnitNode = Ptr; + using AST = CompilationUnitNode; + + /* Node definitions */ + struct nodes::CompilationUnit { + String unitName; + Vector declarations; + }; + +} // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Common.hpp b/lib/include/artichoke/Parser/AST/Common.hpp new file mode 100644 index 0000000..4ce90d0 --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Common.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace arti::lang::ast { + + struct SourceLocation { + std::size_t line; + std::size_t column; + }; + + enum class Mutability { + Mutable, + Constant, + }; + + enum class TypeQualifier { + Pointer, + Slice, + Mutable, + Optional, + }; + + enum class UnaryOperator { + Not, + Minus, + BitNot, + Ampersand, + Star, + }; + + enum class BinaryOperator { + Equal, + NotEqual, + GreaterThan, + LessThan, + GreaterEqual, + LessEqual, + }; + + enum class CompoundAssignOperator { + Addition, + Substraction, + Multiplication, + Division, + Modulo, + BitAnd, + BitOr, + LeftShift, + RightShift, + BoolAnd, + BoolOr, + }; + + /* Alising of types for consistency */ + + using Boolean = bool; + using String = std::string; + + template + using Ptr = std::unique_ptr; + + template + using Optional = std::optional; + + template + using Variant = std::variant; + + template + using Vector = std::vector; + +} // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Declarations.hpp b/lib/include/artichoke/Parser/AST/Declarations.hpp new file mode 100644 index 0000000..deb2db1 --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Declarations.hpp @@ -0,0 +1,139 @@ +#pragma once + +#include +#include +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main declaration node types */ + struct ModuleDeclaration; + struct StructDeclaration; + struct EnumDeclaration; + struct FunctionDeclaration; + struct ImportDeclaration; + struct AliasDeclaration; + + /* Helper declaration node types */ + struct EnumMember; + struct StructMember; + struct GenericParam; + struct FunctionParam; + + } // namespace nodes + + /* Public Aliases */ + using ModuleDeclNode = Ptr; + using StructDeclNode = Ptr; + using EnumDeclNode = Ptr; + using FunctionDeclNode = Ptr; + using ImportDeclNode = Ptr; + using AliasDeclNode = Ptr; + using GenericParamNode = Ptr; + using FunctionParamNode = Ptr; + using EnumMemberNode = Ptr; + using StructMemberNode = Ptr; + + /* Variant nodes */ + using TopLevelDeclNode = Variant< + ModuleDeclNode, + StructDeclNode, + EnumDeclNode, + FunctionDeclNode, + ImportDeclNode, + AliasDeclNode + >; + + using ModuleInnerDeclNode = Variant< + StructDeclNode, + EnumDeclNode, + FunctionDeclNode + >; + + /* Node definitions */ + + struct nodes::ModuleDeclaration { + SourceLocation location; + + Boolean isExported; + NamespacedIdentifierNode name; + Vector childModules; + Vector innerDeclarations; + Vector aliasDeclarations; + }; + + struct nodes::StructDeclaration { + SourceLocation location; + + Boolean isExported; + String name; + Vector genericParams; + Vector structMembers; + }; + + struct nodes::EnumDeclaration { + SourceLocation location; + + Boolean isExported; + String name; + Vector genericParams; + Vector enumMembers; + }; + + struct nodes::FunctionDeclaration { + SourceLocation location; + + Boolean isExported; + String name; + Optional returnType; + Vector genericParams; + Vector functionParams; + CodeBlockStmtNode functionBody; + }; + + struct nodes::ImportDeclaration { + SourceLocation location; + + Boolean importAll; + NamespacedIdentifierNode importTarget; + }; + + struct nodes::AliasDeclaration { + SourceLocation location; + + String alias; + TypeNode target; + }; + + struct nodes::StructMember { + SourceLocation location; + + String name; + TypeNode type; + }; + + struct nodes::EnumMember { + SourceLocation location; + + String name; + Optional type; + }; + + struct nodes::GenericParam { + SourceLocation location; + + String name; + }; + + struct nodes::FunctionParam { + SourceLocation location; + + Boolean isThis; + String name; + TypeNode type; + }; + +} // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Expressions.hpp b/lib/include/artichoke/Parser/AST/Expressions.hpp new file mode 100644 index 0000000..49c6446 --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Expressions.hpp @@ -0,0 +1,205 @@ +#pragma once + +#include +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main declaration node types */ + struct IdentifierExpression; + struct UnaryExpression; + struct BinaryExpression; + struct AssignExpression; + struct CompoundAssignExpression; + struct FunctionCallExpression; + struct SliceAccessExpression; + struct SliceRangeExpression; + struct MemberAccessExpression; + struct PointerAccessExpression; + struct ScopeAccessExpression; + struct ReflectionExpression; + struct SliceCreationExpression; + struct SliceLengthExpression; + struct SlicePtrExpression; + + } // namespace nodes + + /* Public Aliases */ + using IdentifierExprNode = Ptr; + using UnaryExprNode = Ptr; + using BinaryExprNode = Ptr; + using AssignExprNode = Ptr; + using CompoundAssignExprNode = Ptr; + using FunctionCallExprNode = Ptr; + using SliceAccessExprNode = Ptr; + using SliceRangeExprNode = Ptr; + using MemberAccessExprNode = Ptr; + using PointerAccessExprNode = Ptr; + using ScopeAccessExprNode = Ptr; + using ReflectionExprNode = Ptr; + using SliceCreationExprNode = Ptr; + using SliceLengthExprNode = Ptr; + using SlicePtrExprNode = Ptr; + + /* Variant nodes */ + using ExpressionNode = Variant< + CharLtrlNode, + NullLtrlNode, + StringLtrlNode, + FloatLtrlNode, + IntegerLtrlNode, + BooleanLtrlNode, + StructLtrlNode, + SliceLtrlNode, + IdentifierExprNode, + UnaryExprNode, + BinaryExprNode, + AssignExprNode, + CompoundAssignExprNode, + FunctionCallExprNode, + SliceAccessExprNode, + SliceRangeExprNode, + MemberAccessExprNode, + PointerAccessExprNode, + ScopeAccessExprNode, + SliceCreationExprNode, + SliceLengthExprNode, + SlicePtrExprNode, + ReflectionExprNode + >; + + /* Node definitions */ + struct nodes::IdentifierExpression { + SourceLocation location; + String identifierName; + }; + + struct nodes::UnaryExpression { + SourceLocation location; + UnaryOperator op; + ExpressionNode right; + }; + + struct nodes::BinaryExpression { + SourceLocation location; + + BinaryOperator op; + ExpressionNode left; + ExpressionNode right; + }; + + struct nodes::AssignExpression { + SourceLocation location; + + ExpressionNode left; + ExpressionNode right; + }; + + struct nodes::CompoundAssignExpression { + SourceLocation location; + + CompoundAssignOperator op; + ExpressionNode left; + ExpressionNode right; + }; + + struct nodes::FunctionCallExpression { + SourceLocation location; + + ExpressionNode callee; + Vector arguments; + }; + + struct nodes::SliceAccessExpression { + SourceLocation location; + + ExpressionNode slice; + ExpressionNode index; + }; + + struct nodes::SliceRangeExpression { + SourceLocation location; + + ExpressionNode slice; + Optional start; + Optional end; + }; + + struct nodes::MemberAccessExpression { + SourceLocation location; + + String memberName; + ExpressionNode object; + }; + + struct nodes::PointerAccessExpression { + SourceLocation location; + + String memberName; + ExpressionNode object; + }; + + struct nodes::ScopeAccessExpression { + SourceLocation location; + + String memberName; + ExpressionNode scope; + Vector genericParams; + }; + + struct nodes::ReflectionExpression { + SourceLocation location; + + String attribute; + ExpressionNode object; + }; + + struct nodes::SliceCreationExpression { + SourceLocation location; + + ExpressionNode object; + ExpressionNode length; + }; + + struct nodes::SliceLengthExpression { + SourceLocation location; + + ExpressionNode object; + }; + + struct nodes::SlicePtrExpression { + SourceLocation location; + + ExpressionNode object; + }; + + struct nodes::StructLiteralNamedFieldInit { + SourceLocation location; + + String fieldName; + ExpressionNode fieldValue; + }; + + struct nodes::StructLiteralPositionalInit { + SourceLocation location; + + ExpressionNode fieldValue; + }; + + struct nodes::StructLiteralNamedInitializer { + SourceLocation location; + + Vector fields; + }; + + struct nodes::StructLiteralPositionalInitializer { + SourceLocation location; + + Vector fields; + }; + +} // namespace arti::lang::ast + diff --git a/lib/include/artichoke/Parser/AST/Literals.hpp b/lib/include/artichoke/Parser/AST/Literals.hpp new file mode 100644 index 0000000..3699b8e --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Literals.hpp @@ -0,0 +1,109 @@ +#pragma once + +#include +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main declaration node types */ + struct CharLiteral; + struct NullLiteral; + struct StringLiteral; + struct FloatLiteral; + struct IntegerLiteral; + struct BooleanLiteral; + struct StructLiteral; + struct SliceLiteral; + + /* Helper declaration node types */ + struct StructLiteralNamedFieldInit; + struct StructLiteralPositionalInit; + struct StructLiteralNamedInitializer; + struct StructLiteralPositionalInitializer; + + } // namespace nodes + + /* Public Aliases */ + using CharLtrlNode = Ptr; + using NullLtrlNode = Ptr; + using StringLtrlNode = Ptr; + using FloatLtrlNode = Ptr; + using IntegerLtrlNode = Ptr; + using BooleanLtrlNode = Ptr; + using StructLtrlNode = Ptr; + using SliceLtrlNode = Ptr; + + using StructLtrlNamedFieldInitNode = + Ptr; + using StructLtrlPositionalInitNode = + Ptr; + using StructLtrlNamedInitializerNode = + Ptr; + using StructLtrlPositionalInitializerNode = + Ptr; + + /* Variant nodes */ + using StructLtrlInitializerNode = Variant< + StructLtrlNamedInitializerNode, + StructLtrlPositionalInitializerNode + >; + + /* Node definitions */ + + struct nodes::CharLiteral { + SourceLocation location; + + uint8_t value; + }; + + struct nodes::NullLiteral { + SourceLocation location; + }; + + struct nodes::StringLiteral { + SourceLocation location; + + String value; + }; + + struct nodes::FloatLiteral { + SourceLocation location; + + double value; + }; + + struct nodes::IntegerLiteral { + SourceLocation location; + + uint64_t value; + }; + + struct nodes::BooleanLiteral { + SourceLocation location; + + Boolean value; + }; + + struct nodes::StructLiteral { + SourceLocation location; + + TypeNode type; + Optional initializer; + }; + + struct nodes::SliceLiteral { + SourceLocation location; + + TypeNode type; + Optional initializer; + }; + + /* INFO: Helper types definitions are on Expressions.hpp + * due to dependency in ExpressionNode variant. */ + +} // namespace arti::lang::ast + + diff --git a/lib/include/artichoke/Parser/AST/Node.hpp b/lib/include/artichoke/Parser/AST/Node.hpp deleted file mode 100644 index a992385..0000000 --- a/lib/include/artichoke/Parser/AST/Node.hpp +++ /dev/null @@ -1,580 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace arti::lang::ast { - - struct SourceLocation { - std::size_t line; - std::size_t column; - }; - - namespace node { - template - using Ptr = std::unique_ptr; - - template - using Opt = std::optional; - - enum class Mutability { - Mutable, - Constant, - }; - - enum class TypeQualifier { - Pointer, - Slice, - Mutable, - Optional, - }; - - enum class UnaryOperator { - Not, - Minus, - BitNot, - Ampersand, - Star, - }; - - enum class BinaryOperator { - Equal, - NotEqual, - GreaterThan, - LessThan, - GreaterEqual, - LessEqual, - }; - - enum class CompoundAssignType { - Addition, - Substraction, - Multiplication, - Division, - Modulo, - BitAnd, - BitOr, - LeftShift, - RightShift, - BoolAnd, - BoolOr, - }; - - /* -------- Nodes Forward Declarations -------- */ - struct Module; - struct Struct; - struct Enum; - struct Function; - struct ImportStatement; - struct AliasStatement; - struct GenericParam; - struct FunctionParam; - struct StructMember; - struct EnumMember; - struct CodeBlock; - struct VariableDeclaration; - struct IfStatement; - struct ElseStatement; - struct DeferStatement; - struct ErrDeferStatement; - struct ReturnStatement; - struct BreakStatement; - struct ContinueStatement; - struct MatchStatement; - struct SwitchStatement; - struct CForStatement; - struct RangeForStatement; - struct WhileStatement; - struct DoWhileStatement; - struct InfLoopStatement; - struct ExpressionStatement; - struct MatchCase; - struct SwitchCase; - struct Type; - struct SimpleTypeExpression; - struct GenericTypeExpression; - struct AccessTypeExpression; - struct NamespacedIdentifier; - - struct UnaryExpression; - struct BinaryExpression; - - struct AssignExpression; - struct CompoundAssignExpression; - struct FunctionCallExpression; - struct SliceAccessExpression; - struct SliceRangeExpression; - struct MemberAccessExpression; - struct ScopeAccessExpression; - struct PointerAccessExpression; - struct ReflectionExpression; - struct SliceCreationExpression; - struct SliceLengthExpression; - struct SlicePtrExpression; - struct IdentifierExpression; - - struct StructNamedInit; - struct StructNamedFieldsInit; - struct StructExpressionsInit; - - struct CharLiteral; - struct NullLiteral; - struct StringLiteral; - struct FloatLiteral; - struct IntegerLiteral; - struct BooleanLiteral; - struct StructLiteral; - - /* -------- Nodes Definitions -------- */ - - /* Top Level & Declarations */ - - using Declaration = std::variant< - Ptr, - Ptr, - Ptr>; - - using TopLevelDeclaration = std::variant< - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr>; - - struct Module { - SourceLocation location; - bool isExported; - Ptr name; - std::vector> childModules; - std::vector declarations; - std::vector> aliasedElements; - }; - - struct ImportStatement { - SourceLocation location; - bool importAll; - Ptr target; - }; - - struct AliasStatement { - SourceLocation location; - std::string name; - Ptr aliased; - }; - - struct Function { - SourceLocation location; - bool isExported; - std::string name; - Ptr returnType; - Ptr body; - std::vector> generics; - std::vector> params; - }; - - struct Struct { - SourceLocation location; - bool isExported; - std::string name; - std::vector> generics; - std::vector> members; - }; - - struct Enum { - SourceLocation location; - bool isExported; - std::string name; - std::vector> generics; - std::vector> members; - }; - - struct GenericParam { - SourceLocation location; - std::string name; - }; - - struct FunctionParam { - SourceLocation location; - bool isThis; - std::string name; - Ptr type; - }; - - struct StructMember { - SourceLocation location; - std::string name; - Ptr type; - }; - - struct EnumMember { - SourceLocation location; - std::string name; - Ptr type; - }; - - /* Expression node types */ - - using Expression = std::variant< - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr>; - - using StructLiteralFields = std::variant< - Ptr, - Ptr>; - - struct CharLiteral { - SourceLocation location; - uint8_t value; - }; - - struct NullLiteral { - SourceLocation location; - }; - - struct StringLiteral { - SourceLocation location; - std::string value; - }; - - struct FloatLiteral { - SourceLocation location; - double value; - }; - - struct IntegerLiteral { - SourceLocation location; - uint64_t value; - }; - - struct BooleanLiteral { - SourceLocation location; - bool value; - }; - - struct StructLiteral { - SourceLocation location; - Ptr type; - StructLiteralFields fields; - }; - - struct StructNamedInit { - SourceLocation location; - std::string name; - Ptr initializer; - }; - - struct StructNamedFieldsInit { - std::vector fields; - }; - - struct StructExpressionsInit { - std::vector locations; - std::vector> initializers; - }; - - struct IdentifierExpression { - SourceLocation location; - std::string name; - }; - - struct UnaryExpression { - SourceLocation location; - UnaryOperator operatorT; - Ptr right; - }; - - struct BinaryExpression { - SourceLocation location; - BinaryOperator operatorT; - Ptr leftHs; - Ptr rightHs; - }; - - struct AssignExpression { - SourceLocation location; - Ptr leftHs; - Ptr rightHs; - }; - - struct CompoundAssignExpression { - SourceLocation location; - CompoundAssignType type; - Ptr leftHs; - Ptr rightHs; - }; - - struct FunctionCallExpression { - SourceLocation location; - Ptr callee; - std::vector> arguments; - }; - - struct SliceAccessExpression { - SourceLocation location; - Ptr slice; - Ptr index; - }; - - struct SliceRangeExpression { - SourceLocation location; - Ptr slice; - Ptr start; - Ptr end; - }; - - struct MemberAccessExpression { - SourceLocation location; - Ptr object; - std::string memberName; - }; - - struct ScopeAccessExpression { - SourceLocation location; - Ptr object; - std::string memberName; - std::vector> genericParams; - }; - - struct PointerAccessExpression { - SourceLocation location; - Ptr object; - std::string memberName; - }; - - struct ReflectionExpression { - SourceLocation location; - Ptr object; - Opt attribute; - }; - - struct SliceCreationExpression { - SourceLocation location; - Ptr object; - Ptr length; - }; - - struct SliceLengthExpression { - SourceLocation location; - Ptr object; - }; - - struct SlicePtrExpression { - SourceLocation location; - Ptr object; - }; - - /* Statements */ - - using Statement = std::variant< - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr, - Ptr>; - - using ElseBranch = std::variant< - Ptr, - Ptr>; - - using Deferable = std::variant< - Ptr, - Ptr>; - - using PreLoopStatement = std::variant< - Ptr, - Ptr>; - - using TypeExpression = std::variant< - Ptr, - Ptr, - Ptr>; - - - struct CodeBlock { - SourceLocation location; - std::vector statements; - }; - - struct VariableDeclaration { - SourceLocation location; - Mutability mutability; - std::string name; - Ptr type; - Ptr initializer; - }; - - struct IfStatement { - SourceLocation location; - Opt unwrappedVar; - Ptr condition; - Ptr body; - Opt elseBranch; - }; - - struct ElseStatement { - SourceLocation location; - Opt unwrappedVar; - Ptr body; - }; - - struct DeferStatement { - SourceLocation location; - Deferable body; - }; - - struct ErrDeferStatement { - SourceLocation location; - Deferable body; - }; - - struct ReturnStatement { - SourceLocation location; - Ptr value; - }; - - struct BreakStatement { - SourceLocation location; - Opt label; - }; - - struct ContinueStatement { - SourceLocation location; - Opt label; - }; - - struct MatchStatement { - SourceLocation location; - Ptr value; - std::vector> cases; - Ptr defaultCase; - }; - - struct SwitchStatement { - SourceLocation location; - Ptr value; - std::vector> cases; - Ptr defaultCase; - }; - - struct MatchCase { - SourceLocation location; - std::string identifier; - Ptr matchType; - Ptr body; - }; - - struct SwitchCase { - SourceLocation location; - Ptr matchExpr; - Ptr body; - }; - - struct CForStatement { - SourceLocation location; - Ptr preLoop; - Ptr condition; - Ptr postLoop; - Ptr body; - }; - - struct RangeForStatement { - SourceLocation location; - Mutability varMutability; - std::string varName; - Ptr range; - Ptr body; - }; - - struct WhileStatement { - SourceLocation location; - Opt unwrappedVar; - Ptr condition; - Ptr body; - Opt elseBranch; - }; - - struct DoWhileStatement { - SourceLocation location; - Ptr body; - Ptr condition; - }; - - struct InfLoopStatement { - SourceLocation location; - Ptr body; - }; - - struct ExpressionStatement { - SourceLocation location; - Ptr expression; - }; - - struct SimpleTypeExpression { - SourceLocation location; - Ptr name; - }; - - struct GenericTypeExpression { - SourceLocation location; - TypeExpression baseType; - std::vector> genericArgs; - }; - - struct AccessTypeExpression { - SourceLocation location; - TypeExpression baseType; - std::string memberName; - }; - - struct Type { - SourceLocation location; - std::vector qualifiers; - TypeExpression expression; - }; - - struct NamespacedIdentifier { - SourceLocation location; - std::vector identifierParts; - }; - - } // namespace node - - struct AST { - std::vector declarations; - }; - -} // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Statements.hpp b/lib/include/artichoke/Parser/AST/Statements.hpp new file mode 100644 index 0000000..6c30b88 --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Statements.hpp @@ -0,0 +1,238 @@ +#pragma once + +#include +#include +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main declaration node types */ + struct CodeBlockStatement; + struct VariableDeclStatement; + struct IfStatement; + struct ElseStatement; + struct DeferStatement; + struct ErrDeferStatement; + struct ReturnStatement; + struct BreakStatement; + struct ContinueStatement; + struct MatchStatement; + struct SwitchStatement; + struct CForStatement; + struct RangeForStatement; + struct WhileStatement; + struct DoWhileStatement; + struct InfLoopStatement; + struct ExpressionStatement; + + /* Helper declaration node types */ + struct MatchCase; + struct SwitchCase; + + } // namespace nodes + + /* Public Aliases */ + using CodeBlockStmtNode = Ptr; + using VariableStmtNode = Ptr; + using IfStmtNode = Ptr; + using ElseStmtNode = Ptr; + using DeferStmtNode = Ptr; + using ErrDeferStmtNode = Ptr; + using ReturnStmtNode = Ptr; + using BreakStmtNode = Ptr; + using ContinueStmtNode = Ptr; + using MatchStmtNode = Ptr; + using SwitchStmtNode = Ptr; + using CForStmtNode = Ptr; + using RangeForStmtNode = Ptr; + using WhileStmtNode = Ptr; + using DoWhileStmtNode = Ptr; + using InfLoopStmtNode = Ptr; + using ExpressionStmtNode = Ptr; + using MatchCaseNode = Ptr; + using SwitchCaseNode = Ptr; + + /* Variant nodes */ + using StatementNode = Variant< + VariableStmtNode, + IfStmtNode, + DeferStmtNode, + ErrDeferStmtNode, + ReturnStmtNode, + BreakStmtNode, + ContinueStmtNode, + MatchStmtNode, + SwitchStmtNode, + CForStmtNode, + RangeForStmtNode, + WhileStmtNode, + DoWhileStmtNode, + InfLoopStmtNode, + ExpressionStmtNode + >; + + using ElseBranchNode = Variant< + ElseStmtNode, + IfStmtNode + >; + + using DeferableNode = Variant< + ExpressionStmtNode, + CodeBlockStmtNode + >; + + using PreLoopStmtNode = Variant< + VariableStmtNode, + ExpressionStmtNode + >; + + /* Node definitions */ + + struct nodes::CodeBlockStatement { + SourceLocation location; + + Vector statements; + }; + + struct nodes::VariableDeclStatement { + SourceLocation location; + + String name; + Mutability mutability; + Optional type; + Optional initializer; + }; + + struct nodes::IfStatement { + SourceLocation location; + + Optional unwrappedVar; + ExpressionNode condition; + CodeBlockStmtNode body; + ElseBranchNode elseBranch; + }; + + struct nodes::ElseStatement { + SourceLocation location; + + Optional unwrappedVar; + CodeBlockStmtNode body; + }; + + struct nodes::DeferStatement { + SourceLocation location; + + DeferableNode body; + }; + + struct nodes::ErrDeferStatement { + SourceLocation location; + + DeferableNode body; + }; + + struct nodes::ReturnStatement { + SourceLocation location; + + Optional value; + }; + + struct nodes::BreakStatement { + SourceLocation location; + + Optional label; + }; + + struct nodes::ContinueStatement { + SourceLocation location; + + Optional label; + }; + + struct nodes::MatchStatement { + SourceLocation location; + + ExpressionNode value; + Vector matchCases; + CodeBlockStmtNode defaultCase; + }; + + struct nodes::SwitchStatement { + SourceLocation location; + + ExpressionNode value; + Vector switchCases; + CodeBlockStmtNode defaultCase; + }; + + struct nodes::CForStatement { + SourceLocation location; + + Optional label; + PreLoopStmtNode preLoop; + ExpressionNode condition; + ExpressionNode postLoop; + CodeBlockStmtNode body; + }; + + struct nodes::RangeForStatement { + SourceLocation location; + + Optional label; + String varName; + Mutability varMutability; + ExpressionNode range; + CodeBlockStmtNode body; + }; + + struct nodes::WhileStatement { + SourceLocation location; + + Optional label; + Optional unwrappedVar; + ExpressionNode condition; + CodeBlockStmtNode body; + ElseBranchNode elseBranch; + }; + + struct nodes::DoWhileStatement { + SourceLocation location; + + Optional label; + ExpressionNode condition; + CodeBlockStmtNode body; + }; + + struct nodes::InfLoopStatement { + SourceLocation location; + + Optional label; + CodeBlockStmtNode body; + }; + + struct nodes::ExpressionStatement { + SourceLocation location; + + ExpressionNode expression; + }; + + struct nodes::MatchCase { + SourceLocation location; + + TypeNode matchType; + Optional unwrappedVar; + CodeBlockStmtNode body; + }; + + struct nodes::SwitchCase { + SourceLocation location; + + ExpressionNode matchExpr; + CodeBlockStmtNode body; + }; + +} // namespace arti::lang::ast + diff --git a/lib/include/artichoke/Parser/AST/Types.hpp b/lib/include/artichoke/Parser/AST/Types.hpp new file mode 100644 index 0000000..fd4560d --- /dev/null +++ b/lib/include/artichoke/Parser/AST/Types.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include + +namespace arti::lang::ast { + + namespace nodes { + /* Forward declaration of types */ + + /* Main type node types */ + struct Type; + struct GenericType; + struct IdentifierType; + struct NamespacedType; + + /* Helper type node types */ + struct NamespacedIdentifier; + + } // namespace nodes + + /* Public Aliases */ + using TypeNode = Ptr; + using GenericTypeNode = Ptr; + using IdentifierTypeNode = Ptr; + using NamespacedTypeNode = Ptr; + using NamespacedIdentifierNode = Ptr; + + /* Variant nodes */ + using TypeExpressionNode = Variant< + GenericTypeNode, + IdentifierTypeNode, + NamespacedTypeNode + >; + + /* Node definitions */ + + struct nodes::Type { + SourceLocation location; + + Vector qualifiers; + TypeExpressionNode baseType; + }; + + struct nodes::GenericType { + SourceLocation location; + + TypeExpressionNode baseType; + Vector genericArgs; + }; + + struct nodes::IdentifierType { + SourceLocation location; + + NamespacedIdentifierNode typeName; + }; + + struct nodes::NamespacedType { + SourceLocation location; + + Vector identParts; + }; + +} // namespace arti::lang::ast