gaming
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use crate::io::{CompilerMsg, Span, Spanned};
|
||||
|
||||
mod lit;
|
||||
@@ -35,8 +37,8 @@ impl<'a> Cursor<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn next_if(&mut self, token: &Token) -> bool {
|
||||
if self.peek().is_some_and(|t| t == token) {
|
||||
pub fn next_if(&mut self, token: impl Borrow<Token>) -> bool {
|
||||
if self.peek().is_some_and(|t| t == token.borrow()) {
|
||||
self.next();
|
||||
true
|
||||
} else {
|
||||
@@ -52,11 +54,6 @@ impl<'a> Cursor<'a> {
|
||||
self.next().ok_or_else(CompilerMsg::unexpected_eof)
|
||||
}
|
||||
|
||||
pub fn expect_peek(&self) -> Result<&Token, CompilerMsg> {
|
||||
self.peek().ok_or_else(CompilerMsg::unexpected_eof)
|
||||
// Ok(self.peek().unwrap())
|
||||
}
|
||||
|
||||
pub fn expect(&mut self, token: Token) -> Result<Token, CompilerMsg> {
|
||||
let next = self.expect_next()?;
|
||||
if next == token {
|
||||
@@ -87,7 +84,7 @@ impl CompilerMsg {
|
||||
pub fn unexpected_token(token: &Token, span: Span, expected: &str) -> Self {
|
||||
Self {
|
||||
spans: vec![span],
|
||||
msg: format!("Unexpected token '{}'; expected {expected}", token),
|
||||
msg: format!("Unexpected token '{}', expected {expected}", token),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user