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
1 change: 1 addition & 0 deletions crates/squawk_linter/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub fn possibly_slow_stmt(stmt: &ast::Stmt) -> bool {
| ast::Stmt::Delete(_)
| ast::Stmt::Discard(_)
| ast::Stmt::Do(_)
| ast::Stmt::EmptyStmt(_)
| ast::Stmt::Execute(_)
| ast::Stmt::Explain(_)
| ast::Stmt::Fetch(_)
Expand Down
1 change: 1 addition & 0 deletions crates/squawk_parser/src/generated/syntax_kind.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5677,6 +5677,7 @@ struct StmtRestrictions {

fn stmt(p: &mut Parser, r: &StmtRestrictions) -> Option<CompletedMarker> {
match (p.current(), p.nth(1)) {
(SEMICOLON, _) => Some(empty_stmt(p)),
(ABORT_KW, _) => Some(rollback(p)),
(ALTER_KW, AGGREGATE_KW) => Some(alter_aggregate(p)),
(ALTER_KW, COLLATION_KW) => Some(alter_collation(p)),
Expand Down Expand Up @@ -5959,6 +5960,14 @@ fn stmt(p: &mut Parser, r: &StmtRestrictions) -> Option<CompletedMarker> {
}
}

// handle things like: ;;;select 1
fn empty_stmt(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(SEMICOLON));
let m = p.start();
p.bump(SEMICOLON);
m.complete(p, EMPTY_STMT)
}

// ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
// ALTER STATISTICS name RENAME TO new_name
// ALTER STATISTICS name SET SCHEMA new_schema
Expand Down Expand Up @@ -15293,17 +15302,16 @@ fn set_data_type(p: &mut Parser<'_>) {
pub(crate) fn entry_point(p: &mut Parser) {
let m = p.start();
while !p.at(EOF) {
// handle things like: ;;;select 1
if p.eat(SEMICOLON) {
continue;
}
let parsed_stmt = stmt(
p,
&StmtRestrictions {
begin_end_allowed: true,
},
);
if !p.at(EOF) && parsed_stmt.is_some() {
if !p.at(EOF)
&& let Some(marker) = parsed_stmt
&& marker.kind() != EMPTY_STMT
{
p.expect(SEMICOLON);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ SOURCE_FILE
WHITESPACE " "
ERROR
BOOLEAN_KW "boolean"
SEMICOLON ";"
EMPTY_STMT
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- mismatch options"
WHITESPACE "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SOURCE_FILE
NAME_REF
IDENT "t"
SEMICOLON ";"
SEMICOLON ";"
EMPTY_STMT
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- full"
WHITESPACE "\n"
Expand Down
39 changes: 39 additions & 0 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ Truncate =
('restart' 'identity' | 'continue' 'identity')?
('cascade' | 'restrict')?

EmptyStmt =
';'

LikeOption =
('including' | 'excluding')
('comments'
Expand Down Expand Up @@ -3618,7 +3621,7 @@ Stmt =
| Vacuum
| Values
| ParenSelect
| ';'
| EmptyStmt


SourceFile =
Expand Down
Loading