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
18 changes: 12 additions & 6 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ fn bind_create_table(b: &mut Binder, create_table: impl ast::HasCreateTable) {
return;
};
let name_ptr = path_to_ptr(&path);
let is_temp = create_table.temp_token().is_some() || create_table.temporary_token().is_some();
let is_temp = create_table
.persistence()
.is_some_and(|p| matches!(p, ast::Persistence::Temp(_)));
let Some(schema) = schema_name(b, &path, is_temp) else {
return;
};
Expand Down Expand Up @@ -329,8 +331,9 @@ fn bind_create_table_as(b: &mut Binder, create_table_as: ast::CreateTableAs) {
return;
};
let name_ptr = path_to_ptr(&path);
let is_temp =
create_table_as.temp_token().is_some() || create_table_as.temporary_token().is_some();
let is_temp = create_table_as
.persistence()
.is_some_and(|p| matches!(p, ast::Persistence::Temp(_)));
let Some(schema) = schema_name(b, &path, is_temp) else {
return;
};
Expand Down Expand Up @@ -628,7 +631,9 @@ fn bind_create_view(b: &mut Binder, create_view: ast::CreateView) {
};

let name_ptr = path_to_ptr(&path);
let is_temp = create_view.temp_token().is_some() || create_view.temporary_token().is_some();
let is_temp = create_view
.persistence()
.is_some_and(|p| matches!(p, ast::Persistence::Temp(_)));

let Some(schema) = schema_name(b, &path, is_temp) else {
return;
Expand Down Expand Up @@ -684,8 +689,9 @@ fn bind_create_sequence(b: &mut Binder, create_sequence: ast::CreateSequence) {
};

let name_ptr = path_to_ptr(&path);
let is_temp =
create_sequence.temp_token().is_some() || create_sequence.temporary_token().is_some();
let is_temp = create_sequence
.persistence()
.is_some_and(|p| matches!(p, ast::Persistence::Temp(_)));

let Some(schema) = schema_name(b, &path, is_temp) else {
return;
Expand Down
5 changes: 3 additions & 2 deletions crates/squawk_linter/src/rules/prefer_robust_stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
ast::Stmt::CreateTable(create_table)
if create_table.if_not_exists().is_none() && !inside_transaction =>
{
let is_temp =
create_table.temp_token().is_some() || create_table.temporary_token().is_some();
let is_temp = create_table
.persistence()
.is_some_and(|p| matches!(p, ast::Persistence::Temp(_)));
let on_commit_drop = create_table
.on_commit()
.and_then(|oc| oc.on_commit_action())
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.

41 changes: 25 additions & 16 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ fn opt_into_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
if p.at(INTO_KW) {
let m = p.start();
p.bump(INTO_KW);
let _ = opt_temp(p) || p.eat(UNLOGGED_KW);
opt_persistence(p);
p.eat(TABLE_KW);
path_name(p);
Some(m.complete(p, INTO_CLAUSE))
Expand Down Expand Up @@ -5241,7 +5241,7 @@ fn create_table(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(CREATE_KW));
let m = p.start();
p.expect(CREATE_KW);
opt_temp_or_unlogged(p);
opt_persistence(p);
p.expect(TABLE_KW);
opt_if_not_exists(p);
path_name(p);
Expand Down Expand Up @@ -5290,18 +5290,27 @@ fn create_table(p: &mut Parser<'_>) -> CompletedMarker {
m.complete(p, CREATE_TABLE)
}

fn opt_temp_or_unlogged(p: &mut Parser<'_>) {
// [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ]
if !p.eat(UNLOGGED_KW) {
// [ GLOBAL | LOCAL ] { TEMPORARY | TEMP }
let require_temp = p.eat(GLOBAL_KW) || p.eat(LOCAL_KW);
if require_temp {
if !opt_temp(p) {
p.error("expected temp or temporary");
}
} else {
opt_temp(p);
// [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ]
fn opt_persistence(p: &mut Parser<'_>) -> bool {
let m = p.start();
if p.eat(UNLOGGED_KW) {
m.complete(p, UNLOGGED);
return true;
}
// [ GLOBAL | LOCAL ] { TEMPORARY | TEMP }
let require_temp = p.eat(GLOBAL_KW) || p.eat(LOCAL_KW);
if require_temp {
if !opt_temp(p) {
p.error("expected temp or temporary");
}
m.complete(p, TEMP);
true
} else if opt_temp(p) {
m.complete(p, TEMP);
true
} else {
m.abandon(p);
false
}
}

Expand Down Expand Up @@ -8454,7 +8463,7 @@ fn create_property_graph(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(CREATE_KW));
let m = p.start();
p.bump(CREATE_KW);
opt_temp_or_unlogged(p);
opt_persistence(p);
p.expect(PROPERTY_KW);
p.expect(GRAPH_KW);
path_name(p);
Expand Down Expand Up @@ -9901,7 +9910,7 @@ fn create_sequence(p: &mut Parser<'_>) -> CompletedMarker {
);
let m = p.start();
p.bump(CREATE_KW);
let _ = opt_temp(p) || p.eat(UNLOGGED_KW);
opt_persistence(p);
p.expect(SEQUENCE_KW);
opt_if_not_exists(p);
path_name(p);
Expand Down Expand Up @@ -11953,7 +11962,7 @@ fn create_view(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(CREATE_KW);
opt_or_replace(p);
opt_temp(p);
opt_persistence(p);
p.eat(RECURSIVE_KW);
p.expect(VIEW_KW);
path_name(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
TEMPORARY_KW "temporary"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -23,7 +24,8 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
TEMP_KW "temp"
TEMP
TEMP_KW "temp"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -38,9 +40,10 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
LOCAL_KW "local"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
LOCAL_KW "local"
WHITESPACE " "
TEMPORARY_KW "temporary"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -55,9 +58,10 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
LOCAL_KW "local"
WHITESPACE " "
TEMP_KW "temp"
TEMP
LOCAL_KW "local"
WHITESPACE " "
TEMP_KW "temp"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -72,9 +76,10 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
GLOBAL_KW "global"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
GLOBAL_KW "global"
WHITESPACE " "
TEMPORARY_KW "temporary"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -89,9 +94,10 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
GLOBAL_KW "global"
WHITESPACE " "
TEMP_KW "temp"
TEMP
GLOBAL_KW "global"
WHITESPACE " "
TEMP_KW "temp"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -106,7 +112,8 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand All @@ -121,7 +128,8 @@ SOURCE_FILE
CREATE_PROPERTY_GRAPH
CREATE_KW "create"
WHITESPACE " "
TEMP_KW "temp"
TEMP
TEMP_KW "temp"
WHITESPACE " "
PROPERTY_KW "property"
WHITESPACE " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SOURCE_FILE
CREATE_SEQUENCE
CREATE_KW "create"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
TEMPORARY_KW "temporary"
WHITESPACE " "
SEQUENCE_KW "sequence"
WHITESPACE " "
Expand Down Expand Up @@ -119,7 +120,8 @@ SOURCE_FILE
CREATE_SEQUENCE
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
SEQUENCE_KW "sequence"
WHITESPACE " "
Expand Down
26 changes: 16 additions & 10 deletions crates/squawk_parser/tests/snapshots/tests__create_table_as_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
TEMP_KW "temp"
TEMP
TEMP_KW "temp"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down Expand Up @@ -110,9 +111,10 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
LOCAL_KW "local"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
LOCAL_KW "local"
WHITESPACE " "
TEMPORARY_KW "temporary"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " \n "
Expand Down Expand Up @@ -201,9 +203,10 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
GLOBAL_KW "global"
WHITESPACE " "
TEMP_KW "temp"
TEMP
GLOBAL_KW "global"
WHITESPACE " "
TEMP_KW "temp"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " \n "
Expand Down Expand Up @@ -277,7 +280,8 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand All @@ -303,7 +307,8 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
TEMPORARY_KW "temporary"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand All @@ -328,7 +333,8 @@ SOURCE_FILE
CREATE_TABLE_AS
CREATE_KW "create"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
TEMPORARY_KW "temporary"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ SOURCE_FILE
WHITESPACE "\n"
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down
20 changes: 12 additions & 8 deletions crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ SOURCE_FILE
WHITESPACE "\n"
CREATE_KW "create"
WHITESPACE " "
GLOBAL_KW "global"
WHITESPACE " "
TEMPORARY_KW "temporary"
TEMP
GLOBAL_KW "global"
WHITESPACE " "
TEMPORARY_KW "temporary"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down Expand Up @@ -312,9 +313,10 @@ SOURCE_FILE
CREATE_TABLE
CREATE_KW "create"
WHITESPACE " "
LOCAL_KW "local"
WHITESPACE " "
TEMP_KW "temp"
TEMP
LOCAL_KW "local"
WHITESPACE " "
TEMP_KW "temp"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down Expand Up @@ -344,7 +346,8 @@ SOURCE_FILE
WHITESPACE "\n"
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down Expand Up @@ -1549,7 +1552,8 @@ SOURCE_FILE
WHITESPACE "\n"
CREATE_KW "create"
WHITESPACE " "
UNLOGGED_KW "unlogged"
UNLOGGED
UNLOGGED_KW "unlogged"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
Expand Down
Loading
Loading