EOF -> EOI

trunk
ondra05 2022-07-02 00:22:40 +02:00
parent 17713e3197
commit 18c4791201
3 changed files with 11 additions and 11 deletions

View File

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

View File

@ -50,7 +50,7 @@ impl<'source> Parser<'source> {
match self
.lexer
.next()
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?
.ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?
{
Token::Comment => (),
token => break Ok(token),
@ -195,7 +195,7 @@ impl<'source> Parser<'source> {
cart.push((
value,
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)?),
}
}
.ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?;
.ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?;
cart.push((value, key));
}
@ -259,7 +259,7 @@ impl<'source> Parser<'source> {
let next = self
.lexer
.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)?)
},
kind,

View File

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