From e09c7926e5497acae5514c06f7b5e20266a0c9a2 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Thu, 28 May 2026 11:34:14 +0200 Subject: [PATCH] Updated pattern ast --- crates/parser/src/ast/expr.rs | 2 +- crates/parser/src/grammar.pest | 2 +- crates/parser/src/parser/common/mod.rs | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/parser/src/ast/expr.rs b/crates/parser/src/ast/expr.rs index 1c6eb6b..a1fc4ad 100644 --- a/crates/parser/src/ast/expr.rs +++ b/crates/parser/src/ast/expr.rs @@ -36,7 +36,7 @@ pub enum Pattern { Struct(Path, Vec), Tuple(Vec), Literal(Literal), - Path(Path), + Path(bool, Path), Id(Identifier), } diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 9755861..476234a 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -135,7 +135,7 @@ literal = { // ====================================================== multi_pat_template = _{ - "[" ~ (identifier ~ ("," ~ identifier)*)? ~ "]" + (identifier ~ ("," ~ identifier)*)? } tuple_pattern = { diff --git a/crates/parser/src/parser/common/mod.rs b/crates/parser/src/parser/common/mod.rs index 206e3c9..3057472 100644 --- a/crates/parser/src/parser/common/mod.rs +++ b/crates/parser/src/parser/common/mod.rs @@ -7,8 +7,8 @@ use crate::{ Rule, ast::*, ast_ensure, ast_expr, - error::{AstError, IntoErr, collect_recovered}, - parser::consume_rule, + error::{AstError, AstResult, IntoErr, collect_recovered}, + parser::{consume_rule, listen_rule}, }; impl<'a> TryFrom> for Identifier { @@ -76,7 +76,10 @@ impl<'a> TryFrom> for Pattern { Rule::identifier => ast_expr!(Pattern::Id(pair.try_into())), - Rule::static_path => ast_expr!(Pattern::Path(pair.try_into())), + Rule::path_pattern => ast_expr!(Pattern::Path( + Ok(listen_rule(&mut inner, Rule::mutable)) as AstResult<'_, bool>, + inner.next().unwrap().try_into() + )), _ => AstError::bug_unimplemented(pair), }