Skip to content

Commit 31fe7a5

Browse files
authored
parser: improve error recovery for CTE (#683)
1 parent acac963 commit 31fe7a5

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,11 @@ fn with_query_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
25112511
break;
25122512
}
25132513
if !p.eat(COMMA) {
2514-
break;
2514+
if p.at(IDENT) {
2515+
p.error("missing comma");
2516+
} else {
2517+
break;
2518+
}
25152519
}
25162520
}
25172521
Some(m.complete(p, WITH_CLAUSE))

crates/squawk_parser/tests/data/err/select_cte.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ select * from t order by ordercol;
1212
with t as (select 1)
1313
search depth first by a, b c set ordercol
1414
select * from t order by ordercol;
15+
16+
with
17+
a as (
18+
select 1
19+
) -- <-- missing a comma
20+
b as (
21+
select 3
22+
)
23+
select 2;

crates/squawk_parser/tests/snapshots/tests__select_cte_err.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,62 @@ SOURCE_FILE
184184
NAME_REF
185185
IDENT "ordercol"
186186
SEMICOLON ";"
187+
WHITESPACE "\n\n"
188+
SELECT
189+
WITH_CLAUSE
190+
WITH_KW "with"
191+
WHITESPACE " \n "
192+
WITH_TABLE
193+
NAME
194+
IDENT "a"
195+
WHITESPACE " "
196+
AS_KW "as"
197+
WHITESPACE " "
198+
L_PAREN "("
199+
WHITESPACE "\n "
200+
SELECT
201+
SELECT_CLAUSE
202+
SELECT_KW "select"
203+
WHITESPACE " "
204+
TARGET_LIST
205+
TARGET
206+
LITERAL
207+
INT_NUMBER "1"
208+
WHITESPACE "\n "
209+
R_PAREN ")"
210+
WHITESPACE " "
211+
COMMENT "-- <-- missing a comma"
212+
WHITESPACE "\n "
213+
WITH_TABLE
214+
NAME
215+
IDENT "b"
216+
WHITESPACE " "
217+
AS_KW "as"
218+
WHITESPACE " "
219+
L_PAREN "("
220+
WHITESPACE "\n "
221+
SELECT
222+
SELECT_CLAUSE
223+
SELECT_KW "select"
224+
WHITESPACE " "
225+
TARGET_LIST
226+
TARGET
227+
LITERAL
228+
INT_NUMBER "3"
229+
WHITESPACE "\n "
230+
R_PAREN ")"
231+
WHITESPACE "\n"
232+
SELECT_CLAUSE
233+
SELECT_KW "select"
234+
WHITESPACE " "
235+
TARGET_LIST
236+
TARGET
237+
LITERAL
238+
INT_NUMBER "2"
239+
SEMICOLON ";"
187240
WHITESPACE "\n"
188241
---
189242
ERROR@24: unexpected comma
190243
ERROR@140: unexpected comma, expected a column name
191244
ERROR@270: expected COMMA
245+
ERROR@357: missing comma

0 commit comments

Comments
 (0)