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 0d497bccdd
commit 603a244b78

View file

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