Skip to main content

squawk_syntax/ast/
traits.rs

1// based on rust-analyzer's ast traits
2// https://github.com/rust-lang/rust-analyzer/blob/d8887c0758bbd2d5f752d5bd405d4491e90e7ed6/crates/syntax/src/ast/traits.rs
3use crate::ast;
4use crate::ast::{AstNode, support};
5
6pub trait NameLike: AstNode {
7    fn text(&self) -> String;
8    fn is_quoted(&self) -> bool;
9}
10
11pub trait HasPathRef: AstNode {
12    #[inline]
13    fn path_ref(&self) -> Option<ast::PathRef> {
14        support::child(self.syntax())
15    }
16}
17
18pub trait HasCreateTable: AstNode {
19    #[inline]
20    fn table_name(&self) -> Option<ast::TableName> {
21        support::child(self.syntax())
22    }
23
24    #[inline]
25    fn table_arg_list(&self) -> Option<ast::TableArgList> {
26        support::child(self.syntax())
27    }
28
29    #[inline]
30    fn persistence(&self) -> Option<ast::Persistence> {
31        support::child(self.syntax())
32    }
33
34    #[inline]
35    fn inherits(&self) -> Option<ast::Inherits> {
36        support::child(self.syntax())
37    }
38}
39
40pub trait HasWithClause: AstNode {
41    #[inline]
42    fn with_clause(&self) -> Option<ast::WithClause> {
43        support::child(self.syntax())
44    }
45}
46
47pub trait HasSelectTail: AstNode {
48    #[inline]
49    fn order_by_clause(&self) -> Option<ast::OrderByClause> {
50        support::child(self.syntax())
51    }
52
53    #[inline]
54    fn limit_clause(&self) -> Option<ast::LimitClause> {
55        support::child(self.syntax())
56    }
57
58    #[inline]
59    fn offset_clause(&self) -> Option<ast::OffsetClause> {
60        support::child(self.syntax())
61    }
62
63    #[inline]
64    fn fetch_clause(&self) -> Option<ast::FetchClause> {
65        support::child(self.syntax())
66    }
67
68    #[inline]
69    fn locking_clauses(&self) -> ast::AstChildren<ast::LockingClause> {
70        support::children(self.syntax())
71    }
72}