From 00eae58f256c6c7a09e9c9b72ac9fee5a98a17db Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 4 Aug 2023 17:29:44 +0800 Subject: [PATCH] Fix lexing of block comments --- crates/syntax/src/lexer.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/syntax/src/lexer.rs b/crates/syntax/src/lexer.rs index c5862bf..85802f1 100644 --- a/crates/syntax/src/lexer.rs +++ b/crates/syntax/src/lexer.rs @@ -90,7 +90,7 @@ regex_dfa! { DEFAULT_TOKEN_DFA { // The order matters! SPACE = r"[ \r\n\t]+", - COMMENT = r"#.*|/\*([^*]|\*[^/])*\*/", + COMMENT = r"#.*|/\*([^*]|\*+[^/*])*\*+/", // N.B. Nix somehow accepts multiple slashes in path interpolation except the first // slash, but the first path fragment accepts at most 2 continuous slashes. // @@ -623,4 +623,35 @@ mod tests { "#]], ); } + + #[test] + fn comment() { + check_lex( + "/*1/*2*/3*/4", + expect![[r#" + COMMENT "/*1/*2*/" + INT "3" + STAR "*" + PATH "/4" + "#]], + ); + check_lex( + "1/**/2", + expect![[r#" + INT "1" + COMMENT "/**/" + INT "2" + "#]], + ); + check_lex( + "1/*/2/**/3/***/4", + expect![[r#" + INT "1" + COMMENT "/*/2/**/" + INT "3" + COMMENT "/***/" + INT "4" + "#]], + ); + } }