From dcb5b7f919237daf55bc02458fb0df7b8be4dbc5 Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Wed, 23 Oct 2024 20:42:17 -0500 Subject: [PATCH] Added ability to parse polymorphic types --- src/ast/datatype/kind/display.rs | 3 +++ src/ast/datatype/kind/mod.rs | 1 + src/parser/parse_type.rs | 20 ++++++++++++-------- src/resolve/mod.rs | 4 ++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ast/datatype/kind/display.rs b/src/ast/datatype/kind/display.rs index 1f42f06..462a2b9 100644 --- a/src/ast/datatype/kind/display.rs +++ b/src/ast/datatype/kind/display.rs @@ -48,6 +48,9 @@ impl Display for &TypeKind { TypeKind::FunctionPointer(_function) => { write!(f, "(function pointer type)")?; } + TypeKind::Polymorph(polymorph) => { + write!(f, "${}", polymorph)?; + } } Ok(()) diff --git a/src/ast/datatype/kind/mod.rs b/src/ast/datatype/kind/mod.rs index 032819f..f4705ba 100644 --- a/src/ast/datatype/kind/mod.rs +++ b/src/ast/datatype/kind/mod.rs @@ -21,6 +21,7 @@ pub enum TypeKind { AnonymousUnion(AnoymousUnion), AnonymousEnum(AnonymousEnum), FunctionPointer(FunctionPointer), + Polymorph(String), } impl TypeKind { diff --git a/src/parser/parse_type.rs b/src/parser/parse_type.rs index ff50fae..b6e7846 100644 --- a/src/parser/parse_type.rs +++ b/src/parser/parse_type.rs @@ -20,14 +20,18 @@ impl<'a, I: Inflow> Parser<'a, I> { let token = self.input.peek().clone(); let Ok(name) = self.parse_name(None::<&str>) else { - return Err(ParseError { - kind: ParseErrorKind::ExpectedType { - prefix: prefix.map(|prefix| prefix.to_string()), - for_reason: for_reason.map(|for_reason| for_reason.to_string()), - got: token.to_string(), - }, - source, - }); + if !token.kind.is_polymorph() { + return Err(ParseError { + kind: ParseErrorKind::ExpectedType { + prefix: prefix.map(|prefix| prefix.to_string()), + for_reason: for_reason.map(|for_reason| for_reason.to_string()), + got: token.to_string(), + }, + source, + }); + } + + return Ok(TypeKind::Polymorph(token.kind.unwrap_polymorph()).at(source)); }; let generics = self.parse_generics()?; diff --git a/src/resolve/mod.rs b/src/resolve/mod.rs index 3c48891..15a1f61 100644 --- a/src/resolve/mod.rs +++ b/src/resolve/mod.rs @@ -647,6 +647,10 @@ impl<'a> ResolveTypeCtx<'a> { }, )) } + ast::TypeKind::Polymorph(polymorph) => Err(ResolveErrorKind::Other { + message: format!("Unresolved polymorphic type '${}'", polymorph), + } + .at(ast_type.source)), } .map(|kind| kind.at(ast_type.source)) }