Skip to content

Commit 313080a

Browse files
zyuiopayman-sigma
authored andcommitted
Tokenize empty line comments correctly (apache#2161)
1 parent d01009a commit 313080a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/tokenizer.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,11 @@ impl<'a> Tokenizer<'a> {
14271427
Some('-') => {
14281428
let mut is_comment = true;
14291429
if self.dialect.requires_single_line_comment_whitespace() {
1430-
is_comment = Some(' ') == chars.peekable.clone().nth(1);
1430+
is_comment = chars
1431+
.peekable
1432+
.clone()
1433+
.nth(1)
1434+
.is_some_and(char::is_whitespace);
14311435
}
14321436

14331437
if is_comment {
@@ -4148,6 +4152,24 @@ mod tests {
41484152
Token::Minus,
41494153
],
41504154
);
4155+
4156+
all_dialects_where(|d| d.requires_single_line_comment_whitespace()).tokenizes_to(
4157+
"--\n-- Table structure for table...\n--\n",
4158+
vec![
4159+
Token::Whitespace(Whitespace::SingleLineComment {
4160+
prefix: "--".to_string(),
4161+
comment: "\n".to_string(),
4162+
}),
4163+
Token::Whitespace(Whitespace::SingleLineComment {
4164+
prefix: "--".to_string(),
4165+
comment: " Table structure for table...\n".to_string(),
4166+
}),
4167+
Token::Whitespace(Whitespace::SingleLineComment {
4168+
prefix: "--".to_string(),
4169+
comment: "\n".to_string(),
4170+
}),
4171+
],
4172+
);
41514173
}
41524174

41534175
#[test]

0 commit comments

Comments
 (0)