Patched if statements acting like structs

This commit is contained in:
2026-06-13 03:23:13 +02:00
parent 919447875a
commit 3196b2b652
2 changed files with 14 additions and 6 deletions
+12 -4
View File
@@ -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* }
+2 -2
View File
@@ -16,7 +16,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
let mut inner = pair.clone().into_inner();
match rule {
Rule::expr => {
Rule::expr | Rule::expr_no_struct => {
static PRATT_PARSER: OnceLock<PrattParser<Rule>> = OnceLock::new();
let pratt = PRATT_PARSER.get_or_init(|| {
use pest::pratt_parser::{Assoc::*, Op};
@@ -36,7 +36,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> 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();