Better error messages for unrecognized tokens.

This commit is contained in:
Stephen Chung 2020-06-14 19:13:11 +08:00
parent 0c6a939c66
commit f26c12b8ea

View File

@ -862,6 +862,14 @@ impl<'a> TokenIterator<'a> {
self.eat_next();
return Some((Token::MinusAssign, pos));
}
('-', '>') => {
return Some((
Token::LexError(Box::new(LERR::ImproperSymbol(
"'->' is not a valid symbol. This is not C or C++!".to_string(),
))),
pos,
))
}
('-', _) if self.can_be_unary => return Some((Token::UnaryMinus, pos)),
('-', _) => return Some((Token::Minus, pos)),
@ -931,7 +939,7 @@ impl<'a> TokenIterator<'a> {
// Warn against `===`
if self.peek_next() == Some('=') {
return Some((
Token::LexError(Box::new(LERR::ImproperKeyword(
Token::LexError(Box::new(LERR::ImproperSymbol(
"'===' is not a valid operator. This is not JavaScript! Should it be '=='?"
.to_string(),
))),
@ -941,18 +949,44 @@ impl<'a> TokenIterator<'a> {
return Some((Token::EqualsTo, pos));
}
('=', '>') => {
return Some((
Token::LexError(Box::new(LERR::ImproperSymbol(
"'=>' is not a valid symbol. This is not Rust! Should it be '>='?"
.to_string(),
))),
pos,
))
}
('=', _) => return Some((Token::Equals, pos)),
(':', ':') => {
self.eat_next();
return Some((Token::DoubleColon, pos));
}
(':', '=') => {
return Some((
Token::LexError(Box::new(LERR::ImproperSymbol(
"':=' is not a valid assignment operator. This is not Pascal! Should it be simply '='?"
.to_string(),
))),
pos,
))
}
(':', _) => return Some((Token::Colon, pos)),
('<', '=') => {
self.eat_next();
return Some((Token::LessThanEqualsTo, pos));
}
('<', '-') => {
return Some((
Token::LexError(Box::new(LERR::ImproperSymbol(
"'<-' is not a valid symbol. Should it be '<='?".to_string(),
))),
pos,
))
}
('<', '<') => {
self.eat_next();
@ -993,7 +1027,7 @@ impl<'a> TokenIterator<'a> {
// Warn against `!==`
if self.peek_next() == Some('=') {
return Some((
Token::LexError(Box::new(LERR::ImproperKeyword(
Token::LexError(Box::new(LERR::ImproperSymbol(
"'!==' is not a valid operator. This is not JavaScript! Should it be '!='?"
.to_string(),
))),