lexer: produce correct token for single !

This commit is contained in:
Ryan Chandler 2022-11-30 00:31:06 +00:00
parent c372b9e9bd
commit e21b6a40ef
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
3 changed files with 3 additions and 7 deletions

View File

@ -187,7 +187,7 @@ impl Lexer {
} }
[b'!', ..] => { [b'!', ..] => {
self.next(); self.next();
TokenKind::BangEquals TokenKind::Bang
} }
[b'&', b'&', ..] => { [b'&', b'&', ..] => {
self.skip(2); self.skip(2);

View File

@ -210,6 +210,7 @@ impl Default for Token {
impl Display for TokenKind { impl Display for TokenKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self { let s = match self {
Self::BangEquals => "!=",
Self::From => "from", Self::From => "from",
Self::Print => "print", Self::Print => "print",
Self::BitwiseNot => "~", Self::BitwiseNot => "~",

View File

@ -2203,12 +2203,7 @@ impl Parser {
prefix(&op, rhs) prefix(&op, rhs)
} }
TokenKind::Dollar => self.dynamic_variable()?, TokenKind::Dollar => self.dynamic_variable()?,
_ => todo!( _ => return Err(ParseError::UnexpectedToken(self.current.kind.to_string(), self.current.span)),
"expr lhs: {:?}, line {} col {}",
self.current.kind,
self.current.span.0,
self.current.span.1
),
}; };
if self.current.kind == TokenKind::SemiColon { if self.current.kind == TokenKind::SemiColon {