Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4510,6 +4510,8 @@ const TARGET_FOLLOW: TokenSet = TokenSet::new(&[
R_PAREN,
R_BRACK,
RETURNING_KW,
SEMICOLON,
EOF,
])
.union(COMPOUND_SELECT_FIRST);

Expand Down Expand Up @@ -4567,7 +4569,7 @@ fn opt_target_list(p: &mut Parser) -> Option<CompletedMarker> {
let m = p.start();
while !p.at(EOF) && !p.at(SEMICOLON) {
if opt_target_el(p).is_some() {
if p.at(COMMA) && matches!(p.nth(1), SEMICOLON | EOF) {
if p.at(COMMA) && p.nth_at_ts(1, TARGET_FOLLOW) {
p.err_and_bump("unexpected trailing comma");
break;
}
Expand All @@ -4584,6 +4586,8 @@ fn opt_target_list(p: &mut Parser) -> Option<CompletedMarker> {
break;
}
}
} else {
break;
}
}
Some(m.complete(p, TARGET_LIST))
Expand Down
3 changes: 3 additions & 0 deletions crates/squawk_parser/tests/data/err/select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ select numeric 1234;
-- warns about a missing semicolon
select select;

-- extra comma
select a, from t;

-- trailing comma at EOF
select 1,
24 changes: 23 additions & 1 deletion crates/squawk_parser/tests/snapshots/tests__select_err.snap
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ SOURCE_FILE
SELECT_KW "select"
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- extra comma"
WHITESPACE "\n"
SELECT
SELECT_CLAUSE
SELECT_KW "select"
WHITESPACE " "
TARGET_LIST
TARGET
NAME_REF
IDENT "a"
ERROR
COMMA ","
WHITESPACE " "
FROM_CLAUSE
FROM_KW "from"
WHITESPACE " "
FROM_ITEM
NAME_REF
IDENT "t"
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- trailing comma at EOF"
WHITESPACE "\n"
SELECT
Expand All @@ -248,4 +269,5 @@ ERROR@396: expected expression
ERROR@397: expected expression
ERROR@520: missing comma
ERROR@646: expected SEMICOLON
ERROR@689: unexpected trailing comma
ERROR@679: unexpected trailing comma
ERROR@723: unexpected trailing comma
Loading