From 5e94021ae5a8a1982ada37fd5f99e0d36442d318 Mon Sep 17 00:00:00 2001 From: erick-alcachofa Date: Sun, 12 Oct 2025 18:55:34 -0600 Subject: [PATCH] feat(AST): Add node factory helper and missing identifier node Signed-off-by: erick-alcachofa This commit introduces an utility factory function and structural improvements to the Abstract Syntax Tree (AST). * Adds a new `ASTNodePtr` C++20 concept to constrain template types to be `std::unique_ptr`s pointing to AST nodes. * Introduces a `MakeNode()` factory function that uses this concept to simplify and standardize the creation of new nodes. * Fixed `NamespacedType` and added the missing `NamespacedIdentifier` node. --- lib/include/artichoke/Parser/AST/AST.hpp | 5 +++++ lib/include/artichoke/Parser/AST/Common.hpp | 6 ++++++ lib/include/artichoke/Parser/AST/Types.hpp | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/lib/include/artichoke/Parser/AST/AST.hpp b/lib/include/artichoke/Parser/AST/AST.hpp index a53c54f..c44d640 100644 --- a/lib/include/artichoke/Parser/AST/AST.hpp +++ b/lib/include/artichoke/Parser/AST/AST.hpp @@ -23,4 +23,9 @@ namespace arti::lang::ast { Vector declarations; }; + template + auto MakeNode() { + return std::make_unique(); + } + } // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Common.hpp b/lib/include/artichoke/Parser/AST/Common.hpp index 4ce90d0..107cdd7 100644 --- a/lib/include/artichoke/Parser/AST/Common.hpp +++ b/lib/include/artichoke/Parser/AST/Common.hpp @@ -74,4 +74,10 @@ namespace arti::lang::ast { template using Vector = std::vector; + template + concept ASTNodePtr = requires { + typename Node::element_type; + requires std::is_same_v, Node>; + }; + } // namespace arti::lang::ast diff --git a/lib/include/artichoke/Parser/AST/Types.hpp b/lib/include/artichoke/Parser/AST/Types.hpp index fd4560d..f3bf72e 100644 --- a/lib/include/artichoke/Parser/AST/Types.hpp +++ b/lib/include/artichoke/Parser/AST/Types.hpp @@ -57,6 +57,13 @@ namespace arti::lang::ast { struct nodes::NamespacedType { SourceLocation location; + String typeName; + TypeExpressionNode baseType; + }; + + struct nodes::NamespacedIdentifier { + SourceLocation location; + Vector identParts; };