Skip to content

Commit 38768c0

Browse files
authored
Merge pull request #79 from supabase/fix/multiple-nested-statements
2 parents a92ba29 + 694f006 commit 38768c0

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

crates/parser/src/parse/statement.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ fn collect_statement_token_range(parser: &mut Parser, kind: SyntaxKind) -> Range
6969
// advance with all start tokens of statement
7070
advance_over_start_tokens(parser, kind);
7171

72-
let mut is_parsing_sub_stmt = false;
72+
let mut is_sub_stmt = 0;
7373
let mut ignore_next_non_whitespace = false;
7474
while !parser.at(SyntaxKind::Ascii59) && !parser.eof() {
7575
match parser.nth(0, false).kind {
7676
// opening brackets "(", consume until closing bracket ")"
7777
SyntaxKind::Ascii40 => {
78-
is_parsing_sub_stmt = true;
78+
is_sub_stmt += 1;
7979
parser.advance();
8080
}
8181
SyntaxKind::Ascii41 => {
82-
is_parsing_sub_stmt = false;
82+
is_sub_stmt -= 1;
8383
parser.advance();
8484
}
8585
SyntaxKind::As => {
@@ -91,7 +91,7 @@ fn collect_statement_token_range(parser: &mut Parser, kind: SyntaxKind) -> Range
9191
// if another stmt FIRST is encountered, break
9292
// ignore if parsing sub stmt
9393
if ignore_next_non_whitespace == false
94-
&& is_parsing_sub_stmt == false
94+
&& is_sub_stmt == 0
9595
&& is_at_stmt_start(parser).is_some()
9696
{
9797
break;

crates/parser/src/parser.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ mod tests {
342342
})
343343
}
344344

345+
#[test]
346+
fn test_nested_substatements() {
347+
init();
348+
349+
let input = "select is ((select true), true);\nselect isnt ((select false), true);";
350+
351+
let mut p = Parser::new(lex(input));
352+
source(&mut p);
353+
let result = p.finish();
354+
355+
dbg!(&result.cst);
356+
assert_eq!(result.stmts.len(), 2);
357+
println!("{:#?}", result.errors);
358+
}
359+
345360
#[test]
346361
fn test_parser_simple() {
347362
init();

0 commit comments

Comments
 (0)