Implement parsing of multiple parameters
This commit is contained in:
parent
575abe8172
commit
e8e2b4cebd
@ -349,16 +349,32 @@ impl Parse for FunctionDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct FunctionParam(String, Type);
|
||||||
|
|
||||||
|
impl Parse for FunctionParam {
|
||||||
|
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
|
||||||
|
let Some(Token::Identifier(arg_name)) = stream.next() else {
|
||||||
|
return Err(stream.expected_err("parameter name")?);
|
||||||
|
};
|
||||||
|
stream.expect(Token::Colon)?;
|
||||||
|
Ok(FunctionParam(arg_name, stream.parse()?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for FunctionSignature {
|
impl Parse for FunctionSignature {
|
||||||
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
|
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
|
||||||
if let Some(Token::Identifier(name)) = stream.next() {
|
if let Some(Token::Identifier(name)) = stream.next() {
|
||||||
stream.expect(Token::ParenOpen)?;
|
stream.expect(Token::ParenOpen)?;
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
|
|
||||||
while let Some(Token::Identifier(arg_name)) = stream.peek() {
|
if let Ok(param) = stream.parse::<FunctionParam>() {
|
||||||
|
args.push((param.0, param.1));
|
||||||
|
while let Some(Token::Comma) = stream.peek() {
|
||||||
stream.next();
|
stream.next();
|
||||||
stream.expect(Token::Colon)?;
|
let param = stream.parse::<FunctionParam>()?;
|
||||||
args.push((arg_name, stream.parse()?));
|
args.push((param.0, param.1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.expect(Token::ParenClose)?;
|
stream.expect(Token::ParenClose)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user