forked from AbleScript/ablescript
Invalid Token error + fixed forgotten refactor
This commit is contained in:
parent
5c0889a0ae
commit
2c04ebbadc
|
@ -12,6 +12,9 @@ pub enum ErrorKind {
|
|||
/// Parser expected token, but none was available
|
||||
UnexpectedEoi,
|
||||
|
||||
/// Parser encountered unknown token
|
||||
InvalidToken,
|
||||
|
||||
/// Parser expected certain token, but other one appeared
|
||||
UnexpectedToken(Token),
|
||||
|
||||
|
@ -65,6 +68,7 @@ impl Display for ErrorKind {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ErrorKind::UnexpectedEoi => write!(f, "unexpected end of input"),
|
||||
ErrorKind::InvalidToken => write!(f, "invalid token"),
|
||||
ErrorKind::UnexpectedToken(Token::Melo) => write!(f, "unexpected marten"),
|
||||
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
|
||||
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),
|
||||
|
|
|
@ -34,6 +34,9 @@ impl<'source> Parser<'source> {
|
|||
// Ignore comments
|
||||
Token::Comment => continue,
|
||||
|
||||
// Invalid token
|
||||
Token::Error => return Err(Error::new(ErrorKind::InvalidToken, self.lexer.span())),
|
||||
|
||||
// T-Dark block (replace `lang` with `script`)
|
||||
Token::TDark => ast.extend(self.tdark_flow()?),
|
||||
token => ast.push(self.parse_stmt(token)?),
|
||||
|
@ -53,6 +56,7 @@ impl<'source> Parser<'source> {
|
|||
.ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?
|
||||
{
|
||||
Token::Comment => (),
|
||||
Token::Error => break Err(Error::new(ErrorKind::InvalidToken, self.lexer.span())),
|
||||
token => break Ok(token),
|
||||
}
|
||||
}
|
||||
|
@ -256,10 +260,7 @@ impl<'source> Parser<'source> {
|
|||
.ok_or_else(|| Error::new(ErrorKind::MissingLhs, self.lexer.span()))?,
|
||||
),
|
||||
rhs: {
|
||||
let next = self
|
||||
.lexer
|
||||
.next()
|
||||
.ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?;
|
||||
let next = self.checked_next()?;
|
||||
Box::new(self.parse_expr(next, &mut None)?)
|
||||
},
|
||||
kind,
|
||||
|
|
Loading…
Reference in a new issue