From ccd45241061be149687aec04db43dec96d8a961d Mon Sep 17 00:00:00 2001 From: Yip Coekjan <69834864+Coekjan@users.noreply.github.com> Date: Fri, 16 Aug 2024 03:53:15 +0800 Subject: [PATCH] Fix lexer on sth followed by comments (#4739) --- crates/typst-syntax/src/lexer.rs | 5 ++++- tests/suite/syntax/comment.typ | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs index 92e78b2d0..721225c6e 100644 --- a/crates/typst-syntax/src/lexer.rs +++ b/crates/typst-syntax/src/lexer.rs @@ -503,7 +503,10 @@ impl Lexer<'_> { } fn space_or_end(&self) -> bool { - self.s.done() || self.s.at(char::is_whitespace) + self.s.done() + || self.s.at(char::is_whitespace) + || self.s.at("//") + || self.s.at("/*") } } diff --git a/tests/suite/syntax/comment.typ b/tests/suite/syntax/comment.typ index 5e7e0ee69..88802fe97 100644 --- a/tests/suite/syntax/comment.typ +++ b/tests/suite/syntax/comment.typ @@ -34,6 +34,41 @@ Second part First part // Second part +--- issue-4632-sth-followed-by-comment --- +// Test heading markers followed by comments. +#test([ + =// Comment + =/* Comment */ +], [ + = + = +]) + +// Test list markers followed by comments. +#test([ + -// Comment + -/* Comment */ +], [ + - + - +]) + +// Test enum markers followed by comments. +#test([ + +// Comment + +/* Comment */ + + 1.// Comment + 2./* Comment */ +], [ + + + + + + 1. + 2. +]) + + --- comment-block-unclosed --- // End should not appear without start. // Error: 7-9 unexpected end of block comment