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
|
/// Parser expected token, but none was available
|
||||||
UnexpectedEoi,
|
UnexpectedEoi,
|
||||||
|
|
||||||
|
/// Parser encountered unknown token
|
||||||
|
InvalidToken,
|
||||||
|
|
||||||
/// Parser expected certain token, but other one appeared
|
/// Parser expected certain token, but other one appeared
|
||||||
UnexpectedToken(Token),
|
UnexpectedToken(Token),
|
||||||
|
|
||||||
|
@ -65,6 +68,7 @@ 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::UnexpectedEoi => write!(f, "unexpected end of input"),
|
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::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),
|
||||||
|
|
|
@ -34,6 +34,9 @@ impl<'source> Parser<'source> {
|
||||||
// Ignore comments
|
// Ignore comments
|
||||||
Token::Comment => continue,
|
Token::Comment => continue,
|
||||||
|
|
||||||
|
// Invalid token
|
||||||
|
Token::Error => return Err(Error::new(ErrorKind::InvalidToken, self.lexer.span())),
|
||||||
|
|
||||||
// T-Dark block (replace `lang` with `script`)
|
// T-Dark block (replace `lang` with `script`)
|
||||||
Token::TDark => ast.extend(self.tdark_flow()?),
|
Token::TDark => ast.extend(self.tdark_flow()?),
|
||||||
token => ast.push(self.parse_stmt(token)?),
|
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))?
|
.ok_or_else(|| Error::unexpected_eoi(self.lexer.span().start))?
|
||||||
{
|
{
|
||||||
Token::Comment => (),
|
Token::Comment => (),
|
||||||
|
Token::Error => break Err(Error::new(ErrorKind::InvalidToken, self.lexer.span())),
|
||||||
token => break Ok(token),
|
token => break Ok(token),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,10 +260,7 @@ impl<'source> Parser<'source> {
|
||||||
.ok_or_else(|| Error::new(ErrorKind::MissingLhs, self.lexer.span()))?,
|
.ok_or_else(|| Error::new(ErrorKind::MissingLhs, self.lexer.span()))?,
|
||||||
),
|
),
|
||||||
rhs: {
|
rhs: {
|
||||||
let next = self
|
let next = self.checked_next()?;
|
||||||
.lexer
|
|
||||||
.next()
|
|
||||||
.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,
|
||||||
|
|
Loading…
Reference in a new issue