Skip to content

Commit

Permalink
Fix lexing of block comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Aug 4, 2023
1 parent 6f20ed4 commit 00eae58
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion crates/syntax/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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"
"#]],
);
}
}

0 comments on commit 00eae58

Please sign in to comment.