Skip to content

Commit 105bbd2

Browse files
committed
Fix failing to parse GO after a comment
1 parent dc04842 commit 105bbd2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/parser/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16501,6 +16501,12 @@ impl<'a> Parser<'a> {
1650116501
match prev_token.token {
1650216502
Token::Whitespace(ref w) => match w {
1650316503
Whitespace::Newline => break,
16504+
Whitespace::SingleLineComment { comment, prefix: _ } => {
16505+
if comment.ends_with('\n') {
16506+
break;
16507+
}
16508+
look_back_count += 1;
16509+
}
1650416510
_ => look_back_count += 1,
1650516511
},
1650616512
_ => {

tests/sqlparser_mssql.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,20 @@ fn parse_mssql_go_keyword() {
25532553
assert_eq!(stmts[1], Statement::Go(GoStatement { count: Some(5) }));
25542554
assert_eq!(stmts[3], Statement::Go(GoStatement { count: None }));
25552555

2556+
let single_line_comment_preceding_go = "USE some_database; -- okay\nGO";
2557+
let stmts = ms()
2558+
.parse_sql_statements(single_line_comment_preceding_go)
2559+
.unwrap();
2560+
assert_eq!(stmts.len(), 2);
2561+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2562+
2563+
let multi_line_comment_preceding_go = "USE some_database; /* okay */\nGO";
2564+
let stmts = ms()
2565+
.parse_sql_statements(multi_line_comment_preceding_go)
2566+
.unwrap();
2567+
assert_eq!(stmts.len(), 2);
2568+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2569+
25562570
let comment_following_go = "USE some_database;\nGO -- okay";
25572571
let stmts = ms().parse_sql_statements(comment_following_go).unwrap();
25582572
assert_eq!(stmts.len(), 2);

0 commit comments

Comments
 (0)