aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs86
-rw-r--r--crates/libsyntax2/src/ast/mod.rs6
2 files changed, 90 insertions, 2 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index e8743caa8..d72e2091a 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -4,6 +4,28 @@ use {
4 SyntaxKind::*, 4 SyntaxKind::*,
5}; 5};
6 6
7// ArgList
8#[derive(Debug, Clone, Copy)]
9pub struct ArgList<'a> {
10 syntax: SyntaxNodeRef<'a>,
11}
12
13impl<'a> AstNode<'a> for ArgList<'a> {
14 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
15 match syntax.kind() {
16 ARG_LIST => Some(ArgList { syntax }),
17 _ => None,
18 }
19 }
20 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
21}
22
23impl<'a> ArgList<'a> {
24 pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a {
25 super::children(self)
26 }
27}
28
7// ArrayExpr 29// ArrayExpr
8#[derive(Debug, Clone, Copy)] 30#[derive(Debug, Clone, Copy)]
9pub struct ArrayExpr<'a> { 31pub struct ArrayExpr<'a> {
@@ -181,7 +203,15 @@ impl<'a> AstNode<'a> for CallExpr<'a> {
181 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 203 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
182} 204}
183 205
184impl<'a> CallExpr<'a> {} 206impl<'a> CallExpr<'a> {
207 pub fn expr(self) -> Option<Expr<'a>> {
208 super::child_opt(self)
209 }
210
211 pub fn arg_list(self) -> Option<ArgList<'a>> {
212 super::child_opt(self)
213 }
214}
185 215
186// CastExpr 216// CastExpr
187#[derive(Debug, Clone, Copy)] 217#[derive(Debug, Clone, Copy)]
@@ -705,7 +735,15 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> {
705 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 735 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
706} 736}
707 737
708impl<'a> LambdaExpr<'a> {} 738impl<'a> LambdaExpr<'a> {
739 pub fn param_list(self) -> Option<ParamList<'a>> {
740 super::child_opt(self)
741 }
742
743 pub fn body(self) -> Option<Expr<'a>> {
744 super::child_opt(self)
745 }
746}
709 747
710// LetStmt 748// LetStmt
711#[derive(Debug, Clone, Copy)] 749#[derive(Debug, Clone, Copy)]
@@ -733,6 +771,46 @@ impl<'a> LetStmt<'a> {
733 } 771 }
734} 772}
735 773
774// Lifetime
775#[derive(Debug, Clone, Copy)]
776pub struct Lifetime<'a> {
777 syntax: SyntaxNodeRef<'a>,
778}
779
780impl<'a> AstNode<'a> for Lifetime<'a> {
781 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
782 match syntax.kind() {
783 LIFETIME => Some(Lifetime { syntax }),
784 _ => None,
785 }
786 }
787 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
788}
789
790impl<'a> Lifetime<'a> {}
791
792// LifetimeParam
793#[derive(Debug, Clone, Copy)]
794pub struct LifetimeParam<'a> {
795 syntax: SyntaxNodeRef<'a>,
796}
797
798impl<'a> AstNode<'a> for LifetimeParam<'a> {
799 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
800 match syntax.kind() {
801 LIFETIME_PARAM => Some(LifetimeParam { syntax }),
802 _ => None,
803 }
804 }
805 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
806}
807
808impl<'a> LifetimeParam<'a> {
809 pub fn lifetime(self) -> Option<Lifetime<'a>> {
810 super::child_opt(self)
811 }
812}
813
736// Literal 814// Literal
737#[derive(Debug, Clone, Copy)] 815#[derive(Debug, Clone, Copy)]
738pub struct Literal<'a> { 816pub struct Literal<'a> {
@@ -1813,6 +1891,10 @@ impl<'a> TypeParamList<'a> {
1813 pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a { 1891 pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a {
1814 super::children(self) 1892 super::children(self)
1815 } 1893 }
1894
1895 pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a {
1896 super::children(self)
1897 }
1816} 1898}
1817 1899
1818// TypeRef 1900// TypeRef
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index 9941138a7..3b5e9269f 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -67,6 +67,12 @@ impl<'a> Attr<'a> {
67 } 67 }
68} 68}
69 69
70impl<'a> Lifetime<'a> {
71 pub fn text(&self) -> SmolStr {
72 self.syntax().leaf_text().unwrap()
73 }
74}
75
70impl<'a> Name<'a> { 76impl<'a> Name<'a> {
71 pub fn text(&self) -> SmolStr { 77 pub fn text(&self) -> SmolStr {
72 let ident = self.syntax().first_child() 78 let ident = self.syntax().first_child()