mirror of
https://github.com/danog/parser.git
synced 2025-01-22 04:51:13 +01:00
lexer: use Err type for unrecognised tokens instead of unimplemented
This commit is contained in:
parent
ae2f617700
commit
010fe7be26
@ -16,6 +16,7 @@ pub enum SyntaxError {
|
||||
UnpredictableState(Span),
|
||||
InvalidDocIndentation(Span),
|
||||
InvalidDocBodyIndentationLevel(usize, Span),
|
||||
UnrecognisedToken(u8, Span),
|
||||
}
|
||||
|
||||
impl Display for SyntaxError {
|
||||
@ -72,6 +73,13 @@ impl Display for SyntaxError {
|
||||
expected,
|
||||
span.0
|
||||
),
|
||||
Self::UnrecognisedToken(token, span) => write!(
|
||||
f,
|
||||
"Syntax Error: Unrecognised token {} on line {} column {}",
|
||||
token,
|
||||
span.0,
|
||||
span.1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1126,12 +1126,7 @@ impl Lexer {
|
||||
let label = self.consume_identifier(state);
|
||||
TokenKind::Identifier(label.into())
|
||||
}
|
||||
&[b, ..] => unimplemented!(
|
||||
"<var offset> char: {}, line: {}, col: {}",
|
||||
b as char,
|
||||
state.span.0,
|
||||
state.span.1
|
||||
),
|
||||
&[b, ..] => return Err(SyntaxError::UnrecognisedToken(b, state.span)),
|
||||
[] => return Err(SyntaxError::UnexpectedEndOfFile(state.span)),
|
||||
};
|
||||
Ok(Token { kind, span })
|
||||
|
Loading…
x
Reference in New Issue
Block a user