From 07e90325e6b6767f6943bf76d12335a44ce2b3ee Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Tue, 16 Sep 2025 23:40:43 -0400 Subject: [PATCH] syntax: fill out more of the ast --- .../squawk_syntax/src/ast/generated/nodes.rs | 170 +++++++++++++++++- crates/squawk_syntax/src/postgresql.ungram | 26 ++- 2 files changed, 187 insertions(+), 9 deletions(-) diff --git a/crates/squawk_syntax/src/ast/generated/nodes.rs b/crates/squawk_syntax/src/ast/generated/nodes.rs index c6e36d00..dd6fbcc1 100644 --- a/crates/squawk_syntax/src/ast/generated/nodes.rs +++ b/crates/squawk_syntax/src/ast/generated/nodes.rs @@ -121,6 +121,10 @@ pub struct Alias { pub(crate) syntax: SyntaxNode, } impl Alias { + #[inline] + pub fn column_list(&self) -> Option { + support::child(&self.syntax) + } #[inline] pub fn as_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::AS_KW) @@ -1642,6 +1646,10 @@ pub struct ColumnList { pub(crate) syntax: SyntaxNode, } impl ColumnList { + #[inline] + pub fn columns(&self) -> AstChildren { + support::children(&self.syntax) + } #[inline] pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::L_PAREN) @@ -4766,14 +4774,46 @@ pub struct FromItem { pub(crate) syntax: SyntaxNode, } impl FromItem { + #[inline] + pub fn alias(&self) -> Option { + support::child(&self.syntax) + } + #[inline] + pub fn call_expr(&self) -> Option { + support::child(&self.syntax) + } #[inline] pub fn name_ref(&self) -> Option { support::child(&self.syntax) } #[inline] + pub fn paren_select(&self) -> Option { + support::child(&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) + } + #[inline] + pub fn from_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::FROM_KW) + } + #[inline] + pub fn lateral_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::LATERAL_KW) + } + #[inline] pub fn only_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::ONLY_KW) } + #[inline] + pub fn rows_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::ROWS_KW) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -5572,6 +5612,10 @@ pub struct Join { pub(crate) syntax: SyntaxNode, } impl Join { + #[inline] + pub fn from_item(&self) -> Option { + support::child(&self.syntax) + } #[inline] pub fn join_type(&self) -> Option { support::child(&self.syntax) @@ -8282,6 +8326,10 @@ impl Select { pub fn window_clause(&self) -> Option { support::child(&self.syntax) } + #[inline] + pub fn with_clause(&self) -> Option { + support::child(&self.syntax) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -9104,9 +9152,17 @@ impl Target { support::child(&self.syntax) } #[inline] + pub fn name(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn star_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::STAR) } + #[inline] + pub fn as_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::AS_KW) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -9440,6 +9496,10 @@ pub struct WhereClause { pub(crate) syntax: SyntaxNode, } impl WhereClause { + #[inline] + pub fn expr(&self) -> Option { + support::child(&self.syntax) + } #[inline] pub fn where_token(&self) -> Option { support::token(&self.syntax, SyntaxKind::WHERE_KW) @@ -9622,17 +9682,37 @@ pub struct WithTable { pub(crate) syntax: SyntaxNode, } impl WithTable { + #[inline] + pub fn column_list(&self) -> Option { + support::child(&self.syntax) + } #[inline] pub fn materialized(&self) -> Option { support::child(&self.syntax) } #[inline] + pub fn name(&self) -> Option { + support::child(&self.syntax) + } + #[inline] pub fn not_materialized(&self) -> Option { support::child(&self.syntax) } #[inline] - pub fn with_token(&self) -> Option { - support::token(&self.syntax, SyntaxKind::WITH_KW) + pub fn query(&self) -> Option { + support::child(&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) + } + #[inline] + pub fn as_token(&self) -> Option { + support::token(&self.syntax, SyntaxKind::AS_KW) } } @@ -10216,6 +10296,16 @@ pub enum Type { PercentType(PercentType), TimeType(TimeType), } + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum WithQuery { + Delete(Delete), + Insert(Insert), + Merge(Merge), + Select(Select), + Update(Update), + Values(Values), +} impl AstNode for AddColumn { #[inline] fn can_cast(kind: SyntaxKind) -> bool { @@ -22655,3 +22745,79 @@ impl From for Type { Type::TimeType(node) } } +impl AstNode for WithQuery { + #[inline] + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + SyntaxKind::DELETE + | SyntaxKind::INSERT + | SyntaxKind::MERGE + | SyntaxKind::SELECT + | SyntaxKind::UPDATE + | SyntaxKind::VALUES + ) + } + #[inline] + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + SyntaxKind::DELETE => WithQuery::Delete(Delete { syntax }), + SyntaxKind::INSERT => WithQuery::Insert(Insert { syntax }), + SyntaxKind::MERGE => WithQuery::Merge(Merge { syntax }), + SyntaxKind::SELECT => WithQuery::Select(Select { syntax }), + SyntaxKind::UPDATE => WithQuery::Update(Update { syntax }), + SyntaxKind::VALUES => WithQuery::Values(Values { syntax }), + _ => { + return None; + } + }; + Some(res) + } + #[inline] + fn syntax(&self) -> &SyntaxNode { + match self { + WithQuery::Delete(it) => &it.syntax, + WithQuery::Insert(it) => &it.syntax, + WithQuery::Merge(it) => &it.syntax, + WithQuery::Select(it) => &it.syntax, + WithQuery::Update(it) => &it.syntax, + WithQuery::Values(it) => &it.syntax, + } + } +} +impl From for WithQuery { + #[inline] + fn from(node: Delete) -> WithQuery { + WithQuery::Delete(node) + } +} +impl From for WithQuery { + #[inline] + fn from(node: Insert) -> WithQuery { + WithQuery::Insert(node) + } +} +impl From for WithQuery { + #[inline] + fn from(node: Merge) -> WithQuery { + WithQuery::Merge(node) + } +} +impl From