From 86e1391ea21dfe26777bda208366d4aad9c89cb9 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 20 Mar 2022 02:20:55 +0100 Subject: [PATCH] Used checked next in require --- ablescript/src/parser.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 52a8577..59a8581 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -120,11 +120,10 @@ impl<'source> Parser<'source> { } /// Require next item to be equal with expected one - fn require(&mut self, expected: Token) -> Result<(), Error> { - match self.lexer.next() { - Some(t) if t == expected => Ok(()), - Some(t) => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())), - None => Err(Error::unexpected_eof(self.lexer.span().start)), + fn require(&mut self, required: Token) -> Result<(), Error> { + match self.checked_next()? { + t if t == required => Ok(()), + t => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())), } } @@ -176,7 +175,7 @@ impl<'source> Parser<'source> { })), start..self.lexer.span().end, )), - + Token::LeftBracket => match buf.take() { Some(buf) => Ok(Expr::new( self.index_flow(buf)?,