Skip to content

Commit 06aa178

Browse files
committed
Fix failing to parse GO after a comment
1 parent c417dfd commit 06aa178

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
@@ -17366,6 +17366,12 @@ impl<'a> Parser<'a> {
1736617366
match prev_token.token {
1736717367
Token::Whitespace(ref w) => match w {
1736817368
Whitespace::Newline => break,
17369+
Whitespace::SingleLineComment { comment, prefix: _ } => {
17370+
if comment.ends_with('\n') {
17371+
break;
17372+
}
17373+
look_back_count += 1;
17374+
}
1736917375
_ => look_back_count += 1,
1737017376
},
1737117377
_ => {

tests/sqlparser_mssql.rs

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

2572+
let single_line_comment_preceding_go = "USE some_database; -- okay\nGO";
2573+
let stmts = ms()
2574+
.parse_sql_statements(single_line_comment_preceding_go)
2575+
.unwrap();
2576+
assert_eq!(stmts.len(), 2);
2577+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2578+
2579+
let multi_line_comment_preceding_go = "USE some_database; /* okay */\nGO";
2580+
let stmts = ms()
2581+
.parse_sql_statements(multi_line_comment_preceding_go)
2582+
.unwrap();
2583+
assert_eq!(stmts.len(), 2);
2584+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2585+
25722586
let comment_following_go = "USE some_database;\nGO -- okay";
25732587
let stmts = ms().parse_sql_statements(comment_following_go).unwrap();
25742588
assert_eq!(stmts.len(), 2);

0 commit comments

Comments
 (0)