Skip to content

Commit c144e2f

Browse files
committed
Fix failing to parse GO after a comment
1 parent be9e785 commit c144e2f

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
@@ -16407,6 +16407,12 @@ impl<'a> Parser<'a> {
1640716407
match prev_token.token {
1640816408
Token::Whitespace(ref w) => match w {
1640916409
Whitespace::Newline => break,
16410+
Whitespace::SingleLineComment { comment, prefix: _ } => {
16411+
if comment.ends_with('\n') {
16412+
break;
16413+
}
16414+
look_back_count += 1;
16415+
}
1641016416
_ => look_back_count += 1,
1641116417
},
1641216418
_ => {

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)