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 {
fmt::Result fmt(self*, Formatter<'_> mut* f) {
match (self) {
LogLevel::Info => {
return write!(f, "[INFO]");
}
return match (self) {
LogLevel::Info => write!(f, "[INFO]");
LogLevel::Warning => {
return write!(f, "[WARN]");
}
LogLevel::Warning => 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,
body: Box<Statement>,
},
Match(Expression, Vec<(Vec<Pattern>, Block)>),
Match(Expression, Vec<(Vec<Pattern>, Expression)>),
Return(Option<Expression>),
Break,
+1 -1
View File
@@ -419,7 +419,7 @@ for_stmt = {
pattern_list = { pattern ~ ("|" ~ pattern)* }
match_item = {
pattern_list ~ "=>" ~ block
pattern_list ~ "=>" ~ statement
}
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();
Ok((
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<_>>>(),