Update: Closures #64

This commit is contained in:
2026-06-05 18:51:55 +02:00
parent 765e2ded93
commit a9eb77f158
2 changed files with 6 additions and 3 deletions
+4 -1
View File
@@ -453,7 +453,10 @@ match_stmt = {
// CLOSURES // CLOSURES
// ------------------------------------------------------ // ------------------------------------------------------
closure = { type_expr? ~ "fn" ~ "(" ~ param_list ~ ")" ~ expr } closure = {
"fn" ~ "(" ~ param_list ~ ")" ~ type_expr? ~ block
| "fn" ~ "(" ~ param_list ~ ")" ~ type_expr? ~ "->" ~ expr
}
// ------------------------------------------------------ // ------------------------------------------------------
// TUPLES & ARRAYS // TUPLES & ARRAYS
+2 -2
View File
@@ -77,10 +77,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
Rule::closure => { Rule::closure => {
ast_expr!(Expression::Closure { ast_expr!(Expression::Closure {
params: collect_recovered(inner.next().unwrap().into_inner()),
return_type: consume_rule(&mut inner, Rule::type_expr) return_type: consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from) .map(TypeExpr::try_from)
.transpose(), .transpose(),
params: collect_recovered(inner.next().unwrap().into_inner()),
body: Expression::try_from(inner.next().unwrap()).map(Box::new), body: Expression::try_from(inner.next().unwrap()).map(Box::new),
}) })
} }
@@ -109,7 +109,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
)), )),
} }
} }
Rule::statement | Rule::basic_stmt | Rule::control_flow => ast_expr!( Rule::statement | Rule::basic_stmt | Rule::control_flow | Rule::block => ast_expr!(
Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new)) Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new))
), ),