EOF -> EOI

This commit is contained in:
Erin 2022-07-02 00:22:40 +02:00 committed by ondra05
parent 9e6639851e
commit 51d8623f03
3 changed files with 11 additions and 11 deletions

View file

@ -9,7 +9,7 @@ pub struct Error {
#[derive(Debug)] #[derive(Debug)]
pub enum ErrorKind { pub enum ErrorKind {
UnexpectedEof, UnexpectedEoi,
UnexpectedToken(Token), UnexpectedToken(Token),
UnknownVariable(String), UnknownVariable(String),
MeloVariable(String), MeloVariable(String),
@ -25,10 +25,10 @@ impl Error {
Self { kind, span } Self { kind, span }
} }
/// Create an UnexpectedEof error, where the EOF occurs at the /// Create an UnexpectedEoi error, where the EOI occurs at the
/// given index in the file. /// given index in the input.
pub fn unexpected_eof(index: usize) -> Self { pub fn unexpected_eoi(index: usize) -> Self {
Self::new(ErrorKind::UnexpectedEof, index..index) Self::new(ErrorKind::UnexpectedEoi, index..index)
} }
} }
@ -46,7 +46,7 @@ impl std::error::Error for Error {}
impl Display for ErrorKind { impl Display for ErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"), ErrorKind::UnexpectedEoi => write!(f, "unexpected end of input"),
ErrorKind::UnexpectedToken(Token::Melo) => write!(f, "unexpected marten"), ErrorKind::UnexpectedToken(Token::Melo) => write!(f, "unexpected marten"),
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),

View file

@ -50,7 +50,7 @@ impl<'source> Parser<'source> {
match self match self
.lexer .lexer
.next() .next()
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))? .ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?
{ {
Token::Comment => (), Token::Comment => (),
token => break Ok(token), token => break Ok(token),
@ -195,7 +195,7 @@ impl<'source> Parser<'source> {
cart.push(( cart.push((
value, value,
buf.take().ok_or_else(|| { buf.take().ok_or_else(|| {
Error::unexpected_eof(self.lexer.span().start) Error::unexpected_eoi(self.lexer.span().start)
})?, })?,
)); ));
@ -205,7 +205,7 @@ impl<'source> Parser<'source> {
t => buf = Some(self.parse_expr(t, &mut buf)?), t => buf = Some(self.parse_expr(t, &mut buf)?),
} }
} }
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?; .ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?;
cart.push((value, key)); cart.push((value, key));
} }
@ -259,7 +259,7 @@ impl<'source> Parser<'source> {
let next = self let next = self
.lexer .lexer
.next() .next()
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?; .ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?;
Box::new(self.parse_expr(next, &mut None)?) Box::new(self.parse_expr(next, &mut None)?)
}, },
kind, kind,

View file

@ -31,7 +31,7 @@ pub fn repl(ast_print: bool) {
Err(ablescript::error::Error { Err(ablescript::error::Error {
// Treat "Unexpected EOF" errors as "we need // Treat "Unexpected EOF" errors as "we need
// more data". // more data".
kind: ablescript::error::ErrorKind::UnexpectedEof, kind: ablescript::error::ErrorKind::UnexpectedEoi,
.. ..
}) => Some(partial_data), }) => Some(partial_data),
Err(e) => { Err(e) => {