Nest the loop inside a match arm

This commit is contained in:
Erin 2021-07-29 19:17:10 +02:00 committed by ondra05
parent 50be7ca556
commit 754ad496af

View file

@ -237,10 +237,9 @@ impl<'source> Parser<'source> {
let mut buf = None; let mut buf = None;
match self.checked_next()? { match self.checked_next()? {
Token::RightBracket => return Ok(ExprKind::Cart(cart)), Token::RightBracket => (),
t => buf = Some(self.parse_expr(t, &mut buf)?), t => {
} buf = Some(self.parse_expr(t, &mut buf)?);
'cart: loop { 'cart: loop {
let value = loop { let value = loop {
match self.checked_next()? { match self.checked_next()? {
@ -257,8 +256,9 @@ impl<'source> Parser<'source> {
Token::RightBracket => { Token::RightBracket => {
cart.push(( cart.push((
value, value,
buf.take() buf.take().ok_or_else(|| {
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?, Error::unexpected_eof(self.lexer.span().start)
})?,
)); ));
break 'cart; break 'cart;
@ -271,6 +271,8 @@ impl<'source> Parser<'source> {
cart.push((value, key)); cart.push((value, key));
} }
}
}
Ok(ExprKind::Cart(cart)) Ok(ExprKind::Cart(cart))
} }