squawk_syntax/ast/
nodes.rs

1pub use crate::ast::generated::nodes::*;
2use crate::{
3    SyntaxNode,
4    ast::{self, AstNode, support},
5};
6
7// TODO: Initial attempt to try and unify the CreateTable and
8// CreateForeignTable. Not sure this is the right approach, we may want to be
9// more general, like TableSource, which can be a View, CTE, Table,
10// ForeignTable, Subquery, etc.
11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct CreateTableLike {
13    pub(crate) syntax: SyntaxNode,
14}
15impl CreateTableLike {
16    #[inline]
17    pub fn path(&self) -> Option<ast::Path> {
18        support::child(&self.syntax)
19    }
20    #[inline]
21    pub fn table_arg_list(&self) -> Option<ast::TableArgList> {
22        support::child(&self.syntax)
23    }
24}
25impl AstNode for CreateTableLike {
26    #[inline]
27    fn can_cast(kind: ast::SyntaxKind) -> bool {
28        matches!(
29            kind,
30            ast::SyntaxKind::CREATE_TABLE | ast::SyntaxKind::CREATE_FOREIGN_TABLE
31        )
32    }
33    #[inline]
34    fn cast(syntax: SyntaxNode) -> Option<Self> {
35        if Self::can_cast(syntax.kind()) {
36            Some(Self { syntax })
37        } else {
38            None
39        }
40    }
41    #[inline]
42    fn syntax(&self) -> &SyntaxNode {
43        &self.syntax
44    }
45}