Flexible types.

This commit is contained in:
2026-11-15 12:34:33 +01:00
parent ef1a527ef8
commit 81cdf9a8dc
2 changed files with 14 additions and 14 deletions
+3 -3
View File
@@ -126,7 +126,7 @@ pub struct Ident {
}
#[derive(Debug, PartialEq)]
pub enum Type {
Number,
String,
pub struct Type {
pub name: String,
pub span: Span,
}
+11 -11
View File
@@ -134,15 +134,9 @@ where
};
self.next_expected(Token::Colon)?;
let param_type_token = self.next_expected(Token::Ident)?;
let param_type = match self.slice(*param_type_token.span())? {
"Number" => Type::Number,
"String" => Type::String,
other => {
return Err(ParseError {
span: *param_type_token.span(),
message: format!("Unknown type: {}", other),
});
}
let param_type = Type {
name: self.slice(*param_type_token.span())?.to_string(),
span: *param_type_token.span(),
};
params.push(FnParam {
name: param_name,
@@ -532,7 +526,10 @@ mod tests {
name: "p1".to_string(),
span: Span::new(7, 9),
},
ty: Type::Number,
ty: Type {
name: "Number".to_string(),
span: Span::new(11, 17),
},
span: Span::new(7, 17),
},
FnParam {
@@ -540,7 +537,10 @@ mod tests {
name: "p2".to_string(),
span: Span::new(19, 21),
},
ty: Type::String,
ty: Type {
name: "String".to_string(),
span: Span::new(23, 29),
},
span: Span::new(19, 29),
},
],