aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs96
-rw-r--r--crates/ra_syntax/src/ast/make.rs2
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs12
3 files changed, 53 insertions, 57 deletions
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 9f9c06e50..46d73215c 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -165,7 +165,7 @@ impl ast::GenericParamsOwner for StructDef {}
165impl StructDef { 165impl StructDef {
166 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } 166 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) }
167 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 167 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
168 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } 168 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
169} 169}
170#[derive(Debug, Clone, PartialEq, Eq, Hash)] 170#[derive(Debug, Clone, PartialEq, Eq, Hash)]
171pub struct TraitDef { 171pub struct TraitDef {
@@ -208,9 +208,7 @@ impl ast::VisibilityOwner for UnionDef {}
208impl ast::GenericParamsOwner for UnionDef {} 208impl ast::GenericParamsOwner for UnionDef {}
209impl UnionDef { 209impl UnionDef {
210 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } 210 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) }
211 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { 211 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) }
212 support::child(&self.syntax)
213 }
214} 212}
215#[derive(Debug, Clone, PartialEq, Eq, Hash)] 213#[derive(Debug, Clone, PartialEq, Eq, Hash)]
216pub struct Use { 214pub struct Use {
@@ -391,42 +389,42 @@ impl TypeBoundList {
391 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } 389 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
392} 390}
393#[derive(Debug, Clone, PartialEq, Eq, Hash)] 391#[derive(Debug, Clone, PartialEq, Eq, Hash)]
394pub struct RecordFieldDefList { 392pub struct RecordFieldList {
395 pub(crate) syntax: SyntaxNode, 393 pub(crate) syntax: SyntaxNode,
396} 394}
397impl RecordFieldDefList { 395impl RecordFieldList {
398 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 396 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
399 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } 397 pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) }
400 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 398 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
401} 399}
402#[derive(Debug, Clone, PartialEq, Eq, Hash)] 400#[derive(Debug, Clone, PartialEq, Eq, Hash)]
403pub struct TupleFieldDefList { 401pub struct TupleFieldList {
404 pub(crate) syntax: SyntaxNode, 402 pub(crate) syntax: SyntaxNode,
405} 403}
406impl TupleFieldDefList { 404impl TupleFieldList {
407 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 405 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
408 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } 406 pub fn fields(&self) -> AstChildren<TupleField> { support::children(&self.syntax) }
409 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 407 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
410} 408}
411#[derive(Debug, Clone, PartialEq, Eq, Hash)] 409#[derive(Debug, Clone, PartialEq, Eq, Hash)]
412pub struct RecordFieldDef { 410pub struct RecordField {
413 pub(crate) syntax: SyntaxNode, 411 pub(crate) syntax: SyntaxNode,
414} 412}
415impl ast::AttrsOwner for RecordFieldDef {} 413impl ast::AttrsOwner for RecordField {}
416impl ast::NameOwner for RecordFieldDef {} 414impl ast::NameOwner for RecordField {}
417impl ast::VisibilityOwner for RecordFieldDef {} 415impl ast::VisibilityOwner for RecordField {}
418impl ast::TypeAscriptionOwner for RecordFieldDef {} 416impl ast::TypeAscriptionOwner for RecordField {}
419impl RecordFieldDef { 417impl RecordField {
420 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 418 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
421} 419}
422#[derive(Debug, Clone, PartialEq, Eq, Hash)] 420#[derive(Debug, Clone, PartialEq, Eq, Hash)]
423pub struct TupleFieldDef { 421pub struct TupleField {
424 pub(crate) syntax: SyntaxNode, 422 pub(crate) syntax: SyntaxNode,
425} 423}
426impl ast::AttrsOwner for TupleFieldDef {} 424impl ast::AttrsOwner for TupleField {}
427impl ast::NameOwner for TupleFieldDef {} 425impl ast::NameOwner for TupleField {}
428impl ast::VisibilityOwner for TupleFieldDef {} 426impl ast::VisibilityOwner for TupleField {}
429impl TupleFieldDef { 427impl TupleField {
430 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 428 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
431} 429}
432#[derive(Debug, Clone, PartialEq, Eq, Hash)] 430#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -446,7 +444,7 @@ impl ast::AttrsOwner for EnumVariant {}
446impl ast::NameOwner for EnumVariant {} 444impl ast::NameOwner for EnumVariant {}
447impl ast::VisibilityOwner for EnumVariant {} 445impl ast::VisibilityOwner for EnumVariant {}
448impl EnumVariant { 446impl EnumVariant {
449 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } 447 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
450 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 448 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
451 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 449 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
452} 450}
@@ -1326,9 +1324,9 @@ pub enum Pat {
1326 MacroPat(MacroPat), 1324 MacroPat(MacroPat),
1327} 1325}
1328#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1326#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1329pub enum FieldDefList { 1327pub enum FieldList {
1330 RecordFieldDefList(RecordFieldDefList), 1328 RecordFieldList(RecordFieldList),
1331 TupleFieldDefList(TupleFieldDefList), 1329 TupleFieldList(TupleFieldList),
1332} 1330}
1333#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1331#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1334pub enum Expr { 1332pub enum Expr {
@@ -1765,8 +1763,8 @@ impl AstNode for TypeBoundList {
1765 } 1763 }
1766 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1767} 1765}
1768impl AstNode for RecordFieldDefList { 1766impl AstNode for RecordFieldList {
1769 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } 1767 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST }
1770 fn cast(syntax: SyntaxNode) -> Option<Self> { 1768 fn cast(syntax: SyntaxNode) -> Option<Self> {
1771 if Self::can_cast(syntax.kind()) { 1769 if Self::can_cast(syntax.kind()) {
1772 Some(Self { syntax }) 1770 Some(Self { syntax })
@@ -1776,8 +1774,8 @@ impl AstNode for RecordFieldDefList {
1776 } 1774 }
1777 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1775 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1778} 1776}
1779impl AstNode for TupleFieldDefList { 1777impl AstNode for TupleFieldList {
1780 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF_LIST } 1778 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_LIST }
1781 fn cast(syntax: SyntaxNode) -> Option<Self> { 1779 fn cast(syntax: SyntaxNode) -> Option<Self> {
1782 if Self::can_cast(syntax.kind()) { 1780 if Self::can_cast(syntax.kind()) {
1783 Some(Self { syntax }) 1781 Some(Self { syntax })
@@ -1787,8 +1785,8 @@ impl AstNode for TupleFieldDefList {
1787 } 1785 }
1788 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1786 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1789} 1787}
1790impl AstNode for RecordFieldDef { 1788impl AstNode for RecordField {
1791 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } 1789 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD }
1792 fn cast(syntax: SyntaxNode) -> Option<Self> { 1790 fn cast(syntax: SyntaxNode) -> Option<Self> {
1793 if Self::can_cast(syntax.kind()) { 1791 if Self::can_cast(syntax.kind()) {
1794 Some(Self { syntax }) 1792 Some(Self { syntax })
@@ -1798,8 +1796,8 @@ impl AstNode for RecordFieldDef {
1798 } 1796 }
1799 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1797 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1800} 1798}
1801impl AstNode for TupleFieldDef { 1799impl AstNode for TupleField {
1802 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } 1800 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD }
1803 fn cast(syntax: SyntaxNode) -> Option<Self> { 1801 fn cast(syntax: SyntaxNode) -> Option<Self> {
1804 if Self::can_cast(syntax.kind()) { 1802 if Self::can_cast(syntax.kind()) {
1805 Some(Self { syntax }) 1803 Some(Self { syntax })
@@ -3046,33 +3044,31 @@ impl AstNode for Pat {
3046 } 3044 }
3047 } 3045 }
3048} 3046}
3049impl From<RecordFieldDefList> for FieldDefList { 3047impl From<RecordFieldList> for FieldList {
3050 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } 3048 fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) }
3051} 3049}
3052impl From<TupleFieldDefList> for FieldDefList { 3050impl From<TupleFieldList> for FieldList {
3053 fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) } 3051 fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) }
3054} 3052}
3055impl AstNode for FieldDefList { 3053impl AstNode for FieldList {
3056 fn can_cast(kind: SyntaxKind) -> bool { 3054 fn can_cast(kind: SyntaxKind) -> bool {
3057 match kind { 3055 match kind {
3058 RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true, 3056 RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true,
3059 _ => false, 3057 _ => false,
3060 } 3058 }
3061 } 3059 }
3062 fn cast(syntax: SyntaxNode) -> Option<Self> { 3060 fn cast(syntax: SyntaxNode) -> Option<Self> {
3063 let res = match syntax.kind() { 3061 let res = match syntax.kind() {
3064 RECORD_FIELD_DEF_LIST => { 3062 RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }),
3065 FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax }) 3063 TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }),
3066 }
3067 TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }),
3068 _ => return None, 3064 _ => return None,
3069 }; 3065 };
3070 Some(res) 3066 Some(res)
3071 } 3067 }
3072 fn syntax(&self) -> &SyntaxNode { 3068 fn syntax(&self) -> &SyntaxNode {
3073 match self { 3069 match self {
3074 FieldDefList::RecordFieldDefList(it) => &it.syntax, 3070 FieldList::RecordFieldList(it) => &it.syntax,
3075 FieldDefList::TupleFieldDefList(it) => &it.syntax, 3071 FieldList::TupleFieldList(it) => &it.syntax,
3076 } 3072 }
3077 } 3073 }
3078} 3074}
@@ -3425,7 +3421,7 @@ impl std::fmt::Display for Pat {
3425 std::fmt::Display::fmt(self.syntax(), f) 3421 std::fmt::Display::fmt(self.syntax(), f)
3426 } 3422 }
3427} 3423}
3428impl std::fmt::Display for FieldDefList { 3424impl std::fmt::Display for FieldList {
3429 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3425 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3430 std::fmt::Display::fmt(self.syntax(), f) 3426 std::fmt::Display::fmt(self.syntax(), f)
3431 } 3427 }
@@ -3625,22 +3621,22 @@ impl std::fmt::Display for TypeBoundList {
3625 std::fmt::Display::fmt(self.syntax(), f) 3621 std::fmt::Display::fmt(self.syntax(), f)
3626 } 3622 }
3627} 3623}
3628impl std::fmt::Display for RecordFieldDefList { 3624impl std::fmt::Display for RecordFieldList {
3629 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3625 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3630 std::fmt::Display::fmt(self.syntax(), f) 3626 std::fmt::Display::fmt(self.syntax(), f)
3631 } 3627 }
3632} 3628}
3633impl std::fmt::Display for TupleFieldDefList { 3629impl std::fmt::Display for TupleFieldList {
3634 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3630 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3635 std::fmt::Display::fmt(self.syntax(), f) 3631 std::fmt::Display::fmt(self.syntax(), f)
3636 } 3632 }
3637} 3633}
3638impl std::fmt::Display for RecordFieldDef { 3634impl std::fmt::Display for RecordField {
3639 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3635 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3640 std::fmt::Display::fmt(self.syntax(), f) 3636 std::fmt::Display::fmt(self.syntax(), f)
3641 } 3637 }
3642} 3638}
3643impl std::fmt::Display for TupleFieldDef { 3639impl std::fmt::Display for TupleField {
3644 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3640 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3645 std::fmt::Display::fmt(self.syntax(), f) 3641 std::fmt::Display::fmt(self.syntax(), f)
3646 } 3642 }
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 183ec4481..509e8ae7a 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -75,7 +75,7 @@ pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordE
75 } 75 }
76} 76}
77 77
78pub fn record_field_def(name: ast::NameRef, ty: ast::TypeRef) -> ast::RecordFieldDef { 78pub fn record_field_def(name: ast::NameRef, ty: ast::TypeRef) -> ast::RecordField {
79 ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty)) 79 ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty))
80} 80}
81 81
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 8c7457e32..ffe6746d3 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -166,16 +166,16 @@ impl ast::ImplDef {
166 166
167#[derive(Debug, Clone, PartialEq, Eq)] 167#[derive(Debug, Clone, PartialEq, Eq)]
168pub enum StructKind { 168pub enum StructKind {
169 Record(ast::RecordFieldDefList), 169 Record(ast::RecordFieldList),
170 Tuple(ast::TupleFieldDefList), 170 Tuple(ast::TupleFieldList),
171 Unit, 171 Unit,
172} 172}
173 173
174impl StructKind { 174impl StructKind {
175 fn from_node<N: AstNode>(node: &N) -> StructKind { 175 fn from_node<N: AstNode>(node: &N) -> StructKind {
176 if let Some(nfdl) = support::child::<ast::RecordFieldDefList>(node.syntax()) { 176 if let Some(nfdl) = support::child::<ast::RecordFieldList>(node.syntax()) {
177 StructKind::Record(nfdl) 177 StructKind::Record(nfdl)
178 } else if let Some(pfl) = support::child::<ast::TupleFieldDefList>(node.syntax()) { 178 } else if let Some(pfl) = support::child::<ast::TupleFieldList>(node.syntax()) {
179 StructKind::Tuple(pfl) 179 StructKind::Tuple(pfl)
180 } else { 180 } else {
181 StructKind::Unit 181 StructKind::Unit
@@ -477,8 +477,8 @@ impl ast::DocCommentsOwner for ast::SourceFile {}
477impl ast::DocCommentsOwner for ast::Fn {} 477impl ast::DocCommentsOwner for ast::Fn {}
478impl ast::DocCommentsOwner for ast::StructDef {} 478impl ast::DocCommentsOwner for ast::StructDef {}
479impl ast::DocCommentsOwner for ast::UnionDef {} 479impl ast::DocCommentsOwner for ast::UnionDef {}
480impl ast::DocCommentsOwner for ast::RecordFieldDef {} 480impl ast::DocCommentsOwner for ast::RecordField {}
481impl ast::DocCommentsOwner for ast::TupleFieldDef {} 481impl ast::DocCommentsOwner for ast::TupleField {}
482impl ast::DocCommentsOwner for ast::EnumDef {} 482impl ast::DocCommentsOwner for ast::EnumDef {}
483impl ast::DocCommentsOwner for ast::EnumVariant {} 483impl ast::DocCommentsOwner for ast::EnumVariant {}
484impl ast::DocCommentsOwner for ast::TraitDef {} 484impl ast::DocCommentsOwner for ast::TraitDef {}