Flexible types.
This commit is contained in:
+3
-3
@@ -126,7 +126,7 @@ pub struct Ident {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Type {
|
||||
Number,
|
||||
String,
|
||||
pub struct Type {
|
||||
pub name: String,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
+10
-10
@@ -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 {
|
||||
let param_type = Type {
|
||||
name: self.slice(*param_type_token.span())?.to_string(),
|
||||
span: *param_type_token.span(),
|
||||
message: format!("Unknown type: {}", other),
|
||||
});
|
||||
}
|
||||
};
|
||||
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),
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user