From 69e5ab2a5e1d70cc3fab57a16607e0992a8aea56 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 19 May 2026 06:55:58 +0200 Subject: [PATCH] Dyn type --- parser/src/ast/mod.rs | 1 + parser/src/grammar.pest | 6 +++++- parser/src/parser/common/types.rs | 2 ++ src/codegen.rs | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index f1d03f3..deff4e2 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -26,6 +26,7 @@ pub enum TypePostfix { RefMut, RefLifetime(Identifier), RefMutLifetime(Identifier), + Dyn, } #[derive(Debug, Clone, Serialize)] diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index f969378..d13c390 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -85,8 +85,12 @@ ref_type = { mutable? ~ lifetime? ~ "*" } +dyn_type = { + "dyn" +} + type_expr = { - (path_type | tuple_type) ~ ref_type* + (path_type | tuple_type) ~ (ref_type | dyn_type)* } lifetime = { diff --git a/parser/src/parser/common/types.rs b/parser/src/parser/common/types.rs index 840ae4d..c557e53 100644 --- a/parser/src/parser/common/types.rs +++ b/parser/src/parser/common/types.rs @@ -36,6 +36,8 @@ impl<'a> TryFrom> for TypePostfix { }) } + Rule::dyn_type => Ok(TypePostfix::Dyn), + _ => AstError::bug_unimplemented(pair), } } diff --git a/src/codegen.rs b/src/codegen.rs index 6fdd3c9..3349139 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -828,6 +828,7 @@ impl GetRust for TypePostfix { TypePostfix::RefMut => format!("&mut "), TypePostfix::RefLifetime(lifetime) => format!("&'{} ", lifetime.get_rust()), TypePostfix::RefMutLifetime(lifetime) => format!("&'{} mut ", lifetime.get_rust()), + TypePostfix::Dyn => format!("dyn "), } } }