This commit is contained in:
2026-05-24 12:29:42 +02:00
parent fde41b9a22
commit 1c2cc94cb9
5 changed files with 56 additions and 15 deletions
+1
View File
@@ -62,6 +62,7 @@ pub enum Prefix {
New(Option<Generics>),
Not,
Neg,
Closure(Option<TypeExpr>, Vec<VarDecl>),
}
#[derive(Debug, Clone, Serialize)]
+8 -1
View File
@@ -436,6 +436,12 @@ match_stmt = {
// EXPRESSIONS
// ======================================================
// ------------------------------------------------------
// CLOSURES
// ------------------------------------------------------
closure = { type_expr? ~ "|" ~ param_list ~ "|" }
// ------------------------------------------------------
// TUPLES & ARRAYS
// ------------------------------------------------------
@@ -549,7 +555,8 @@ not_px = { "!" }
neg_px = { "-" }
prefix = {
deref_px
closure
| deref_px
| mut_ref_px
| ref_px
| new_px
+11
View File
@@ -3,6 +3,7 @@ use crate::{
ast::*,
ast_ensure, ast_expr,
error::{AstError, AstResult, GetLength, IntoErr, collect_recovered, collect_recovered_map},
parser::consume_rule,
};
use pest::pratt_parser::PrattParser;
use std::sync::OnceLock;
@@ -104,6 +105,16 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Prefix {
),
Rule::not_px => Self::Not,
Rule::neg_px => Self::Neg,
Rule::closure => {
let mut inner = pair.into_inner();
return ast_expr!(Self::Closure(
consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from)
.transpose(),
collect_recovered(inner.next().unwrap().into_inner())
));
}
_ => return AstError::bug_unimplemented(pair),
})