Skip to content

Commit ca0bb28

Browse files
committed
Fix failing to parse GO after a comment
1 parent 3db7fba commit ca0bb28

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
@@ -15254,6 +15254,12 @@ impl<'a> Parser<'a> {
1525415254
match prev_token.token {
1525515255
Token::Whitespace(ref w) => match w {
1525615256
Whitespace::Newline => break,
15257+
Whitespace::SingleLineComment { comment, prefix: _ } => {
15258+
if comment.ends_with('\n') {
15259+
break;
15260+
}
15261+
look_back_count += 1;
15262+
}
1525715263
_ => look_back_count += 1,
1525815264
},
1525915265
_ => {

tests/sqlparser_mssql.rs

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

2206+
let single_line_comment_preceding_go = "USE some_database; -- okay\nGO";
2207+
let stmts = ms()
2208+
.parse_sql_statements(single_line_comment_preceding_go)
2209+
.unwrap();
2210+
assert_eq!(stmts.len(), 2);
2211+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2212+
2213+
let multi_line_comment_preceding_go = "USE some_database; /* okay */\nGO";
2214+
let stmts = ms()
2215+
.parse_sql_statements(multi_line_comment_preceding_go)
2216+
.unwrap();
2217+
assert_eq!(stmts.len(), 2);
2218+
assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }));
2219+
22062220
let comment_following_go = "USE some_database;\nGO -- okay";
22072221
let stmts = ms().parse_sql_statements(comment_following_go).unwrap();
22082222
assert_eq!(stmts.len(), 2);

0 commit comments

Comments
 (0)