From 2f12f5ac53f531f8ddda80b89beecaf3c021910c Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 23 Jun 2026 17:41:49 +0200 Subject: [PATCH] Updated closure syntax --- crates/parser/src/grammar.pest | 12 ++++++------ crates/parser/src/parser/common/expr.rs | 2 +- mist-test/src/common/expr_test.mist | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index d4f09b7..c254af8 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -30,7 +30,6 @@ keyword = { | "false" | "dyn" | "loop" - | "fn" | "unsafe" | "override" } @@ -200,8 +199,8 @@ attributes = { // DECLARATION HELPERS // ====================================================== var_decl = { - ("let" ~ pattern) | - type_expr ~ (!tuple_pattern ~ pattern) + ("let" ~ pattern) + | type_expr ~ (!tuple_pattern ~ pattern) } field = { @@ -343,7 +342,8 @@ function_decl = { // ====================================================== top_level = { - mod_attribute | (attributes ~ (import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl)) + mod_attribute + | (attributes ~ (import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | declare_module | function_decl)) } // ====================================================== @@ -466,8 +466,8 @@ match_stmt = { // ------------------------------------------------------ closure = { - "fn" ~ "(" ~ param_list ~ ")" ~ type_expr? ~ block - | "fn" ~ "(" ~ param_list ~ ")" ~ type_expr? ~ "->" ~ expr + ("(" ~ param_list ~ ")" ~ "=>" ~ expr) + | (type_expr ~ "(" ~ param_list ~ ")" ~ "=>" ~ expr) } // ------------------------------------------------------ diff --git a/crates/parser/src/parser/common/expr.rs b/crates/parser/src/parser/common/expr.rs index 01ae58b..5f4afa6 100644 --- a/crates/parser/src/parser/common/expr.rs +++ b/crates/parser/src/parser/common/expr.rs @@ -77,10 +77,10 @@ impl<'a> TryFrom> for Expression { Rule::closure => { ast_expr!(Expression::Closure { - params: collect_recovered(inner.next().unwrap().into_inner()), return_type: consume_rule(&mut inner, Rule::type_expr) .map(TypeExpr::try_from) .transpose(), + params: collect_recovered(inner.next().unwrap().into_inner()), body: Expression::try_from(inner.next().unwrap()).map(Box::new), }) } diff --git a/mist-test/src/common/expr_test.mist b/mist-test/src/common/expr_test.mist index 888447b..c344a00 100644 --- a/mist-test/src/common/expr_test.mist +++ b/mist-test/src/common/expr_test.mist @@ -88,7 +88,7 @@ pub void test_as_cast() { } pub void test_closure() { - let add = fn(a, b) -> a + b; + let add = (a, b) => a + b; assert_eq!(add(2, 3), 5); }