Update: Function #65

This commit is contained in:
2026-06-05 18:07:47 +02:00
parent ac9ee5a4b6
commit d364c41c26
5 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ pub struct FunctionDecl {
pub name: Identifier,
pub generics: GenericsDecl,
pub params: ParamList,
pub return_type: TypeExpr,
pub return_type: Option<TypeExpr>,
pub body: Option<Block>,
}
+2 -2
View File
@@ -192,7 +192,7 @@ attributes = {
// DECLARATION HELPERS
// ======================================================
var_decl = {
"let" ~ WHITESPACE ~ pattern ~ type_expr?
"let" ~ pattern ~ type_expr?
}
field = {
@@ -323,7 +323,7 @@ trait_decl = {
// ======================================================
function_decl = {
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ (block | semicolon)
visibility? ~ "fn" ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ type_expr? ~ (block | semicolon)
}
// ======================================================
+4 -1
View File
@@ -13,7 +13,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
ast_ensure!(pair, Rule::function_decl => {
let mut inner = pair.into_inner();
let visibility = Visibility::try_from(&mut inner);
let return_type = TypeExpr::try_from(inner.next().unwrap());
let name = Identifier::try_from(inner.next().unwrap());
let generics = consume_rule(&mut inner, Rule::generics_decl)
@@ -51,6 +50,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
})
.unwrap_or_else(|| Ok(ParamList(self_param.into_iter().collect())));
let return_type = consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from)
.transpose();
let body = inner.next().map(Block::try_from).transpose();
ast_expr!(Self {