Improved match statements
This commit is contained in:
@@ -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 => {
|
LogLevel::Error => write!(f, "[ERROR]");
|
||||||
return write!(f, "[ERROR]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
@@ -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<_>>>(),
|
||||||
|
|||||||
Reference in New Issue
Block a user