From 084bd304f304e674fc3d5b132daf8a9f975064c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 3 Jan 2020 20:37:02 +0100 Subject: Switch ast declaration from ron to a macro --- crates/ra_syntax/src/ast/generated.rs | 3060 ++++++++++++++++----------------- crates/ra_syntax/src/grammar.ron | 730 -------- 2 files changed, 1526 insertions(+), 2264 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index e64c83d33..2eb4b14d2 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -6,13 +6,13 @@ use crate::{ SyntaxNode, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Alias { +pub struct SourceFile { pub(crate) syntax: SyntaxNode, } -impl AstNode for Alias { +impl AstNode for SourceFile { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ALIAS => true, + SOURCE_FILE => true, _ => false, } } @@ -27,16 +27,21 @@ impl AstNode for Alias { &self.syntax } } -impl ast::NameOwner for Alias {} -impl Alias {} +impl ast::ModuleItemOwner for SourceFile {} +impl ast::FnDefOwner for SourceFile {} +impl SourceFile { + pub fn modules(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArgList { +pub struct FnDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for ArgList { +impl AstNode for FnDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ARG_LIST => true, + FN_DEF => true, _ => false, } } @@ -51,19 +56,30 @@ impl AstNode for ArgList { &self.syntax } } -impl ArgList { - pub fn args(&self) -> AstChildren { - AstChildren::new(&self.syntax) +impl ast::VisibilityOwner for FnDef {} +impl ast::NameOwner for FnDef {} +impl ast::TypeParamsOwner for FnDef {} +impl ast::DocCommentsOwner for FnDef {} +impl ast::AttrsOwner for FnDef {} +impl FnDef { + pub fn param_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn ret_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn body(&self) -> Option { + AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayExpr { +pub struct RetType { pub(crate) syntax: SyntaxNode, } -impl AstNode for ArrayExpr { +impl AstNode for RetType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ARRAY_EXPR => true, + RET_TYPE => true, _ => false, } } @@ -78,19 +94,19 @@ impl AstNode for ArrayExpr { &self.syntax } } -impl ArrayExpr { - pub fn exprs(&self) -> AstChildren { - AstChildren::new(&self.syntax) +impl RetType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayType { +pub struct StructDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for ArrayType { +impl AstNode for StructDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ARRAY_TYPE => true, + STRUCT_DEF => true, _ => false, } } @@ -105,22 +121,20 @@ impl AstNode for ArrayType { &self.syntax } } -impl ArrayType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} +impl ast::VisibilityOwner for StructDef {} +impl ast::NameOwner for StructDef {} +impl ast::TypeParamsOwner for StructDef {} +impl ast::AttrsOwner for StructDef {} +impl ast::DocCommentsOwner for StructDef {} +impl StructDef {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct AssocTypeArg { +pub struct UnionDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for AssocTypeArg { +impl AstNode for UnionDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ASSOC_TYPE_ARG => true, + UNION_DEF => true, _ => false, } } @@ -135,22 +149,24 @@ impl AstNode for AssocTypeArg { &self.syntax } } -impl AssocTypeArg { - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn type_ref(&self) -> Option { +impl ast::VisibilityOwner for UnionDef {} +impl ast::NameOwner for UnionDef {} +impl ast::TypeParamsOwner for UnionDef {} +impl ast::AttrsOwner for UnionDef {} +impl ast::DocCommentsOwner for UnionDef {} +impl UnionDef { + pub fn record_field_def_list(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Attr { +pub struct RecordFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for Attr { +impl AstNode for RecordFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ATTR => true, + RECORD_FIELD_DEF_LIST => true, _ => false, } } @@ -165,60 +181,47 @@ impl AstNode for Attr { &self.syntax } } -impl Attr { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn input(&self) -> Option { - AstChildren::new(&self.syntax).next() +impl RecordFieldDefList { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum AttrInput { - Literal(Literal), - TokenTree(TokenTree), -} -impl From for AttrInput { - fn from(node: Literal) -> AttrInput { - AttrInput::Literal(node) - } -} -impl From for AttrInput { - fn from(node: TokenTree) -> AttrInput { - AttrInput::TokenTree(node) - } +pub struct RecordFieldDef { + pub(crate) syntax: SyntaxNode, } -impl AstNode for AttrInput { +impl AstNode for RecordFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - LITERAL | TOKEN_TREE => true, + RECORD_FIELD_DEF => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - LITERAL => AttrInput::Literal(Literal { syntax }), - TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }), - _ => return None, - }; - Some(res) + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } } fn syntax(&self) -> &SyntaxNode { - match self { - AttrInput::Literal(it) => &it.syntax, - AttrInput::TokenTree(it) => &it.syntax, - } + &self.syntax } } -impl AttrInput {} +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 AwaitExpr { +pub struct TupleFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for AwaitExpr { +impl AstNode for TupleFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - AWAIT_EXPR => true, + TUPLE_FIELD_DEF_LIST => true, _ => false, } } @@ -233,19 +236,19 @@ impl AstNode for AwaitExpr { &self.syntax } } -impl AwaitExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() +impl TupleFieldDefList { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BinExpr { +pub struct TupleFieldDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for BinExpr { +impl AstNode for TupleFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BIN_EXPR => true, + TUPLE_FIELD_DEF => true, _ => false, } } @@ -260,15 +263,21 @@ impl AstNode for BinExpr { &self.syntax } } -impl BinExpr {} +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 BindPat { +pub struct EnumDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for BindPat { +impl AstNode for EnumDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BIND_PAT => true, + ENUM_DEF => true, _ => false, } } @@ -283,20 +292,24 @@ impl AstNode for BindPat { &self.syntax } } -impl ast::NameOwner for BindPat {} -impl BindPat { - pub fn pat(&self) -> Option { +impl ast::VisibilityOwner for EnumDef {} +impl ast::NameOwner for EnumDef {} +impl ast::TypeParamsOwner for EnumDef {} +impl ast::AttrsOwner for EnumDef {} +impl ast::DocCommentsOwner for EnumDef {} +impl EnumDef { + pub fn variant_list(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Block { +pub struct EnumVariantList { pub(crate) syntax: SyntaxNode, } -impl AstNode for Block { +impl AstNode for EnumVariantList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BLOCK => true, + ENUM_VARIANT_LIST => true, _ => false, } } @@ -311,24 +324,19 @@ impl AstNode for Block { &self.syntax } } -impl ast::AttrsOwner for Block {} -impl ast::ModuleItemOwner for Block {} -impl Block { - pub fn statements(&self) -> AstChildren { +impl EnumVariantList { + pub fn variants(&self) -> AstChildren { AstChildren::new(&self.syntax) } - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BlockExpr { +pub struct EnumVariant { pub(crate) syntax: SyntaxNode, } -impl AstNode for BlockExpr { +impl AstNode for EnumVariant { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BLOCK_EXPR => true, + ENUM_VARIANT => true, _ => false, } } @@ -343,19 +351,22 @@ impl AstNode for BlockExpr { &self.syntax } } -impl BlockExpr { - pub fn block(&self) -> Option { +impl ast::NameOwner for EnumVariant {} +impl ast::DocCommentsOwner for EnumVariant {} +impl ast::AttrsOwner for EnumVariant {} +impl EnumVariant { + pub fn expr(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BoxExpr { +pub struct TraitDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for BoxExpr { +impl AstNode for TraitDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BOX_EXPR => true, + TRAIT_DEF => true, _ => false, } } @@ -370,19 +381,25 @@ impl AstNode for BoxExpr { &self.syntax } } -impl BoxExpr { - pub fn expr(&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 BoxPat { +pub struct Module { pub(crate) syntax: SyntaxNode, } -impl AstNode for BoxPat { +impl AstNode for Module { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BOX_PAT => true, + MODULE => true, _ => false, } } @@ -397,19 +414,23 @@ impl AstNode for BoxPat { &self.syntax } } -impl BoxPat { - pub fn pat(&self) -> Option { +impl ast::VisibilityOwner for Module {} +impl ast::NameOwner for Module {} +impl ast::AttrsOwner for Module {} +impl ast::DocCommentsOwner for Module {} +impl Module { + pub fn item_list(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BreakExpr { +pub struct ItemList { pub(crate) syntax: SyntaxNode, } -impl AstNode for BreakExpr { +impl AstNode for ItemList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BREAK_EXPR => true, + ITEM_LIST => true, _ => false, } } @@ -424,19 +445,21 @@ impl AstNode for BreakExpr { &self.syntax } } -impl BreakExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CallExpr { +impl ast::FnDefOwner for ItemList {} +impl ast::ModuleItemOwner for ItemList {} +impl ItemList { + pub fn impl_items(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConstDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for CallExpr { +impl AstNode for ConstDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CALL_EXPR => true, + CONST_DEF => true, _ => false, } } @@ -451,20 +474,25 @@ impl AstNode for CallExpr { &self.syntax } } -impl ast::ArgListOwner for CallExpr {} -impl CallExpr { - pub fn expr(&self) -> Option { +impl ast::VisibilityOwner for ConstDef {} +impl ast::NameOwner for ConstDef {} +impl ast::TypeParamsOwner for ConstDef {} +impl ast::AttrsOwner for ConstDef {} +impl ast::DocCommentsOwner for ConstDef {} +impl ast::TypeAscriptionOwner for ConstDef {} +impl ConstDef { + pub fn body(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CastExpr { +pub struct StaticDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for CastExpr { +impl AstNode for StaticDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CAST_EXPR => true, + STATIC_DEF => true, _ => false, } } @@ -479,22 +507,25 @@ impl AstNode for CastExpr { &self.syntax } } -impl CastExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn type_ref(&self) -> Option { +impl ast::VisibilityOwner for StaticDef {} +impl ast::NameOwner for StaticDef {} +impl ast::TypeParamsOwner for StaticDef {} +impl ast::AttrsOwner for StaticDef {} +impl ast::DocCommentsOwner for StaticDef {} +impl ast::TypeAscriptionOwner for StaticDef {} +impl StaticDef { + pub fn body(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Condition { +pub struct TypeAliasDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for Condition { +impl AstNode for TypeAliasDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONDITION => true, + TYPE_ALIAS_DEF => true, _ => false, } } @@ -509,22 +540,25 @@ impl AstNode for Condition { &self.syntax } } -impl Condition { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn expr(&self) -> Option { +impl ast::VisibilityOwner for TypeAliasDef {} +impl ast::NameOwner for TypeAliasDef {} +impl ast::TypeParamsOwner for TypeAliasDef {} +impl ast::AttrsOwner for TypeAliasDef {} +impl ast::DocCommentsOwner for TypeAliasDef {} +impl ast::TypeBoundsOwner for TypeAliasDef {} +impl TypeAliasDef { + pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConstDef { +pub struct ImplBlock { pub(crate) syntax: SyntaxNode, } -impl AstNode for ConstDef { +impl AstNode for ImplBlock { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONST_DEF => true, + IMPL_BLOCK => true, _ => false, } } @@ -539,25 +573,21 @@ impl AstNode for ConstDef { &self.syntax } } -impl ast::VisibilityOwner for ConstDef {} -impl ast::NameOwner for ConstDef {} -impl ast::TypeParamsOwner for ConstDef {} -impl ast::AttrsOwner for ConstDef {} -impl ast::DocCommentsOwner for ConstDef {} -impl ast::TypeAscriptionOwner for ConstDef {} -impl ConstDef { - pub fn body(&self) -> Option { +impl ast::TypeParamsOwner for ImplBlock {} +impl ast::AttrsOwner for ImplBlock {} +impl ImplBlock { + pub fn item_list(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConstParam { +pub struct ParenType { pub(crate) syntax: SyntaxNode, } -impl AstNode for ConstParam { +impl AstNode for ParenType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONST_PARAM => true, + PAREN_TYPE => true, _ => false, } } @@ -572,22 +602,19 @@ impl AstNode for ConstParam { &self.syntax } } -impl ast::NameOwner for ConstParam {} -impl ast::AttrsOwner for ConstParam {} -impl ast::TypeAscriptionOwner for ConstParam {} -impl ConstParam { - pub fn default_val(&self) -> Option { +impl ParenType { + pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ContinueExpr { +pub struct TupleType { pub(crate) syntax: SyntaxNode, } -impl AstNode for ContinueExpr { +impl AstNode for TupleType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONTINUE_EXPR => true, + TUPLE_TYPE => true, _ => false, } } @@ -602,15 +629,19 @@ impl AstNode for ContinueExpr { &self.syntax } } -impl ContinueExpr {} +impl TupleType { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DotDotPat { +pub struct NeverType { pub(crate) syntax: SyntaxNode, } -impl AstNode for DotDotPat { +impl AstNode for NeverType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - DOT_DOT_PAT => true, + NEVER_TYPE => true, _ => false, } } @@ -625,15 +656,15 @@ impl AstNode for DotDotPat { &self.syntax } } -impl DotDotPat {} +impl NeverType {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynTraitType { +pub struct PathType { pub(crate) syntax: SyntaxNode, } -impl AstNode for DynTraitType { +impl AstNode for PathType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - DYN_TRAIT_TYPE => true, + PATH_TYPE => true, _ => false, } } @@ -648,16 +679,19 @@ impl AstNode for DynTraitType { &self.syntax } } -impl ast::TypeBoundsOwner for DynTraitType {} -impl DynTraitType {} +impl PathType { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumDef { +pub struct PointerType { pub(crate) syntax: SyntaxNode, } -impl AstNode for EnumDef { +impl AstNode for PointerType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ENUM_DEF => true, + POINTER_TYPE => true, _ => false, } } @@ -672,24 +706,19 @@ impl AstNode for EnumDef { &self.syntax } } -impl ast::VisibilityOwner for EnumDef {} -impl ast::NameOwner for EnumDef {} -impl ast::TypeParamsOwner for EnumDef {} -impl ast::AttrsOwner for EnumDef {} -impl ast::DocCommentsOwner for EnumDef {} -impl EnumDef { - pub fn variant_list(&self) -> Option { +impl PointerType { + pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumVariant { +pub struct ArrayType { pub(crate) syntax: SyntaxNode, } -impl AstNode for EnumVariant { +impl AstNode for ArrayType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ENUM_VARIANT => true, + ARRAY_TYPE => true, _ => false, } } @@ -704,22 +733,22 @@ impl AstNode for EnumVariant { &self.syntax } } -impl ast::NameOwner for EnumVariant {} -impl ast::DocCommentsOwner for EnumVariant {} -impl ast::AttrsOwner for EnumVariant {} -impl EnumVariant { +impl ArrayType { + pub fn type_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 EnumVariantList { +pub struct SliceType { pub(crate) syntax: SyntaxNode, } -impl AstNode for EnumVariantList { +impl AstNode for SliceType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ENUM_VARIANT_LIST => true, + SLICE_TYPE => true, _ => false, } } @@ -734,294 +763,69 @@ impl AstNode for EnumVariantList { &self.syntax } } -impl EnumVariantList { - pub fn variants(&self) -> AstChildren { - AstChildren::new(&self.syntax) +impl SliceType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Expr { - TupleExpr(TupleExpr), - ArrayExpr(ArrayExpr), - ParenExpr(ParenExpr), - PathExpr(PathExpr), - LambdaExpr(LambdaExpr), - IfExpr(IfExpr), - LoopExpr(LoopExpr), - ForExpr(ForExpr), - WhileExpr(WhileExpr), - ContinueExpr(ContinueExpr), - BreakExpr(BreakExpr), - Label(Label), - BlockExpr(BlockExpr), - ReturnExpr(ReturnExpr), - MatchExpr(MatchExpr), - RecordLit(RecordLit), - CallExpr(CallExpr), - IndexExpr(IndexExpr), - MethodCallExpr(MethodCallExpr), - FieldExpr(FieldExpr), - AwaitExpr(AwaitExpr), - TryExpr(TryExpr), - TryBlockExpr(TryBlockExpr), - CastExpr(CastExpr), - RefExpr(RefExpr), - PrefixExpr(PrefixExpr), - RangeExpr(RangeExpr), - BinExpr(BinExpr), - Literal(Literal), - MacroCall(MacroCall), - BoxExpr(BoxExpr), -} -impl From for Expr { - fn from(node: TupleExpr) -> Expr { - Expr::TupleExpr(node) - } +pub struct ReferenceType { + pub(crate) syntax: SyntaxNode, } -impl From for Expr { - fn from(node: ArrayExpr) -> Expr { - Expr::ArrayExpr(node) +impl AstNode for ReferenceType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + REFERENCE_TYPE => true, + _ => false, + } } -} -impl From for Expr { - fn from(node: ParenExpr) -> Expr { - Expr::ParenExpr(node) + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } } -} -impl From for Expr { - fn from(node: PathExpr) -> Expr { - Expr::PathExpr(node) + fn syntax(&self) -> &SyntaxNode { + &self.syntax } } -impl From for Expr { - fn from(node: LambdaExpr) -> Expr { - Expr::LambdaExpr(node) +impl ReferenceType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() } } -impl From for Expr { - fn from(node: IfExpr) -> Expr { - Expr::IfExpr(node) - } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PlaceholderType { + pub(crate) syntax: SyntaxNode, } -impl From for Expr { - fn from(node: LoopExpr) -> Expr { - Expr::LoopExpr(node) - } -} -impl From for Expr { - fn from(node: ForExpr) -> Expr { - Expr::ForExpr(node) - } -} -impl From for Expr { - fn from(node: WhileExpr) -> Expr { - Expr::WhileExpr(node) - } -} -impl From for Expr { - fn from(node: ContinueExpr) -> Expr { - Expr::ContinueExpr(node) - } -} -impl From for Expr { - fn from(node: BreakExpr) -> Expr { - Expr::BreakExpr(node) - } -} -impl From