Add associated function parsing partially
This commit is contained in:
parent
b03adf0ab6
commit
bee31f4b92
@ -236,6 +236,7 @@ pub enum TopLevelStatement {
|
|||||||
FunctionDefinition(FunctionDefinition),
|
FunctionDefinition(FunctionDefinition),
|
||||||
TypeDefinition(TypeDefinition),
|
TypeDefinition(TypeDefinition),
|
||||||
BinopDefinition(BinopDefinition),
|
BinopDefinition(BinopDefinition),
|
||||||
|
AssociatedFunction(Type, Vec<FunctionDefinition>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -874,7 +874,14 @@ impl Parse for TopLevelStatement {
|
|||||||
range,
|
range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Some(Token::Impl) => Stmt::BinopDefinition(stream.parse()?),
|
Some(Token::Impl) => match stream.peek2() {
|
||||||
|
Some(Token::Binop) => Stmt::BinopDefinition(stream.parse()?),
|
||||||
|
Some(_) => {
|
||||||
|
let AssociatedFunctionBlock(ty, functions) = stream.parse::<AssociatedFunctionBlock>()?;
|
||||||
|
Stmt::AssociatedFunction(ty, functions)
|
||||||
|
}
|
||||||
|
_ => Err(stream.expecting_err("binop or associated function block")?)?,
|
||||||
|
},
|
||||||
_ => Err(stream.expecting_err("import or fn")?)?,
|
_ => Err(stream.expecting_err("import or fn")?)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -917,3 +924,21 @@ impl Parse for BinopDefinition {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AssociatedFunctionBlock(Type, Vec<FunctionDefinition>);
|
||||||
|
|
||||||
|
impl Parse for AssociatedFunctionBlock {
|
||||||
|
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
|
||||||
|
stream.expect(Token::Impl)?;
|
||||||
|
let ty = stream.parse::<Type>()?;
|
||||||
|
stream.expect(Token::BraceOpen)?;
|
||||||
|
let mut functions = Vec::new();
|
||||||
|
while let Some(Token::FnKeyword) = stream.peek() {
|
||||||
|
functions.push(stream.parse()?);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.expect(Token::BraceClose)?;
|
||||||
|
Ok(AssociatedFunctionBlock(ty, functions))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -120,6 +120,7 @@ impl ast::Module {
|
|||||||
exported: false,
|
exported: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
AssociatedFunction(_, function_definition) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user