From 4b0f30f78e8b35c39b160380081a161f8cd03412 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 7 Oct 2025 05:42:44 -0400 Subject: [PATCH] lexer: Fun little lexer hack to allow trailing commas --- src/lexer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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))