Improved match statements

This commit is contained in:
2026-05-21 14:38:37 +02:00
parent 80ff10503a
commit 4112dcac3b
4 changed files with 8 additions and 13 deletions
+5 -10
View File
@@ -13,18 +13,13 @@ pub enum LogLevel {
impl fmt::Display for LogLevel { impl fmt::Display for LogLevel {
fmt::Result fmt(self*, Formatter<'_> mut* f) { fmt::Result fmt(self*, Formatter<'_> mut* f) {
match (self) { return match (self) {
LogLevel::Info => { LogLevel::Info => write!(f, "[INFO]");
return write!(f, "[INFO]");
}
LogLevel::Warning => { LogLevel::Warning => write!(f, "[WARN]");
return write!(f, "[WARN]");
} LogLevel::Error => write!(f, "[ERROR]");
LogLevel::Error => {
return write!(f, "[ERROR]");
}
} }
} }
} }
+1 -1
View File
@@ -30,7 +30,7 @@ pub enum Statement {
iterator: Expression, iterator: Expression,
body: Box<Statement>, body: Box<Statement>,
}, },
Match(Expression, Vec<(Vec<Pattern>, Block)>), Match(Expression, Vec<(Vec<Pattern>, Expression)>),
Return(Option<Expression>), Return(Option<Expression>),
Break, Break,
+1 -1
View File
@@ -419,7 +419,7 @@ for_stmt = {
pattern_list = { pattern ~ ("|" ~ pattern)* } pattern_list = { pattern ~ ("|" ~ pattern)* }
match_item = { match_item = {
pattern_list ~ "=>" ~ block pattern_list ~ "=>" ~ statement
} }
match_stmt = { match_stmt = {
+1 -1
View File
@@ -95,7 +95,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
let mut match_inner = match_itms.into_inner(); let mut match_inner = match_itms.into_inner();
Ok(( Ok((
collect_recovered(match_inner.next().unwrap().into_inner()).get()?, collect_recovered(match_inner.next().unwrap().into_inner()).get()?,
Block::try_from(match_inner.next().unwrap()).get()?, Expression::try_from(match_inner.next().unwrap()).get()?,
)) ))
}) })
.collect::<AstResult<'a, Vec<_>>>(), .collect::<AstResult<'a, Vec<_>>>(),