diff --git a/src/lexer.rs b/src/lexer.rs index 0b30e10..02a4a1c 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -123,7 +123,7 @@ impl<'t> Lexer<'t> { ')' => RParen, '*' => Star, '+' => Plus, - ',' => Comma, + ',' => return self.consume().trailing(Comma), '-' => Minus, '.' => Dot, '/' => Slash, @@ -198,6 +198,15 @@ impl<'t> Lexer<'t> { Ok(self.consume().produce(tok)) } + pub fn trailing(&mut self, kind: TKind) -> Result { + Ok(match self.skip_whitespace().peek() { + // Some(')') => self.consume().produce(TKind::RParen), // maybe. + Some(']') => self.consume().produce(TKind::RBrack), + Some('}') => self.consume().produce(TKind::RCurly), + _ => self.produce(kind), + }) + } + pub fn line_comment(&mut self) -> Result { while self.consume().peek().is_some_and(|c| c != '\n') {} Ok(self.produce(TKind::Comment))