From 5b18a4eef9e69260ce2f105b33553c929cb7d827 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 23 Aug 2019 15:55:21 +0300 Subject: rename struct -> record, pos -> tuple --- crates/ra_syntax/src/ast/expr_extensions.rs | 6 +- crates/ra_syntax/src/ast/extensions.rs | 8 +- crates/ra_syntax/src/ast/generated.rs | 522 ++++++++++++------------- crates/ra_syntax/src/grammar.ron | 48 +-- crates/ra_syntax/src/parsing/text_tree_sink.rs | 2 +- crates/ra_syntax/src/ptr.rs | 2 +- crates/ra_syntax/src/validation.rs | 2 +- 7 files changed, 295 insertions(+), 295 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index cf5b6f251..d7ea4354d 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -296,8 +296,8 @@ fn test_literal_with_attr() { assert_eq!(lit.token().text(), r#""Hello""#); } -impl ast::NamedField { - pub fn parent_struct_lit(&self) -> ast::StructLit { - self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap() +impl ast::RecordField { + pub fn parent_record_lit(&self) -> ast::RecordLit { + self.syntax().ancestors().find_map(ast::RecordLit::cast).unwrap() } } diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index e0ea3e5ab..d3a375f87 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -195,16 +195,16 @@ impl ast::ImplBlock { #[derive(Debug, Clone, PartialEq, Eq)] pub enum StructKind { - Tuple(ast::PosFieldDefList), - Named(ast::NamedFieldDefList), + Tuple(ast::TupleFieldDefList), + Named(ast::RecordFieldDefList), Unit, } impl StructKind { fn from_node(node: &N) -> StructKind { - if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) { + if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) { StructKind::Named(nfdl) - } else if let Some(pfl) = child_opt::<_, ast::PosFieldDefList>(node) { + } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) { StructKind::Tuple(pfl) } else { StructKind::Unit diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9c5789701..07cc3e0db 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -607,7 +607,7 @@ pub enum Expr { BlockExpr(BlockExpr), ReturnExpr(ReturnExpr), MatchExpr(MatchExpr), - StructLit(StructLit), + RecordLit(RecordLit), CallExpr(CallExpr), IndexExpr(IndexExpr), MethodCallExpr(MethodCallExpr), @@ -698,9 +698,9 @@ impl From for Expr { Expr::MatchExpr(node) } } -impl From for Expr { - fn from(node: StructLit) -> Expr { - Expr::StructLit(node) +impl From for Expr { + fn from(node: RecordLit) -> Expr { + Expr::RecordLit(node) } } impl From for Expr { @@ -778,7 +778,7 @@ impl AstNode for Expr { match kind { TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL - | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR + | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => { true @@ -803,7 +803,7 @@ impl AstNode for Expr { BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }), RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }), MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }), - STRUCT_LIT => Expr::StructLit(StructLit { syntax }), + RECORD_LIT => Expr::RecordLit(RecordLit { syntax }), CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }), @@ -839,7 +839,7 @@ impl AstNode for Expr { Expr::BlockExpr(it) => &it.syntax, Expr::ReturnExpr(it) => &it.syntax, Expr::MatchExpr(it) => &it.syntax, - Expr::StructLit(it) => &it.syntax, + Expr::RecordLit(it) => &it.syntax, Expr::CallExpr(it) => &it.syntax, Expr::IndexExpr(it) => &it.syntax, Expr::MethodCallExpr(it) => &it.syntax, @@ -946,64 +946,6 @@ impl FieldExpr { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FieldPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for FieldPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FIELD_PAT => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl ast::NameOwner for FieldPat {} -impl FieldPat { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FieldPatList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for FieldPatList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FIELD_PAT_LIST => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl FieldPatList { - pub fn field_pats(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn bind_pats(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnDef { pub(crate) syntax: SyntaxNode, } @@ -1942,121 +1884,6 @@ impl AstNode for NameRef { } impl NameRef {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NamedField { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NamedField { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAMED_FIELD => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl NamedField { - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NamedFieldDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NamedFieldDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAMED_FIELD_DEF => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl ast::VisibilityOwner for NamedFieldDef {} -impl ast::NameOwner for NamedFieldDef {} -impl ast::AttrsOwner for NamedFieldDef {} -impl ast::DocCommentsOwner for NamedFieldDef {} -impl ast::TypeAscriptionOwner for NamedFieldDef {} -impl NamedFieldDef {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NamedFieldDefList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NamedFieldDefList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAMED_FIELD_DEF_LIST => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl NamedFieldDefList { - pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NamedFieldList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NamedFieldList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAMED_FIELD_LIST => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl NamedFieldList { - pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn spread(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NeverType { pub(crate) syntax: SyntaxNode, } @@ -2239,7 +2066,7 @@ pub enum Pat { BindPat(BindPat), PlaceholderPat(PlaceholderPat), PathPat(PathPat), - StructPat(StructPat), + RecordPat(RecordPat), TupleStructPat(TupleStructPat), TuplePat(TuplePat), SlicePat(SlicePat), @@ -2266,9 +2093,9 @@ impl From for Pat { Pat::PathPat(node) } } -impl From for Pat { - fn from(node: StructPat) -> Pat { - Pat::StructPat(node) +impl From for Pat { + fn from(node: RecordPat) -> Pat { + Pat::RecordPat(node) } } impl From for Pat { @@ -2299,7 +2126,7 @@ impl From for Pat { impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT + REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, _ => false, } @@ -2310,7 +2137,7 @@ impl AstNode for Pat { BIND_PAT => Pat::BindPat(BindPat { syntax }), PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), PATH_PAT => Pat::PathPat(PathPat { syntax }), - STRUCT_PAT => Pat::StructPat(StructPat { syntax }), + RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), SLICE_PAT => Pat::SlicePat(SlicePat { syntax }), @@ -2326,7 +2153,7 @@ impl AstNode for Pat { Pat::BindPat(it) => &it.syntax, Pat::PlaceholderPat(it) => &it.syntax, Pat::PathPat(it) => &it.syntax, - Pat::StructPat(it) => &it.syntax, + Pat::RecordPat(it) => &it.syntax, Pat::TupleStructPat(it) => &it.syntax, Pat::TuplePat(it) => &it.syntax, Pat::SlicePat(it) => &it.syntax, @@ -2551,13 +2378,13 @@ impl PointerType { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PosFieldDef { +pub struct PrefixExpr { pub(crate) syntax: SyntaxNode, } -impl AstNode for PosFieldDef { +impl AstNode for PrefixExpr { fn can_cast(kind: SyntaxKind) -> bool { match kind { - POS_FIELD_DEF => true, + PREFIX_EXPR => true, _ => false, } } @@ -2572,21 +2399,19 @@ impl AstNode for PosFieldDef { &self.syntax } } -impl ast::VisibilityOwner for PosFieldDef {} -impl ast::AttrsOwner for PosFieldDef {} -impl PosFieldDef { - pub fn type_ref(&self) -> Option { +impl PrefixExpr { + pub fn expr(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PosFieldDefList { +pub struct RangeExpr { pub(crate) syntax: SyntaxNode, } -impl AstNode for PosFieldDefList { +impl AstNode for RangeExpr { fn can_cast(kind: SyntaxKind) -> bool { match kind { - POS_FIELD_DEF_LIST => true, + RANGE_EXPR => true, _ => false, } } @@ -2601,19 +2426,38 @@ impl AstNode for PosFieldDefList { &self.syntax } } -impl PosFieldDefList { - pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) +impl RangeExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RangePat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RangePat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RANGE_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax } } +impl RangePat {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PrefixExpr { +pub struct RecordField { pub(crate) syntax: SyntaxNode, } -impl AstNode for PrefixExpr { +impl AstNode for RecordField { fn can_cast(kind: SyntaxKind) -> bool { match kind { - PREFIX_EXPR => true, + RECORD_FIELD => true, _ => false, } } @@ -2628,19 +2472,22 @@ impl AstNode for PrefixExpr { &self.syntax } } -impl PrefixExpr { +impl RecordField { + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } pub fn expr(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RangeExpr { +pub struct RecordFieldDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for RangeExpr { +impl AstNode for RecordFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - RANGE_EXPR => true, + RECORD_FIELD_DEF => true, _ => false, } } @@ -2655,15 +2502,20 @@ impl AstNode for RangeExpr { &self.syntax } } -impl RangeExpr {} +impl ast::VisibilityOwner for RecordFieldDef {} +impl ast::NameOwner for RecordFieldDef {} +impl ast::AttrsOwner for RecordFieldDef {} +impl ast::DocCommentsOwner for RecordFieldDef {} +impl ast::TypeAscriptionOwner for RecordFieldDef {} +impl RecordFieldDef {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RangePat { +pub struct RecordFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for RangePat { +impl AstNode for RecordFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - RANGE_PAT => true, + RECORD_FIELD_DEF_LIST => true, _ => false, } } @@ -2678,7 +2530,159 @@ impl AstNode for RangePat { &self.syntax } } -impl RangePat {} +impl RecordFieldDefList { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RecordFieldList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordFieldList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_FIELD_LIST => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl RecordFieldList { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn spread(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RecordFieldPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordFieldPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_FIELD_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl ast::NameOwner for RecordFieldPat {} +impl RecordFieldPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RecordFieldPatList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordFieldPatList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_FIELD_PAT_LIST => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl RecordFieldPatList { + pub fn record_field_pats(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn bind_pats(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RecordLit { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordLit { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_LIT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl RecordLit { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn record_field_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RecordPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl RecordPat { + pub fn record_field_pat_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RefExpr { pub(crate) syntax: SyntaxNode, @@ -3018,13 +3022,13 @@ impl ast::AttrsOwner for StructDef {} impl ast::DocCommentsOwner for StructDef {} impl StructDef {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StructLit { +pub struct TokenTree { pub(crate) syntax: SyntaxNode, } -impl AstNode for StructLit { +impl AstNode for TokenTree { fn can_cast(kind: SyntaxKind) -> bool { match kind { - STRUCT_LIT => true, + TOKEN_TREE => true, _ => false, } } @@ -3039,22 +3043,15 @@ impl AstNode for StructLit { &self.syntax } } -impl StructLit { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn named_field_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} +impl TokenTree {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StructPat { +pub struct TraitDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for StructPat { +impl AstNode for TraitDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - STRUCT_PAT => true, + TRAIT_DEF => true, _ => false, } } @@ -3069,22 +3066,25 @@ impl AstNode for StructPat { &self.syntax } } -impl StructPat { - pub fn field_pat_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn path(&self) -> Option { +impl ast::VisibilityOwner for TraitDef {} +impl ast::NameOwner for TraitDef {} +impl ast::AttrsOwner for TraitDef {} +impl ast::DocCommentsOwner for TraitDef {} +impl ast::TypeParamsOwner for TraitDef {} +impl ast::TypeBoundsOwner for TraitDef {} +impl TraitDef { + pub fn item_list(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TokenTree { +pub struct TryBlockExpr { pub(crate) syntax: SyntaxNode, } -impl AstNode for TokenTree { +impl AstNode for TryBlockExpr { fn can_cast(kind: SyntaxKind) -> bool { match kind { - TOKEN_TREE => true, + TRY_BLOCK_EXPR => true, _ => false, } } @@ -3099,15 +3099,16 @@ impl AstNode for TokenTree { &self.syntax } } -impl TokenTree {} +impl ast::TryBlockBodyOwner for TryBlockExpr {} +impl TryBlockExpr {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TraitDef { +pub struct TryExpr { pub(crate) syntax: SyntaxNode, } -impl AstNode for TraitDef { +impl AstNode for TryExpr { fn can_cast(kind: SyntaxKind) -> bool { match kind { - TRAIT_DEF => true, + TRY_EXPR => true, _ => false, } } @@ -3122,25 +3123,19 @@ impl AstNode for TraitDef { &self.syntax } } -impl ast::VisibilityOwner for TraitDef {} -impl ast::NameOwner for TraitDef {} -impl ast::AttrsOwner for TraitDef {} -impl ast::DocCommentsOwner for TraitDef {} -impl ast::TypeParamsOwner for TraitDef {} -impl ast::TypeBoundsOwner for TraitDef {} -impl TraitDef { - pub fn item_list(&self) -> Option { +impl TryExpr { + pub fn expr(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TryBlockExpr { +pub struct TupleExpr { pub(crate) syntax: SyntaxNode, } -impl AstNode for TryBlockExpr { +impl AstNode for TupleExpr { fn can_cast(kind: SyntaxKind) -> bool { match kind { - TRY_BLOCK_EXPR => true, + TUPLE_EXPR => true, _ => false, } } @@ -3155,16 +3150,19 @@ impl AstNode for TryBlockExpr { &self.syntax } } -impl ast::TryBlockBodyOwner for TryBlockExpr {} -impl TryBlockExpr {} +impl TupleExpr { + pub fn exprs(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TryExpr { +pub struct TupleFieldDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for TryExpr { +impl AstNode for TupleFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - TRY_EXPR => true, + TUPLE_FIELD_DEF => true, _ => false, } } @@ -3179,19 +3177,21 @@ impl AstNode for TryExpr { &self.syntax } } -impl TryExpr { - pub fn expr(&self) -> Option { +impl ast::VisibilityOwner for TupleFieldDef {} +impl ast::AttrsOwner for TupleFieldDef {} +impl TupleFieldDef { + pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleExpr { +pub struct TupleFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for TupleExpr { +impl AstNode for TupleFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - TUPLE_EXPR => true, + TUPLE_FIELD_DEF_LIST => true, _ => false, } } @@ -3206,8 +3206,8 @@ impl AstNode for TupleExpr { &self.syntax } } -impl TupleExpr { - pub fn exprs(&self) -> AstChildren { +impl TupleFieldDefList { + pub fn fields(&self) -> AstChildren { AstChildren::new(&self.syntax) } } diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 26efeeba9..4659192cd 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -161,9 +161,9 @@ Grammar( "BIND_PAT", "PLACEHOLDER_PAT", "PATH_PAT", - "STRUCT_PAT", - "FIELD_PAT_LIST", - "FIELD_PAT", + "RECORD_PAT", + "RECORD_FIELD_PAT_LIST", + "RECORD_FIELD_PAT", "TUPLE_STRUCT_PAT", "TUPLE_PAT", "SLICE_PAT", @@ -190,9 +190,9 @@ Grammar( "MATCH_ARM_LIST", "MATCH_ARM", "MATCH_GUARD", - "STRUCT_LIT", - "NAMED_FIELD_LIST", - "NAMED_FIELD", + "RECORD_LIT", + "RECORD_FIELD_LIST", + "RECORD_FIELD", "TRY_BLOCK_EXPR", "BOX_EXPR", @@ -216,10 +216,10 @@ Grammar( "EXTERN_BLOCK", "EXTERN_ITEM_LIST", "ENUM_VARIANT", - "NAMED_FIELD_DEF_LIST", - "NAMED_FIELD_DEF", - "POS_FIELD_DEF_LIST", - "POS_FIELD_DEF", + "RECORD_FIELD_DEF_LIST", + "RECORD_FIELD_DEF", + "TUPLE_FIELD_DEF_LIST", + "TUPLE_FIELD_DEF", "ENUM_VARIANT_LIST", "ITEM_LIST", "ATTR", @@ -286,8 +286,8 @@ Grammar( "DocCommentsOwner" ] ), - "NamedFieldDefList": (collections: [("fields", "NamedFieldDef")]), - "NamedFieldDef": ( + "RecordFieldDefList": (collections: [("fields", "RecordFieldDef")]), + "RecordFieldDef": ( traits: [ "VisibilityOwner", "NameOwner", @@ -296,8 +296,8 @@ Grammar( "TypeAscriptionOwner" ] ), - "PosFieldDefList": (collections: [("fields", "PosFieldDef")]), - "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), + "TupleFieldDefList": (collections: [("fields", "TupleFieldDef")]), + "TupleFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), "EnumDef": ( traits: [ "VisibilityOwner", "NameOwner", @@ -461,12 +461,12 @@ Grammar( traits: [ "AttrsOwner" ] ), "MatchGuard": (options: ["Expr"]), - "StructLit": (options: ["Path", "NamedFieldList"]), - "NamedFieldList": ( - collections: [ ("fields", "NamedField") ], + "RecordLit": (options: ["Path", "RecordFieldList"]), + "RecordFieldList": ( + collections: [ ("fields", "RecordField") ], options: [["spread", "Expr"]] ), - "NamedField": (options: ["NameRef", "Expr"]), + "RecordField": (options: ["NameRef", "Expr"]), "CallExpr": ( traits: ["ArgListOwner"], options: [ "Expr" ], @@ -504,7 +504,7 @@ Grammar( "BlockExpr", "ReturnExpr", "MatchExpr", - "StructLit", + "RecordLit", "CallExpr", "IndexExpr", "MethodCallExpr", @@ -529,14 +529,14 @@ Grammar( ), "PlaceholderPat": (), "PathPat": ( options: [ "Path" ] ), - "StructPat": ( options: ["FieldPatList", "Path"] ), - "FieldPatList": ( + "RecordPat": ( options: ["RecordFieldPatList", "Path"] ), + "RecordFieldPatList": ( collections: [ - ("field_pats", "FieldPat"), + ("record_field_pats", "RecordFieldPat"), ("bind_pats", "BindPat"), ] ), - "FieldPat": ( + "RecordFieldPat": ( traits: ["NameOwner"], options: ["Pat"] ), @@ -555,7 +555,7 @@ Grammar( "BindPat", "PlaceholderPat", "PathPat", - "StructPat", + "RecordPat", "TupleStructPat", "TuplePat", "SlicePat", diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index bf1b35c95..f59c559e9 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs @@ -145,7 +145,7 @@ fn n_attached_trivias<'a>( ) -> usize { match kind { CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF | TRAIT_DEF - | MODULE | NAMED_FIELD_DEF => { + | MODULE | RECORD_FIELD_DEF => { let mut res = 0; for (i, (kind, text)) in trivias.enumerate() { match kind { diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 8665c8976..d24660ac3 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -80,7 +80,7 @@ fn test_local_syntax_ptr() { use crate::{ast, AstNode, SourceFile}; let file = SourceFile::parse("struct Foo { f: u32, }").ok().unwrap(); - let field = file.syntax().descendants().find_map(ast::NamedFieldDef::cast).unwrap(); + let field = file.syntax().descendants().find_map(ast::RecordFieldDef::cast).unwrap(); let ptr = SyntaxNodePtr::new(field.syntax()); let field_syntax = ptr.to_node(file.syntax()); assert_eq!(field.syntax(), &field_syntax); diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index a8c789e0c..ee8797410 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -99,7 +99,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec { .visit::(validate_literal) .visit::(block::validate_block_node) .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) - .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) + .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) .accept(&node); } errors -- cgit v1.2.3