From a233bb18bccaf711cea152e65c212554fe6d20ea Mon Sep 17 00:00:00 2001 From: John Date: Sat, 27 Jul 2024 18:41:50 -0500 Subject: [PATCH] cl-lexer: Record the contents of comments --- compiler/cl-lexer/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/cl-lexer/src/lib.rs b/compiler/cl-lexer/src/lib.rs index 1c1d294..4ee8ec7 100644 --- a/compiler/cl-lexer/src/lib.rs +++ b/compiler/cl-lexer/src/lib.rs @@ -321,18 +321,21 @@ impl<'t> Lexer<'t> { /// Comments impl<'t> Lexer<'t> { fn line_comment(&mut self) -> LResult { + let mut comment = String::new(); while Ok('\n') != self.peek() { - self.consume()?; + comment.push(self.next()?); } - self.produce(Kind::Comment, ()) + self.produce(Kind::Comment, comment) } fn block_comment(&mut self) -> LResult { + let mut comment = String::new(); while let Ok(c) = self.next() { - if '*' == c && Ok('/') == self.next() { + if '*' == c && Ok('/') == self.peek() { break; } + comment.push(c); } - self.produce(Kind::Comment, ()) + self.consume()?.produce(Kind::Comment, comment) } } /// Identifiers