Skip to content

Commit

Permalink
Added ability to parse polymorphic types
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Oct 24, 2024
1 parent e56432a commit dcb5b7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/ast/datatype/kind/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl Display for &TypeKind {
TypeKind::FunctionPointer(_function) => {
write!(f, "(function pointer type)")?;
}
TypeKind::Polymorph(polymorph) => {
write!(f, "${}", polymorph)?;
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/ast/datatype/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum TypeKind {
AnonymousUnion(AnoymousUnion),
AnonymousEnum(AnonymousEnum),
FunctionPointer(FunctionPointer),
Polymorph(String),
}

impl TypeKind {
Expand Down
20 changes: 12 additions & 8 deletions src/parser/parse_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ impl<'a, I: Inflow<Token>> 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()?;
Expand Down
4 changes: 4 additions & 0 deletions src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit dcb5b7f

Please sign in to comment.