diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index d6e934c..a486537 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -401,7 +401,7 @@ control_flow = { | unsafe_block } -statement_branch = { expr ~ block } +statement_branch = { (expr_no_struct | ("(" ~ expr ~ ")")) ~ block } else_if = _{ "else" ~ "if" ~ statement_branch @@ -446,7 +446,7 @@ match_item = { } match_stmt = { - "match" ~ expr ~ "{" ~ match_item* ~ "}" + "match" ~ (expr_no_struct | "(" ~ expr ~ ")") ~ "{" ~ match_item* ~ "}" } // ====================================================== @@ -561,14 +561,13 @@ decrement = { "--" } -postfix = { +postfix_no_struct = _{ field_px | tuple_field_px | call_px | macro_call_paren | macro_call_bracket | macro_call_brace - | struct_px | index_px | as_px | try_px @@ -576,6 +575,11 @@ postfix = { | decrement } +postfix = { + postfix_no_struct + | struct_px +} + // ------------------------------------------------------ // PREFIX EXPRESSIONS // ------------------------------------------------------ @@ -640,3 +644,7 @@ bin_op = { expr = { term ~ (bin_op ~ term)* } term = { prefix* ~ primary ~ postfix* } + +expr_no_struct = { term_no_struct ~ (bin_op ~ term)* } + +term_no_struct = { prefix* ~ primary ~ postfix_no_struct* } diff --git a/crates/parser/src/parser/common/expr.rs b/crates/parser/src/parser/common/expr.rs index c6a67d1..01ae58b 100644 --- a/crates/parser/src/parser/common/expr.rs +++ b/crates/parser/src/parser/common/expr.rs @@ -16,7 +16,7 @@ impl<'a> TryFrom> for Expression { let mut inner = pair.clone().into_inner(); match rule { - Rule::expr => { + Rule::expr | Rule::expr_no_struct => { static PRATT_PARSER: OnceLock> = OnceLock::new(); let pratt = PRATT_PARSER.get_or_init(|| { use pest::pratt_parser::{Assoc::*, Op}; @@ -36,7 +36,7 @@ impl<'a> TryFrom> for Expression { .parse(inner) } - Rule::term => { + Rule::term | Rule::term_no_struct => { let mut prefix_pairs = Vec::new(); let mut primary_pair = None; let mut postfix_pairs = Vec::new();