From 0192844d27e5c112ff69499692bcca887d71c750 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Mon, 4 May 2026 17:25:53 +0200 Subject: [PATCH] Type params gen --- parser/src/ast.rs | 3 ++- parser/src/lib.rs | 8 +++++++- src/codegen.rs | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 4909378..826ac95 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -13,7 +13,8 @@ pub struct Block(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TypeExpr { - Path(StaticPath, Vec), + Path(StaticPath), + PathParams(StaticPath, Vec), Tuple(Vec), } diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 27b25ab..72cea59 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -33,8 +33,14 @@ impl From> for TypeExpr { Rule::tuple_type => TypeExpr::Tuple(pair.into_inner().map(TypeExpr::from).collect()), Rule::path_type => { let mut inner = pair.into_inner(); + let path = StaticPath::from(inner.next().unwrap()); + let params = inner.map(TypeExpr::from).collect::>(); - TypeExpr::Path(StaticPath::from(inner.next().unwrap()), inner.map(TypeExpr::from).collect()) + if params.len() == 0 { + TypeExpr::Path(path) + } else { + TypeExpr::PathParams(path, params) + } } _ => unimplemented!("{pair:#?}"), } diff --git a/src/codegen.rs b/src/codegen.rs index b16ffda..1ede7e7 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -76,6 +76,17 @@ impl GetRust for TypeExpr { fn get_rust(&self) -> String { match self { TypeExpr::Path(path) => get_static_type_path(path), + TypeExpr::PathParams(path, params) => { + format!( + "{}<{}>", + get_static_type_path(path), + params + .iter() + .map(|t| t.get_rust()) + .collect::>() + .join(", ") + ) + } TypeExpr::Tuple(types) => format!( "({})", types