Skip to content

Commit f010708

Browse files
committed
Fix failing to parse GO after a comment
1 parent 55722cf commit f010708

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/parser/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19666,6 +19666,12 @@ impl<'a> Parser<'a> {
1966619666
match prev_token.token {
1966719667
Token::Whitespace(ref w) => match w {
1966819668
Whitespace::Newline => break,
19669+
Whitespace::SingleLineComment { comment, prefix: _ } => {
19670+
if comment.ends_with('\n') {
19671+
break;
19672+
}
19673+
look_back_count += 1;
19674+
}
1966919675
_ => look_back_count += 1,
1967019676
},
1967119677
_ => {

tests/sqlparser_mssql.rs

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

2903+
let single_line_comment_preceding_go = "USE some_database; -- okay\nGO";
2904+
let stmts = ms()
2905+
.parse_sql_statements(single_line_comment_preceding_go)
2906+
.unwrap();
2907+
assert_eq!(stmts.len(), 2);
2908+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2909+
2910+
let multi_line_comment_preceding_go = "USE some_database; /* okay */\nGO";
2911+
let stmts = ms()
2912+
.parse_sql_statements(multi_line_comment_preceding_go)
2913+
.unwrap();
2914+
assert_eq!(stmts.len(), 2);
2915+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2916+
29032917
let comment_following_go = "USE some_database;\nGO -- okay";
29042918
let stmts = ms().parse_sql_statements(comment_following_go).unwrap();
29052919
assert_eq!(stmts.len(), 2);

0 commit comments

Comments
 (0)