Skip to content

Commit ced0d3f

Browse files
authored
parser: fix select select causing a panic (#499)
1 parent da00abe commit ced0d3f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4211,7 +4211,7 @@ fn opt_as_col_label(p: &mut Parser<'_>) -> bool {
42114211
}
42124212

42134213
fn opt_target_list(p: &mut Parser) -> Option<CompletedMarker> {
4214-
if !p.at_ts(TARGET_LIST_START) {
4214+
if !p.at_ts(TARGET_LIST_START) || p.at(SELECT_KW) {
42154215
return None;
42164216
}
42174217
let m = p.start();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ select 1 in c;
2525
-- type cast must use a string literal
2626
select numeric 1234;
2727

28+
-- regression test: this would cause the parser to get stuck & panic, now it
29+
-- warns about a missing semicolon
30+
select select;
31+
2832
-- trailing comma at EOF
2933
select 1,

crates/squawk_parser/tests/snapshots/tests__select_err.snap

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/squawk_parser/tests/tests.rs
33
input_file: crates/squawk_parser/tests/data/err/select.sql
4-
snapshot_kind: text
54
---
65
SOURCE_FILE
76
COMMENT "--- via https://duckdb.org/docs/stable/sql/dialect/friendly_sql.html#trailing-commas"
@@ -209,6 +208,19 @@ SOURCE_FILE
209208
INT_NUMBER "1234"
210209
SEMICOLON ";"
211210
WHITESPACE "\n\n"
211+
COMMENT "-- regression test: this would cause the parser to get stuck & panic, now it"
212+
WHITESPACE "\n"
213+
COMMENT "-- warns about a missing semicolon"
214+
WHITESPACE "\n"
215+
SELECT
216+
SELECT_CLAUSE
217+
SELECT_KW "select"
218+
WHITESPACE " "
219+
SELECT
220+
SELECT_CLAUSE
221+
SELECT_KW "select"
222+
SEMICOLON ";"
223+
WHITESPACE "\n\n"
212224
COMMENT "-- trailing comma at EOF"
213225
WHITESPACE "\n"
214226
SELECT
@@ -233,4 +245,5 @@ ERROR@395: expected expression
233245
ERROR@396: expected expression
234246
ERROR@397: expected expression
235247
ERROR@520: missing comma
236-
ERROR@561: unexpected trailing comma
248+
ERROR@646: expected SEMICOLON
249+
ERROR@689: unexpected trailing comma

0 commit comments

Comments
 (0)