From ddf08daddf7e86d67e8d2e5596f8013b376dd522 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:46:07 +0200 Subject: Fix const arguments grammar --- crates/ra_syntax/src/ast/generated/nodes.rs | 663 ++++++++++++++-------------- 1 file changed, 331 insertions(+), 332 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 132c2ae8c..97a882bf0 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -106,8 +106,7 @@ pub struct ConstArg { pub(crate) syntax: SyntaxNode, } impl ConstArg { - pub fn literal(&self) -> Option { support::child(&self.syntax) } - pub fn block_expr(&self) -> Option { support::child(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeBoundList { @@ -117,23 +116,6 @@ impl TypeBoundList { pub fn bounds(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Literal { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for Literal {} -impl Literal {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BlockExpr { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for BlockExpr {} -impl BlockExpr { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SourceFile { pub(crate) syntax: SyntaxNode, } @@ -437,6 +419,17 @@ impl WhereClause { pub fn predicates(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BlockExpr { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for BlockExpr {} +impl BlockExpr { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SelfParam { pub(crate) syntax: SyntaxNode, } @@ -590,6 +583,12 @@ impl WherePred { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Literal { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for Literal {} +impl Literal {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TokenTree { pub(crate) syntax: SyntaxNode, } @@ -1292,6 +1291,39 @@ pub enum Type { TupleType(TupleType), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Expr { + ArrayExpr(ArrayExpr), + AwaitExpr(AwaitExpr), + BinExpr(BinExpr), + BlockExpr(BlockExpr), + BoxExpr(BoxExpr), + BreakExpr(BreakExpr), + CallExpr(CallExpr), + CastExpr(CastExpr), + ClosureExpr(ClosureExpr), + ContinueExpr(ContinueExpr), + EffectExpr(EffectExpr), + FieldExpr(FieldExpr), + ForExpr(ForExpr), + IfExpr(IfExpr), + IndexExpr(IndexExpr), + Literal(Literal), + LoopExpr(LoopExpr), + MacroCall(MacroCall), + MatchExpr(MatchExpr), + MethodCallExpr(MethodCallExpr), + ParenExpr(ParenExpr), + PathExpr(PathExpr), + PrefixExpr(PrefixExpr), + RangeExpr(RangeExpr), + RecordExpr(RecordExpr), + RefExpr(RefExpr), + ReturnExpr(ReturnExpr), + TryExpr(TryExpr), + TupleExpr(TupleExpr), + WhileExpr(WhileExpr), +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Item { Const(Const), Enum(Enum), @@ -1333,39 +1365,6 @@ pub enum FieldList { TupleFieldList(TupleFieldList), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Expr { - ArrayExpr(ArrayExpr), - AwaitExpr(AwaitExpr), - BinExpr(BinExpr), - BlockExpr(BlockExpr), - BoxExpr(BoxExpr), - BreakExpr(BreakExpr), - CallExpr(CallExpr), - CastExpr(CastExpr), - ClosureExpr(ClosureExpr), - ContinueExpr(ContinueExpr), - EffectExpr(EffectExpr), - FieldExpr(FieldExpr), - ForExpr(ForExpr), - IfExpr(IfExpr), - IndexExpr(IndexExpr), - Literal(Literal), - LoopExpr(LoopExpr), - MacroCall(MacroCall), - MatchExpr(MatchExpr), - MethodCallExpr(MethodCallExpr), - ParenExpr(ParenExpr), - PathExpr(PathExpr), - PrefixExpr(PrefixExpr), - RangeExpr(RangeExpr), - RecordExpr(RecordExpr), - RefExpr(RefExpr), - ReturnExpr(ReturnExpr), - TryExpr(TryExpr), - TupleExpr(TupleExpr), - WhileExpr(WhileExpr), -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AdtDef { Enum(Enum), Struct(Struct), @@ -1537,28 +1536,6 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Literal { - fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for BlockExpr { - fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for SourceFile { fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } fn cast(syntax: SyntaxNode) -> Option { @@ -1834,6 +1811,17 @@ impl AstNode for WhereClause { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for BlockExpr { + fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for SelfParam { fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } fn cast(syntax: SyntaxNode) -> Option { @@ -1988,6 +1976,17 @@ impl AstNode for WherePred { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for Literal { + fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for TokenTree { fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } fn cast(syntax: SyntaxNode) -> Option { @@ -2892,265 +2891,53 @@ impl AstNode for Type { } } } -impl From for Item { - fn from(node: Const) -> Item { Item::Const(node) } +impl From for Expr { + fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } } -impl From for Item { - fn from(node: Enum) -> Item { Item::Enum(node) } +impl From for Expr { + fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) } } -impl From for Item { - fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) } +impl From for Expr { + fn from(node: BinExpr) -> Expr { Expr::BinExpr(node) } } -impl From for Item { - fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) } +impl From for Expr { + fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) } } -impl From for Item { - fn from(node: Fn) -> Item { Item::Fn(node) } +impl From for Expr { + fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) } } -impl From for Item { - fn from(node: Impl) -> Item { Item::Impl(node) } +impl From for Expr { + fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) } } -impl From for Item { - fn from(node: MacroCall) -> Item { Item::MacroCall(node) } +impl From for Expr { + fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } } -impl From for Item { - fn from(node: Module) -> Item { Item::Module(node) } +impl From for Expr { + fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } } -impl From for Item { - fn from(node: Static) -> Item { Item::Static(node) } +impl From for Expr { + fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) } } -impl From for Item { - fn from(node: Struct) -> Item { Item::Struct(node) } +impl From for Expr { + fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } } -impl From for Item { - fn from(node: Trait) -> Item { Item::Trait(node) } +impl From for Expr { + fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } } -impl From for Item { - fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) } +impl From for Expr { + fn from(node: FieldExpr) -> Expr { Expr::FieldExpr(node) } } -impl From for Item { - fn from(node: Union) -> Item { Item::Union(node) } +impl From for Expr { + fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) } } -impl From for Item { - fn from(node: Use) -> Item { Item::Use(node) } +impl From for Expr { + fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } } -impl AstNode for Item { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MODULE - | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - CONST => Item::Const(Const { syntax }), - ENUM => Item::Enum(Enum { syntax }), - EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), - EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), - FN => Item::Fn(Fn { syntax }), - IMPL => Item::Impl(Impl { syntax }), - MACRO_CALL => Item::MacroCall(MacroCall { syntax }), - MODULE => Item::Module(Module { syntax }), - STATIC => Item::Static(Static { syntax }), - STRUCT => Item::Struct(Struct { syntax }), - TRAIT => Item::Trait(Trait { syntax }), - TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), - UNION => Item::Union(Union { syntax }), - USE => Item::Use(Use { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - Item::Const(it) => &it.syntax, - Item::Enum(it) => &it.syntax, - Item::ExternBlock(it) => &it.syntax, - Item::ExternCrate(it) => &it.syntax, - Item::Fn(it) => &it.syntax, - Item::Impl(it) => &it.syntax, - Item::MacroCall(it) => &it.syntax, - Item::Module(it) => &it.syntax, - Item::Static(it) => &it.syntax, - Item::Struct(it) => &it.syntax, - Item::Trait(it) => &it.syntax, - Item::TypeAlias(it) => &it.syntax, - Item::Union(it) => &it.syntax, - Item::Use(it) => &it.syntax, - } - } +impl From for Expr { + fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } } -impl From for Pat { - fn from(node: OrPat) -> Pat { Pat::OrPat(node) } -} -impl From for Pat { - fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } -} -impl From for Pat { - fn from(node: RefPat) -> Pat { Pat::RefPat(node) } -} -impl From for Pat { - fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } -} -impl From for Pat { - fn from(node: BindPat) -> Pat { Pat::BindPat(node) } -} -impl From for Pat { - fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } -} -impl From for Pat { - fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) } -} -impl From for Pat { - fn from(node: PathPat) -> Pat { Pat::PathPat(node) } -} -impl From for Pat { - fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } -} -impl From for Pat { - fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } -} -impl From for Pat { - fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } -} -impl From for Pat { - fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } -} -impl From for Pat { - fn from(node: RangePat) -> Pat { Pat::RangePat(node) } -} -impl From for Pat { - fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } -} -impl From for Pat { - fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } -} -impl AstNode for Pat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT - | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT - | LITERAL_PAT | MACRO_PAT => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - OR_PAT => Pat::OrPat(OrPat { syntax }), - PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), - REF_PAT => Pat::RefPat(RefPat { syntax }), - BOX_PAT => Pat::BoxPat(BoxPat { syntax }), - BIND_PAT => Pat::BindPat(BindPat { syntax }), - PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), - DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }), - PATH_PAT => Pat::PathPat(PathPat { 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 }), - RANGE_PAT => Pat::RangePat(RangePat { syntax }), - LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), - MACRO_PAT => Pat::MacroPat(MacroPat { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - Pat::OrPat(it) => &it.syntax, - Pat::ParenPat(it) => &it.syntax, - Pat::RefPat(it) => &it.syntax, - Pat::BoxPat(it) => &it.syntax, - Pat::BindPat(it) => &it.syntax, - Pat::PlaceholderPat(it) => &it.syntax, - Pat::DotDotPat(it) => &it.syntax, - Pat::PathPat(it) => &it.syntax, - Pat::RecordPat(it) => &it.syntax, - Pat::TupleStructPat(it) => &it.syntax, - Pat::TuplePat(it) => &it.syntax, - Pat::SlicePat(it) => &it.syntax, - Pat::RangePat(it) => &it.syntax, - Pat::LiteralPat(it) => &it.syntax, - Pat::MacroPat(it) => &it.syntax, - } - } -} -impl From for FieldList { - fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) } -} -impl From for FieldList { - fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) } -} -impl AstNode for FieldList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }), - TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - FieldList::RecordFieldList(it) => &it.syntax, - FieldList::TupleFieldList(it) => &it.syntax, - } - } -} -impl From for Expr { - fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } -} -impl From for Expr { - fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) } -} -impl From for Expr { - fn from(node: BinExpr) -> Expr { Expr::BinExpr(node) } -} -impl From for Expr { - fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) } -} -impl From for Expr { - fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) } -} -impl From for Expr { - fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) } -} -impl From for Expr { - fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } -} -impl From for Expr { - fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } -} -impl From for Expr { - fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) } -} -impl From for Expr { - fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } -} -impl From for Expr { - fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } -} -impl From for Expr { - fn from(node: FieldExpr) -> Expr { Expr::FieldExpr(node) } -} -impl From for Expr { - fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) } -} -impl From for Expr { - fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } -} -impl From for Expr { - fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } -} -impl From for Expr { - fn from(node: Literal) -> Expr { Expr::Literal(node) } +impl From for Expr { + fn from(node: Literal) -> Expr { Expr::Literal(node) } } impl From for Expr { fn from(node: LoopExpr) -> Expr { Expr::LoopExpr(node) } @@ -3276,6 +3063,218 @@ impl AstNode for Expr { } } } +impl From for Item { + fn from(node: Const) -> Item { Item::Const(node) } +} +impl From for Item { + fn from(node: Enum) -> Item { Item::Enum(node) } +} +impl From for Item { + fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) } +} +impl From for Item { + fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) } +} +impl From for Item { + fn from(node: Fn) -> Item { Item::Fn(node) } +} +impl From for Item { + fn from(node: Impl) -> Item { Item::Impl(node) } +} +impl From for Item { + fn from(node: MacroCall) -> Item { Item::MacroCall(node) } +} +impl From for Item { + fn from(node: Module) -> Item { Item::Module(node) } +} +impl From for Item { + fn from(node: Static) -> Item { Item::Static(node) } +} +impl From for Item { + fn from(node: Struct) -> Item { Item::Struct(node) } +} +impl From for Item { + fn from(node: Trait) -> Item { Item::Trait(node) } +} +impl From for Item { + fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) } +} +impl From for Item { + fn from(node: Union) -> Item { Item::Union(node) } +} +impl From for Item { + fn from(node: Use) -> Item { Item::Use(node) } +} +impl AstNode for Item { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MODULE + | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + CONST => Item::Const(Const { syntax }), + ENUM => Item::Enum(Enum { syntax }), + EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), + EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), + FN => Item::Fn(Fn { syntax }), + IMPL => Item::Impl(Impl { syntax }), + MACRO_CALL => Item::MacroCall(MacroCall { syntax }), + MODULE => Item::Module(Module { syntax }), + STATIC => Item::Static(Static { syntax }), + STRUCT => Item::Struct(Struct { syntax }), + TRAIT => Item::Trait(Trait { syntax }), + TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), + UNION => Item::Union(Union { syntax }), + USE => Item::Use(Use { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + Item::Const(it) => &it.syntax, + Item::Enum(it) => &it.syntax, + Item::ExternBlock(it) => &it.syntax, + Item::ExternCrate(it) => &it.syntax, + Item::Fn(it) => &it.syntax, + Item::Impl(it) => &it.syntax, + Item::MacroCall(it) => &it.syntax, + Item::Module(it) => &it.syntax, + Item::Static(it) => &it.syntax, + Item::Struct(it) => &it.syntax, + Item::Trait(it) => &it.syntax, + Item::TypeAlias(it) => &it.syntax, + Item::Union(it) => &it.syntax, + Item::Use(it) => &it.syntax, + } + } +} +impl From for Pat { + fn from(node: OrPat) -> Pat { Pat::OrPat(node) } +} +impl From for Pat { + fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } +} +impl From for Pat { + fn from(node: RefPat) -> Pat { Pat::RefPat(node) } +} +impl From for Pat { + fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } +} +impl From for Pat { + fn from(node: BindPat) -> Pat { Pat::BindPat(node) } +} +impl From for Pat { + fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +} +impl From for Pat { + fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) } +} +impl From for Pat { + fn from(node: PathPat) -> Pat { Pat::PathPat(node) } +} +impl From for Pat { + fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } +} +impl From for Pat { + fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } +} +impl From for Pat { + fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } +} +impl From for Pat { + fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } +} +impl From for Pat { + fn from(node: RangePat) -> Pat { Pat::RangePat(node) } +} +impl From for Pat { + fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } +} +impl From for Pat { + fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } +} +impl AstNode for Pat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT + | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT + | LITERAL_PAT | MACRO_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + OR_PAT => Pat::OrPat(OrPat { syntax }), + PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), + REF_PAT => Pat::RefPat(RefPat { syntax }), + BOX_PAT => Pat::BoxPat(BoxPat { syntax }), + BIND_PAT => Pat::BindPat(BindPat { syntax }), + PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }), + PATH_PAT => Pat::PathPat(PathPat { 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 }), + RANGE_PAT => Pat::RangePat(RangePat { syntax }), + LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), + MACRO_PAT => Pat::MacroPat(MacroPat { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + Pat::OrPat(it) => &it.syntax, + Pat::ParenPat(it) => &it.syntax, + Pat::RefPat(it) => &it.syntax, + Pat::BoxPat(it) => &it.syntax, + Pat::BindPat(it) => &it.syntax, + Pat::PlaceholderPat(it) => &it.syntax, + Pat::DotDotPat(it) => &it.syntax, + Pat::PathPat(it) => &it.syntax, + Pat::RecordPat(it) => &it.syntax, + Pat::TupleStructPat(it) => &it.syntax, + Pat::TuplePat(it) => &it.syntax, + Pat::SlicePat(it) => &it.syntax, + Pat::RangePat(it) => &it.syntax, + Pat::LiteralPat(it) => &it.syntax, + Pat::MacroPat(it) => &it.syntax, + } + } +} +impl From for FieldList { + fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) } +} +impl From for FieldList { + fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) } +} +impl AstNode for FieldList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }), + TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + FieldList::RecordFieldList(it) => &it.syntax, + FieldList::TupleFieldList(it) => &it.syntax, + } + } +} impl From for AdtDef { fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } } @@ -3432,22 +3431,22 @@ impl std::fmt::Display for Type { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Item { +impl std::fmt::Display for Expr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Pat { +impl std::fmt::Display for Item { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for FieldList { +impl std::fmt::Display for Pat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Expr { +impl std::fmt::Display for FieldList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3537,16 +3536,6 @@ impl std::fmt::Display for TypeBoundList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Literal { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for BlockExpr { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for SourceFile { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3672,6 +3661,11 @@ impl std::fmt::Display for WhereClause { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for BlockExpr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for SelfParam { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3742,6 +3736,11 @@ impl std::fmt::Display for WherePred { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for Literal { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for TokenTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) -- cgit v1.2.3