Skip to content

Commit

Permalink
feat(ast): add Modifiers support for ClassDecl, EnumDecl, and FuncDecl
Browse files Browse the repository at this point in the history
feat(ast): AST parser is now complete.

Implemented Modifiers support for ClassDecl, EnumDecl, and FuncDecl in the AST nodes of the Helix language. This change enables the specification of various modifiers for these declarations. Files modified: AST_Declarations.def, AST_modifiers.hh, AST_nodes.hh, AST_Expressions.def, AST_modifiers.hh.
  • Loading branch information
Ze7111 committed Oct 3, 2024
1 parent 1b46624 commit 9655043
Show file tree
Hide file tree
Showing 9 changed files with 799 additions and 218 deletions.
5 changes: 3 additions & 2 deletions source/parser/ast/include/config/AST_Declarations.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#ifndef __AST_DECLARATIONS_DEF__
#define __AST_DECLARATIONS_DEF__

#define DECLS(MACRO) \
#define DECLS(MACRO) \
MACRO(RequiresParamDecl) \
MACRO(RequiresParamList) \
MACRO(EnumMemberDecl) \
MACRO(UDTDeriveDecl) \
MACRO(TypeBoundList) \
MACRO(TypeBoundDecl) \
MACRO(RequiresDecl) \
MACRO(ModuleDecl) \
MACRO(StructDecl) \
MACRO(ConstDecl) \
MACRO(ClassDecl) \
Expand All @@ -31,6 +32,6 @@
MACRO(VarDecl) \
MACRO(FFIDecl) \
MACRO(LetDecl) \
MACRO(OpDecl) \
MACRO(OpDecl)

#endif // __AST_DECLARATIONS_DEF__
1 change: 0 additions & 1 deletion source/parser/ast/include/config/AST_Expressions.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
MACRO(NamedArgumentExpr) \
MACRO(ArgumentExpr) \
MACRO(ArgumentListExpr) \
MACRO(GenericArgumentExpr) \
MACRO(GenericInvokeExpr) \
MACRO(GenericInvokePathExpr) \
MACRO(ScopePathExpr) \
Expand Down
12 changes: 11 additions & 1 deletion source/parser/ast/include/config/AST_modifiers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ __AST_BEGIN {
}
}

// so if we set the modifiers to another Modifiers object
// we can copy the expected_modifiers and allowed_modifiers and verify if the other
// object has the modifiers we are looking for

static bool is_modifier(const token::Token &tok, ExpectedModifier modifier) {
switch (modifier) {
case ExpectedModifier::StorageSpec:
Expand All @@ -444,11 +448,17 @@ __AST_BEGIN {
return false;
}
}
static bool is_modifier(const token::Token &tok) {
return StorageSpecifier::is_storage_specifier(tok) ||
AccessSpecifier::is_access_specifier(tok) ||
FunctionSpecifier::is_function_specifier(tok) ||
ClassSpecifier::is_class_specifier(tok);
}

[[nodiscard]] bool find_add(const token::Token &current_token) {

if (allowed_modifiers.find(current_token.token_kind()) == allowed_modifiers.end()) {
return false;
return false; // not a modifier
}

for (const auto &modifier_type : expected_modifiers) {
Expand Down
30 changes: 15 additions & 15 deletions source/parser/ast/include/core/AST_nodes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ __AST_NODE_BEGIN {
return parse_ArgumentExpr(std ::forward<Args>(args)...);
} else if constexpr (std ::is_same_v<T, ArgumentListExpr>) {
return parse_ArgumentListExpr(std ::forward<Args>(args)...);
} else if constexpr (std ::is_same_v<T, GenericArgumentExpr>) {
return parse_GenericArgumentExpr(std ::forward<Args>(args)...);
} else if constexpr (std ::is_same_v<T, GenericInvokeExpr>) {
return parse_GenericInvokeExpr(std ::forward<Args>(args)...);
} else if constexpr (std ::is_same_v<T, GenericInvokePathExpr>) {
Expand Down Expand Up @@ -140,7 +138,6 @@ __AST_NODE_BEGIN {
p_r<ScopePathExpr> parse_ScopePathExpr(p_r<> lhs = null);
p_r<ArrayAccessExpr> parse_ArrayAccessExpr(p_r<> lhs = null);
p_r<ArgumentListExpr> parse_ArgumentListExpr();
p_r<GenericArgumentExpr> parse_GenericArgumentExpr();
p_r<GenericInvokeExpr> parse_GenericInvokeExpr();
p_r<GenericInvokePathExpr> parse_GenericInvokePathExpr();
p_r<ArrayLiteralExpr> parse_ArrayLiteralExpr();
Expand All @@ -156,7 +153,7 @@ __AST_NODE_BEGIN {
p_r<InstOfExpr> parse_InstOfExpr(p_r<> lhs = null);
p_r<Type> parse_Type();
p_r<AsyncThreading> parse_AsyncThreading();
p_r<FunctionCallExpr> parse_FunctionCallExpr(p_r<> lhs = null, p_r<> gens = null);
p_r<FunctionCallExpr> parse_FunctionCallExpr(p_r<> lhs = null);
};

/*
Expand Down Expand Up @@ -326,7 +323,9 @@ __AST_NODE_BEGIN {
return parse_LetDecl(std ::forward<Args>(args)...);
} else if constexpr (std ::is_same_v<T, OpDecl>) {
return parse_OpDecl(std ::forward<Args>(args)...);
};
} else if constexpr (std ::is_same_v<T, ModuleDecl>) {
return parse_ModuleDecl(std ::forward<Args>(args)...);
}
}

private:
Expand All @@ -340,17 +339,18 @@ __AST_NODE_BEGIN {
p_r<TypeBoundList> parse_TypeBoundList();
p_r<TypeBoundDecl> parse_TypeBoundDecl();
p_r<RequiresDecl> parse_RequiresDecl();
p_r<StructDecl> parse_StructDecl();
p_r<ModuleDecl> parse_ModuleDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<StructDecl> parse_StructDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<ConstDecl> parse_ConstDecl();
p_r<ClassDecl> parse_ClassDecl();
p_r<InterDecl> parse_InterDecl();
p_r<EnumDecl> parse_EnumDecl();
p_r<TypeDecl> parse_TypeDecl();
p_r<FuncDecl> parse_FuncDecl();
p_r<VarDecl> parse_VarDecl();
p_r<FFIDecl> parse_FFIDecl();
p_r<LetDecl> parse_LetDecl();
p_r<OpDecl> parse_OpDecl();
p_r<ClassDecl> parse_ClassDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<InterDecl> parse_InterDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<EnumDecl> parse_EnumDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<TypeDecl> parse_TypeDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<FuncDecl> parse_FuncDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<VarDecl> parse_VarDecl(bool force_type = false, bool force_value = false);
p_r<FFIDecl> parse_FFIDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<LetDecl> parse_LetDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
p_r<OpDecl> parse_OpDecl(const std::shared_ptr<token::TokenList>& modifiers = nullptr);
};
} // namespace __AST_BEGIN

Expand Down
Loading

0 comments on commit 9655043

Please sign in to comment.