diff --git a/crates/squawk_ide/src/binder.rs b/crates/squawk_ide/src/binder.rs index 12d202ce..aacaa50e 100644 --- a/crates/squawk_ide/src/binder.rs +++ b/crates/squawk_ide/src/binder.rs @@ -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; }; @@ -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; }; @@ -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; @@ -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; diff --git a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs index f1eb20bd..745ece0b 100644 --- a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs +++ b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs @@ -147,8 +147,9 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse) { 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()) diff --git a/crates/squawk_parser/src/generated/syntax_kind.rs b/crates/squawk_parser/src/generated/syntax_kind.rs index 1d6b8e7f..fa7907dd 100644 --- a/crates/squawk_parser/src/generated/syntax_kind.rs +++ b/crates/squawk_parser/src/generated/syntax_kind.rs @@ -1193,6 +1193,7 @@ pub enum SyntaxKind { UNICODE_NORMAL_FORM, UNIQUE_CONSTRAINT, UNLISTEN, + UNLOGGED, UPDATE, USING_CLAUSE, USING_EXPR_CLAUSE, diff --git a/crates/squawk_parser/src/grammar.rs b/crates/squawk_parser/src/grammar.rs index 182c6c8e..e52b15d5 100644 --- a/crates/squawk_parser/src/grammar.rs +++ b/crates/squawk_parser/src/grammar.rs @@ -2795,7 +2795,7 @@ fn opt_into_clause(p: &mut Parser<'_>) -> Option { 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)) @@ -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); @@ -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 } } @@ -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); @@ -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); @@ -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); diff --git a/crates/squawk_parser/tests/snapshots/tests__create_property_graph_ok.snap b/crates/squawk_parser/tests/snapshots/tests__create_property_graph_ok.snap index 892cdc83..dfd6f33a 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_property_graph_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_property_graph_ok.snap @@ -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 " " @@ -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 " " @@ -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 " " @@ -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 " " @@ -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 " " @@ -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 " " @@ -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 " " @@ -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 " " diff --git a/crates/squawk_parser/tests/snapshots/tests__create_sequence_ok.snap b/crates/squawk_parser/tests/snapshots/tests__create_sequence_ok.snap index 28dc6c9c..ac3fe230 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_sequence_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_sequence_ok.snap @@ -21,7 +21,8 @@ SOURCE_FILE CREATE_SEQUENCE CREATE_KW "create" WHITESPACE " " - TEMPORARY_KW "temporary" + TEMP + TEMPORARY_KW "temporary" WHITESPACE " " SEQUENCE_KW "sequence" WHITESPACE " " @@ -119,7 +120,8 @@ SOURCE_FILE CREATE_SEQUENCE CREATE_KW "create" WHITESPACE " " - UNLOGGED_KW "unlogged" + UNLOGGED + UNLOGGED_KW "unlogged" WHITESPACE " " SEQUENCE_KW "sequence" WHITESPACE " " diff --git a/crates/squawk_parser/tests/snapshots/tests__create_table_as_ok.snap b/crates/squawk_parser/tests/snapshots/tests__create_table_as_ok.snap index b429a85b..3063c0f1 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_table_as_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_table_as_ok.snap @@ -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 " " @@ -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 " @@ -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 " @@ -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 " " @@ -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 " " @@ -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 " " diff --git a/crates/squawk_parser/tests/snapshots/tests__create_table_err.snap b/crates/squawk_parser/tests/snapshots/tests__create_table_err.snap index 0fb733c5..de9273a0 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_table_err.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_table_err.snap @@ -264,7 +264,8 @@ SOURCE_FILE WHITESPACE "\n" CREATE_KW "create" WHITESPACE " " - UNLOGGED_KW "unlogged" + UNLOGGED + UNLOGGED_KW "unlogged" WHITESPACE " " TABLE_KW "table" WHITESPACE " " diff --git a/crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap b/crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap index df443d20..36e4b3c9 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap @@ -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 " " @@ -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 " " @@ -344,7 +346,8 @@ SOURCE_FILE WHITESPACE "\n" CREATE_KW "create" WHITESPACE " " - UNLOGGED_KW "unlogged" + UNLOGGED + UNLOGGED_KW "unlogged" WHITESPACE " " TABLE_KW "table" WHITESPACE " " @@ -1549,7 +1552,8 @@ SOURCE_FILE WHITESPACE "\n" CREATE_KW "create" WHITESPACE " " - UNLOGGED_KW "unlogged" + UNLOGGED + UNLOGGED_KW "unlogged" WHITESPACE " " TABLE_KW "table" WHITESPACE " " diff --git a/crates/squawk_parser/tests/snapshots/tests__create_view_ok.snap b/crates/squawk_parser/tests/snapshots/tests__create_view_ok.snap index 77fbe838..a0179a93 100644 --- a/crates/squawk_parser/tests/snapshots/tests__create_view_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__create_view_ok.snap @@ -416,7 +416,8 @@ SOURCE_FILE WHITESPACE " " REPLACE_KW "replace" WHITESPACE " " - TEMP_KW "temp" + TEMP + TEMP_KW "temp" WHITESPACE " " RECURSIVE_KW "recursive" WHITESPACE " " @@ -493,7 +494,8 @@ SOURCE_FILE CREATE_VIEW CREATE_KW "create" WHITESPACE " " - TEMPORARY_KW "temporary" + TEMP + TEMPORARY_KW "temporary" WHITESPACE " " VIEW_KW "view" WHITESPACE " " diff --git a/crates/squawk_parser/tests/snapshots/tests__misc_ok.snap b/crates/squawk_parser/tests/snapshots/tests__misc_ok.snap index ba67c608..40ad0c35 100644 --- a/crates/squawk_parser/tests/snapshots/tests__misc_ok.snap +++ b/crates/squawk_parser/tests/snapshots/tests__misc_ok.snap @@ -1459,7 +1459,8 @@ SOURCE_FILE CREATE_TABLE CREATE_KW "CREATE" WHITESPACE " " - TEMP_KW "TEMP" + TEMP + TEMP_KW "TEMP" WHITESPACE " " TABLE_KW "TABLE" WHITESPACE " " diff --git a/crates/squawk_syntax/src/ast/generated/nodes.rs b/crates/squawk_syntax/src/ast/generated/nodes.rs index 604561b8..dc262f92 100644 --- a/crates/squawk_syntax/src/ast/generated/nodes.rs +++ b/crates/squawk_syntax/src/ast/generated/nodes.rs @@ -4657,7 +4657,7 @@ impl CreatePropertyGraph { support::child(&self.syntax) } #[inline] - pub fn temp(&self) -> Option { + pub fn persistence(&self) -> Option { support::child(&self.syntax) } #[inline] @@ -4892,6 +4892,10 @@ impl CreateSequence { support::child(&self.syntax) } #[inline] + pub fn persistence(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn sequence_options(&self) -> AstChildren { support::children(&self.syntax) } @@ -4903,18 +4907,6 @@ impl CreateSequence { pub fn sequence_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::SEQUENCE_KW) } - #[inline] - pub fn temp_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMP_KW) - } - #[inline] - pub fn temporary_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMPORARY_KW) - } - #[inline] - pub fn unlogged_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::UNLOGGED_KW) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -5084,6 +5076,10 @@ impl CreateTable { support::child(&self.syntax) } #[inline] + pub fn persistence(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn table_arg_list(&self) -> Option { support::child(&self.syntax) } @@ -5108,29 +5104,9 @@ impl CreateTable { support::token(&self.syntax, SyntaxKind::CREATE_KW) } #[inline] - pub fn global_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::GLOBAL_KW) - } - #[inline] - pub fn local_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::LOCAL_KW) - } - #[inline] pub fn table_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::TABLE_KW) } - #[inline] - pub fn temp_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMP_KW) - } - #[inline] - pub fn temporary_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMPORARY_KW) - } - #[inline] - pub fn unlogged_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::UNLOGGED_KW) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -5151,6 +5127,10 @@ impl CreateTableAs { support::child(&self.syntax) } #[inline] + pub fn persistence(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn query(&self) -> Option { support::child(&self.syntax) } @@ -5187,29 +5167,9 @@ impl CreateTableAs { support::token(&self.syntax, SyntaxKind::CREATE_KW) } #[inline] - pub fn global_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::GLOBAL_KW) - } - #[inline] - pub fn local_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::LOCAL_KW) - } - #[inline] pub fn table_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::TABLE_KW) } - #[inline] - pub fn temp_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMP_KW) - } - #[inline] - pub fn temporary_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMPORARY_KW) - } - #[inline] - pub fn unlogged_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::UNLOGGED_KW) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -5656,6 +5616,10 @@ impl CreateView { support::child(&self.syntax) } #[inline] + pub fn persistence(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn query(&self) -> Option { support::child(&self.syntax) } @@ -5692,14 +5656,6 @@ impl CreateView { support::token(&self.syntax, SyntaxKind::RECURSIVE_KW) } #[inline] - pub fn temp_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMP_KW) - } - #[inline] - pub fn temporary_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::TEMPORARY_KW) - } - #[inline] pub fn view_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::VIEW_KW) } @@ -6002,10 +5958,6 @@ impl DestVertexTable { support::child(&self.syntax) } #[inline] - pub fn name(&self) -> Option { - support::child(&self.syntax) - } - #[inline] pub fn name_ref(&self) -> Option { support::child(&self.syntax) } @@ -9806,9 +9758,17 @@ impl IntoClause { support::child(&self.syntax) } #[inline] + pub fn persistence(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn into_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::INTO_KW) } + #[inline] + pub fn table_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::TABLE_KW) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -11284,14 +11244,6 @@ impl LabelAndPropertiesList { pub fn label_and_propertiess(&self) -> AstChildren { support::children(&self.syntax) } - #[inline] - pub fn l_paren_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::L_PAREN) - } - #[inline] - pub fn r_paren_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::R_PAREN) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -16368,10 +16320,6 @@ impl SourceVertexTable { support::child(&self.syntax) } #[inline] - pub fn name(&self) -> Option { - support::child(&self.syntax) - } - #[inline] pub fn name_ref(&self) -> Option { support::child(&self.syntax) } @@ -16688,10 +16636,6 @@ impl Temp { pub fn temporary_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::TEMPORARY_KW) } - #[inline] - pub fn unlogged_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::UNLOGGED_KW) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -17051,6 +16995,17 @@ impl Unlisten { } } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Unlogged { + pub(crate) syntax: SyntaxNode, +} +impl Unlogged { + #[inline] + pub fn unlogged_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::UNLOGGED_KW) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Update { pub(crate) syntax: SyntaxNode, @@ -18663,6 +18618,12 @@ pub enum PathPrimary { VertexPattern(VertexPattern), } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Persistence { + Temp(Temp), + Unlogged(Unlogged), +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum PreparableStmt { CompoundSelect(CompoundSelect), @@ -30304,6 +30265,24 @@ impl AstNode for Unlisten { &self.syntax } } +impl AstNode for Unlogged { + #[inline] + fn can_cast(kind: SyntaxKind) -> bool { + kind == SyntaxKind::UNLOGGED + } + #[inline] + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + #[inline] + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} impl AstNode for Update { #[inline] fn can_cast(kind: SyntaxKind) -> bool { @@ -34008,6 +33987,42 @@ impl From for PathPrimary { PathPrimary::VertexPattern(node) } } +impl AstNode for Persistence { + #[inline] + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, SyntaxKind::TEMP | SyntaxKind::UNLOGGED) + } + #[inline] + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + SyntaxKind::TEMP => Persistence::Temp(Temp { syntax }), + SyntaxKind::UNLOGGED => Persistence::Unlogged(Unlogged { syntax }), + _ => { + return None; + } + }; + Some(res) + } + #[inline] + fn syntax(&self) -> &SyntaxNode { + match self { + Persistence::Temp(it) => &it.syntax, + Persistence::Unlogged(it) => &it.syntax, + } + } +} +impl From for Persistence { + #[inline] + fn from(node: Temp) -> Persistence { + Persistence::Temp(node) + } +} +impl From for Persistence { + #[inline] + fn from(node: Unlogged) -> Persistence { + Persistence::Unlogged(node) + } +} impl AstNode for PreparableStmt { #[inline] fn can_cast(kind: SyntaxKind) -> bool { diff --git a/crates/squawk_syntax/src/ast/traits.rs b/crates/squawk_syntax/src/ast/traits.rs index 47a165b5..a057603e 100644 --- a/crates/squawk_syntax/src/ast/traits.rs +++ b/crates/squawk_syntax/src/ast/traits.rs @@ -1,9 +1,7 @@ -use squawk_parser::SyntaxKind; - // based on rust-analyzer's ast traits // https://github.com/rust-lang/rust-analyzer/blob/d8887c0758bbd2d5f752d5bd405d4491e90e7ed6/crates/syntax/src/ast/traits.rs +use crate::ast; use crate::ast::{AstNode, support}; -use crate::{SyntaxToken, ast}; pub trait NameLike: AstNode {} @@ -19,13 +17,8 @@ pub trait HasCreateTable: AstNode { } #[inline] - fn temp_token(&self) -> Option { - support::token(self.syntax(), SyntaxKind::TEMP_KW) - } - - #[inline] - fn temporary_token(&self) -> Option { - support::token(self.syntax(), SyntaxKind::TEMPORARY_KW) + fn persistence(&self) -> Option { + support::child(self.syntax()) } #[inline] diff --git a/crates/squawk_syntax/src/postgresql.ungram b/crates/squawk_syntax/src/postgresql.ungram index 71301ab9..f42d3c4c 100644 --- a/crates/squawk_syntax/src/postgresql.ungram +++ b/crates/squawk_syntax/src/postgresql.ungram @@ -1122,7 +1122,7 @@ PartitionBy = CreateTable = 'create' - (('global' | 'local')? ('temporary' | 'temp' | 'unlogged' ))? + Persistence? 'table' IfNotExists? Path PartitionOf? OfType? @@ -1454,7 +1454,7 @@ WithNoData = CreateTableAs = 'create' - (('global' | 'local')? ('temporary' | 'temp' | 'unlogged' ))? + Persistence? 'table' IfNotExists? Path @@ -1684,7 +1684,7 @@ SelectInto = FilterClause? IntoClause = - 'into' Path + 'into' Persistence? 'table'? Path LockingClause = 'for' @@ -2240,7 +2240,10 @@ Repack = 'using' 'index' NameRef? )? -// TODO: use this everywhere +Persistence = + Temp +| Unlogged + Temp = 'temporary' | 'temp' @@ -2248,10 +2251,12 @@ Temp = | 'local' 'temp' | 'global' 'temporary' | 'global' 'temp' -| 'unlogged' + +Unlogged = + 'unlogged' CreatePropertyGraph = - 'create' Temp? 'property' 'graph' Path + 'create' Persistence? 'property' 'graph' Path VertexTables? EdgeTables? @@ -2546,7 +2551,7 @@ CreateRule = 'do' ('also' | 'instead')? ('nothing' | '(' (Stmt (',' Stmt)*) ')' | Stmt) CreateSequence = - 'create' ('temporary' | 'temp' | 'unlogged')? 'sequence' IfNotExists? Path + 'create' Persistence? 'sequence' IfNotExists? Path SequenceOption* CreateServer = @@ -2888,7 +2893,7 @@ Reindex = 'reindex' ('table' | 'index' | 'schema' | 'database' | 'system')? Path? CreateView = - 'create' OrReplace? ('temp' | 'temporary')? 'recursive'? 'view' Path ColumnList? + 'create' OrReplace? Persistence? 'recursive'? 'view' Path ColumnList? WithParams? 'as' query:SelectVariant ('with' ('cascaded' | 'local')? 'check' 'option')?