diff --git a/Cargo.lock b/Cargo.lock index 86e0f45a1bf..9187a913bd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,14 +57,6 @@ dependencies = [ "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "base64" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "base64" version = "0.11.0" @@ -1398,16 +1390,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ron" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rowan" version = "0.8.2" @@ -1772,8 +1754,6 @@ dependencies = [ "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1794,7 +1774,6 @@ dependencies = [ "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" -"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" "checksum bit-vec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" @@ -1915,7 +1894,6 @@ dependencies = [ "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bedde000f40f2921ce439ea165c9c53fd629bfa115140c72e22aceacb4a21954" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5" "checksum rowan 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3eb10a10a48f0f809a217bcf074b85a03dcf79831bae80e7f1a043d0897463e2" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index af2945f571e..262c545e4c8 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -61,46 +61,46 @@ pub enum SyntaxKind { SHR, SHLEQ, SHREQ, - ASYNC_KW, - USE_KW, - FN_KW, - STRUCT_KW, - ENUM_KW, - TRAIT_KW, - IMPL_KW, - DYN_KW, - TRUE_KW, - FALSE_KW, AS_KW, - EXTERN_KW, - CRATE_KW, - MOD_KW, - PUB_KW, - SELF_KW, - SUPER_KW, - IN_KW, - WHERE_KW, - FOR_KW, - LOOP_KW, - WHILE_KW, - CONTINUE_KW, - BREAK_KW, - IF_KW, - ELSE_KW, - MATCH_KW, - CONST_KW, - STATIC_KW, - MUT_KW, - UNSAFE_KW, - TYPE_KW, - REF_KW, - LET_KW, - MOVE_KW, - RETURN_KW, - TRY_KW, - BOX_KW, + ASYNC_KW, AWAIT_KW, + BOX_KW, + BREAK_KW, + CONST_KW, + CONTINUE_KW, + CRATE_KW, + DYN_KW, + ELSE_KW, + ENUM_KW, + EXTERN_KW, + FALSE_KW, + FN_KW, + FOR_KW, + IF_KW, + IMPL_KW, + IN_KW, + LET_KW, + LOOP_KW, MACRO_KW, + MATCH_KW, + MOD_KW, + MOVE_KW, + MUT_KW, + PUB_KW, + REF_KW, + RETURN_KW, + SELF_KW, + STATIC_KW, + STRUCT_KW, + SUPER_KW, + TRAIT_KW, + TRUE_KW, + TRY_KW, + TYPE_KW, + UNSAFE_KW, + USE_KW, + WHERE_KW, + WHILE_KW, AUTO_KW, DEFAULT_KW, EXISTENTIAL_KW, @@ -249,12 +249,12 @@ use self::SyntaxKind::*; impl SyntaxKind { pub fn is_keyword(self) -> bool { match self { - ASYNC_KW | USE_KW | FN_KW | STRUCT_KW | ENUM_KW | TRAIT_KW | IMPL_KW | DYN_KW - | TRUE_KW | FALSE_KW | AS_KW | EXTERN_KW | CRATE_KW | MOD_KW | PUB_KW | SELF_KW - | SUPER_KW | IN_KW | WHERE_KW | FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW - | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW | CONST_KW | STATIC_KW | MUT_KW | UNSAFE_KW - | TYPE_KW | REF_KW | LET_KW | MOVE_KW | RETURN_KW | TRY_KW | BOX_KW | AWAIT_KW - | MACRO_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true, + AS_KW | ASYNC_KW | AWAIT_KW | BOX_KW | BREAK_KW | CONST_KW | CONTINUE_KW | CRATE_KW + | DYN_KW | ELSE_KW | ENUM_KW | EXTERN_KW | FALSE_KW | FN_KW | FOR_KW | IF_KW + | IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW + | MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW + | TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW + | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true, _ => false, } } @@ -278,46 +278,46 @@ impl SyntaxKind { } pub fn from_keyword(ident: &str) -> Option { let kw = match ident { - "async" => ASYNC_KW, - "use" => USE_KW, - "fn" => FN_KW, - "struct" => STRUCT_KW, - "enum" => ENUM_KW, - "trait" => TRAIT_KW, - "impl" => IMPL_KW, - "dyn" => DYN_KW, - "true" => TRUE_KW, - "false" => FALSE_KW, "as" => AS_KW, - "extern" => EXTERN_KW, - "crate" => CRATE_KW, - "mod" => MOD_KW, - "pub" => PUB_KW, - "self" => SELF_KW, - "super" => SUPER_KW, - "in" => IN_KW, - "where" => WHERE_KW, - "for" => FOR_KW, - "loop" => LOOP_KW, - "while" => WHILE_KW, - "continue" => CONTINUE_KW, - "break" => BREAK_KW, - "if" => IF_KW, - "else" => ELSE_KW, - "match" => MATCH_KW, - "const" => CONST_KW, - "static" => STATIC_KW, - "mut" => MUT_KW, - "unsafe" => UNSAFE_KW, - "type" => TYPE_KW, - "ref" => REF_KW, - "let" => LET_KW, - "move" => MOVE_KW, - "return" => RETURN_KW, - "try" => TRY_KW, - "box" => BOX_KW, + "async" => ASYNC_KW, "await" => AWAIT_KW, + "box" => BOX_KW, + "break" => BREAK_KW, + "const" => CONST_KW, + "continue" => CONTINUE_KW, + "crate" => CRATE_KW, + "dyn" => DYN_KW, + "else" => ELSE_KW, + "enum" => ENUM_KW, + "extern" => EXTERN_KW, + "false" => FALSE_KW, + "fn" => FN_KW, + "for" => FOR_KW, + "if" => IF_KW, + "impl" => IMPL_KW, + "in" => IN_KW, + "let" => LET_KW, + "loop" => LOOP_KW, "macro" => MACRO_KW, + "match" => MATCH_KW, + "mod" => MOD_KW, + "move" => MOVE_KW, + "mut" => MUT_KW, + "pub" => PUB_KW, + "ref" => REF_KW, + "return" => RETURN_KW, + "self" => SELF_KW, + "static" => STATIC_KW, + "struct" => STRUCT_KW, + "super" => SUPER_KW, + "trait" => TRAIT_KW, + "true" => TRUE_KW, + "try" => TRY_KW, + "type" => TYPE_KW, + "unsafe" => UNSAFE_KW, + "use" => USE_KW, + "where" => WHERE_KW, + "while" => WHILE_KW, _ => return None, }; Some(kw) @@ -515,126 +515,126 @@ macro_rules! T { ( >>= ) => { $crate::SyntaxKind::SHREQ }; - ( async ) => { - $crate::SyntaxKind::ASYNC_KW - }; - ( use ) => { - $crate::SyntaxKind::USE_KW - }; - ( fn ) => { - $crate::SyntaxKind::FN_KW - }; - ( struct ) => { - $crate::SyntaxKind::STRUCT_KW - }; - ( enum ) => { - $crate::SyntaxKind::ENUM_KW - }; - ( trait ) => { - $crate::SyntaxKind::TRAIT_KW - }; - ( impl ) => { - $crate::SyntaxKind::IMPL_KW - }; - ( dyn ) => { - $crate::SyntaxKind::DYN_KW - }; - ( true ) => { - $crate::SyntaxKind::TRUE_KW - }; - ( false ) => { - $crate::SyntaxKind::FALSE_KW - }; ( as ) => { $crate::SyntaxKind::AS_KW }; - ( extern ) => { - $crate::SyntaxKind::EXTERN_KW - }; - ( crate ) => { - $crate::SyntaxKind::CRATE_KW - }; - ( mod ) => { - $crate::SyntaxKind::MOD_KW - }; - ( pub ) => { - $crate::SyntaxKind::PUB_KW - }; - ( self ) => { - $crate::SyntaxKind::SELF_KW - }; - ( super ) => { - $crate::SyntaxKind::SUPER_KW - }; - ( in ) => { - $crate::SyntaxKind::IN_KW - }; - ( where ) => { - $crate::SyntaxKind::WHERE_KW - }; - ( for ) => { - $crate::SyntaxKind::FOR_KW - }; - ( loop ) => { - $crate::SyntaxKind::LOOP_KW - }; - ( while ) => { - $crate::SyntaxKind::WHILE_KW - }; - ( continue ) => { - $crate::SyntaxKind::CONTINUE_KW - }; - ( break ) => { - $crate::SyntaxKind::BREAK_KW - }; - ( if ) => { - $crate::SyntaxKind::IF_KW - }; - ( else ) => { - $crate::SyntaxKind::ELSE_KW - }; - ( match ) => { - $crate::SyntaxKind::MATCH_KW - }; - ( const ) => { - $crate::SyntaxKind::CONST_KW - }; - ( static ) => { - $crate::SyntaxKind::STATIC_KW - }; - ( mut ) => { - $crate::SyntaxKind::MUT_KW - }; - ( unsafe ) => { - $crate::SyntaxKind::UNSAFE_KW - }; - ( type ) => { - $crate::SyntaxKind::TYPE_KW - }; - ( ref ) => { - $crate::SyntaxKind::REF_KW - }; - ( let ) => { - $crate::SyntaxKind::LET_KW - }; - ( move ) => { - $crate::SyntaxKind::MOVE_KW - }; - ( return ) => { - $crate::SyntaxKind::RETURN_KW - }; - ( try ) => { - $crate::SyntaxKind::TRY_KW - }; - ( box ) => { - $crate::SyntaxKind::BOX_KW + ( async ) => { + $crate::SyntaxKind::ASYNC_KW }; ( await ) => { $crate::SyntaxKind::AWAIT_KW }; + ( box ) => { + $crate::SyntaxKind::BOX_KW + }; + ( break ) => { + $crate::SyntaxKind::BREAK_KW + }; + ( const ) => { + $crate::SyntaxKind::CONST_KW + }; + ( continue ) => { + $crate::SyntaxKind::CONTINUE_KW + }; + ( crate ) => { + $crate::SyntaxKind::CRATE_KW + }; + ( dyn ) => { + $crate::SyntaxKind::DYN_KW + }; + ( else ) => { + $crate::SyntaxKind::ELSE_KW + }; + ( enum ) => { + $crate::SyntaxKind::ENUM_KW + }; + ( extern ) => { + $crate::SyntaxKind::EXTERN_KW + }; + ( false ) => { + $crate::SyntaxKind::FALSE_KW + }; + ( fn ) => { + $crate::SyntaxKind::FN_KW + }; + ( for ) => { + $crate::SyntaxKind::FOR_KW + }; + ( if ) => { + $crate::SyntaxKind::IF_KW + }; + ( impl ) => { + $crate::SyntaxKind::IMPL_KW + }; + ( in ) => { + $crate::SyntaxKind::IN_KW + }; + ( let ) => { + $crate::SyntaxKind::LET_KW + }; + ( loop ) => { + $crate::SyntaxKind::LOOP_KW + }; ( macro ) => { $crate::SyntaxKind::MACRO_KW }; + ( match ) => { + $crate::SyntaxKind::MATCH_KW + }; + ( mod ) => { + $crate::SyntaxKind::MOD_KW + }; + ( move ) => { + $crate::SyntaxKind::MOVE_KW + }; + ( mut ) => { + $crate::SyntaxKind::MUT_KW + }; + ( pub ) => { + $crate::SyntaxKind::PUB_KW + }; + ( ref ) => { + $crate::SyntaxKind::REF_KW + }; + ( return ) => { + $crate::SyntaxKind::RETURN_KW + }; + ( self ) => { + $crate::SyntaxKind::SELF_KW + }; + ( static ) => { + $crate::SyntaxKind::STATIC_KW + }; + ( struct ) => { + $crate::SyntaxKind::STRUCT_KW + }; + ( super ) => { + $crate::SyntaxKind::SUPER_KW + }; + ( trait ) => { + $crate::SyntaxKind::TRAIT_KW + }; + ( true ) => { + $crate::SyntaxKind::TRUE_KW + }; + ( try ) => { + $crate::SyntaxKind::TRY_KW + }; + ( type ) => { + $crate::SyntaxKind::TYPE_KW + }; + ( unsafe ) => { + $crate::SyntaxKind::UNSAFE_KW + }; + ( use ) => { + $crate::SyntaxKind::USE_KW + }; + ( where ) => { + $crate::SyntaxKind::WHERE_KW + }; + ( while ) => { + $crate::SyntaxKind::WHILE_KW + }; ( auto ) => { $crate::SyntaxKind::AUTO_KW }; diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index e64c83d3352..2eb4b14d20b 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,43 +27,21 @@ impl AstNode for Alias { &self.syntax } } -impl ast::NameOwner for Alias {} -impl Alias {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArgList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ArgList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - ARG_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 ArgList { - pub fn args(&self) -> AstChildren { +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 ArrayExpr { +pub struct FnDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for ArrayExpr { +impl AstNode for FnDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ARRAY_EXPR => true, + FN_DEF => true, _ => false, } } @@ -78,49 +56,30 @@ impl AstNode for ArrayExpr { &self.syntax } } -impl ArrayExpr { - pub fn exprs(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ArrayType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - ARRAY_TYPE => 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 ArrayType { - pub fn type_ref(&self) -> Option { +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 expr(&self) -> Option { + 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 AssocTypeArg { +pub struct RetType { pub(crate) syntax: SyntaxNode, } -impl AstNode for AssocTypeArg { +impl AstNode for RetType { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ASSOC_TYPE_ARG => true, + RET_TYPE => true, _ => false, } } @@ -135,22 +94,19 @@ impl AstNode for AssocTypeArg { &self.syntax } } -impl AssocTypeArg { - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } +impl RetType { pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Attr { +pub struct StructDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for Attr { +impl AstNode for StructDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ATTR => true, + STRUCT_DEF => true, _ => false, } } @@ -165,60 +121,52 @@ impl AstNode for Attr { &self.syntax } } -impl Attr { - pub fn path(&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 UnionDef { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for UnionDef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + UNION_DEF => true, + _ => false, + } } - pub fn input(&self) -> Option { + 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 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 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) - } -} -impl AstNode for AttrInput { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LITERAL | TOKEN_TREE => 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) - } - fn syntax(&self) -> &SyntaxNode { - match self { - AttrInput::Literal(it) => &it.syntax, - AttrInput::TokenTree(it) => &it.syntax, - } - } -} -impl AttrInput {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct AwaitExpr { +pub struct RecordFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for AwaitExpr { +impl AstNode for RecordFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - AWAIT_EXPR => true, + RECORD_FIELD_DEF_LIST => true, _ => false, } } @@ -233,102 +181,19 @@ impl AstNode for AwaitExpr { &self.syntax } } -impl AwaitExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BinExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for BinExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - BIN_EXPR => 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 BinExpr {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BindPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for BindPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - BIND_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 BindPat {} -impl BindPat { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Block { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Block { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - BLOCK => 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::AttrsOwner for Block {} -impl ast::ModuleItemOwner for Block {} -impl Block { - pub fn statements(&self) -> AstChildren { +impl RecordFieldDefList { + pub fn fields(&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 RecordFieldDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for BlockExpr { +impl AstNode for RecordFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BLOCK_EXPR => true, + RECORD_FIELD_DEF => true, _ => false, } } @@ -343,19 +208,20 @@ impl AstNode for BlockExpr { &self.syntax } } -impl BlockExpr { - pub fn block(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} +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 BoxExpr { +pub struct TupleFieldDefList { pub(crate) syntax: SyntaxNode, } -impl AstNode for BoxExpr { +impl AstNode for TupleFieldDefList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BOX_EXPR => true, + TUPLE_FIELD_DEF_LIST => true, _ => false, } } @@ -370,19 +236,19 @@ impl AstNode for BoxExpr { &self.syntax } } -impl BoxExpr { - 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 BoxPat { +pub struct TupleFieldDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for BoxPat { +impl AstNode for TupleFieldDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BOX_PAT => true, + TUPLE_FIELD_DEF => true, _ => false, } } @@ -397,104 +263,21 @@ impl AstNode for BoxPat { &self.syntax } } -impl BoxPat { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BreakExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for BreakExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - BREAK_EXPR => 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 BreakExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CallExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for CallExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - CALL_EXPR => 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::ArgListOwner for CallExpr {} -impl CallExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CastExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for CastExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - CAST_EXPR => 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 CastExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } +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 Condition { +pub struct EnumDef { pub(crate) syntax: SyntaxNode, } -impl AstNode for Condition { +impl AstNode for EnumDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONDITION => true, + ENUM_DEF => true, _ => false, } } @@ -509,15 +292,167 @@ impl AstNode for Condition { &self.syntax } } -impl Condition { - 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 EnumVariantList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for EnumVariantList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ENUM_VARIANT_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 EnumVariantList { + pub fn variants(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct EnumVariant { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for EnumVariant { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ENUM_VARIANT => 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 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 TraitDef { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TraitDef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TRAIT_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 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 Module { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Module { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MODULE => 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 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 ItemList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ItemList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ITEM_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 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, } @@ -551,6 +486,1995 @@ impl ConstDef { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct StaticDef { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for StaticDef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + STATIC_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 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 TypeAliasDef { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TypeAliasDef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TYPE_ALIAS_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 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 ImplBlock { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ImplBlock { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + IMPL_BLOCK => 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::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 ParenType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ParenType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PAREN_TYPE => 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 ParenType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TupleType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TupleType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TUPLE_TYPE => 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 TupleType { + pub fn fields(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct NeverType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for NeverType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + NEVER_TYPE => 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 NeverType {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PathType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PathType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PATH_TYPE => 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 PathType { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PointerType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PointerType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + POINTER_TYPE => 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 PointerType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ArrayType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ArrayType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ARRAY_TYPE => 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 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 SliceType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for SliceType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + SLICE_TYPE => 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 SliceType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ReferenceType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ReferenceType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + REFERENCE_TYPE => 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 ReferenceType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PlaceholderType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PlaceholderType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PLACEHOLDER_TYPE => 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 PlaceholderType {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct FnPointerType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for FnPointerType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FN_POINTER_TYPE => 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 FnPointerType { + pub fn param_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn ret_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ForType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ForType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FOR_TYPE => 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 ForType { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ImplTraitType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ImplTraitType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + IMPL_TRAIT_TYPE => 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::TypeBoundsOwner for ImplTraitType {} +impl ImplTraitType {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct DynTraitType { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for DynTraitType { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + DYN_TRAIT_TYPE => 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::TypeBoundsOwner for DynTraitType {} +impl DynTraitType {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TupleExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TupleExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TUPLE_EXPR => 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 TupleExpr { + pub fn exprs(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ArrayExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ArrayExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ARRAY_EXPR => 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 ArrayExpr { + pub fn exprs(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ParenExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ParenExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PAREN_EXPR => 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 ParenExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PathExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PathExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PATH_EXPR => 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 PathExpr { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct LambdaExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for LambdaExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LAMBDA_EXPR => 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 LambdaExpr { + 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 IfExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for IfExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + IF_EXPR => 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 IfExpr { + pub fn condition(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct LoopExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for LoopExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LOOP_EXPR => 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::LoopBodyOwner for LoopExpr {} +impl LoopExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TryBlockExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TryBlockExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TRY_BLOCK_EXPR => 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 TryBlockExpr { + pub fn body(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ForExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ForExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FOR_EXPR => 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::LoopBodyOwner for ForExpr {} +impl ForExpr { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn iterable(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct WhileExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for WhileExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + WHILE_EXPR => 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::LoopBodyOwner for WhileExpr {} +impl WhileExpr { + pub fn condition(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ContinueExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ContinueExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CONTINUE_EXPR => 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 ContinueExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BreakExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BreakExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BREAK_EXPR => 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 BreakExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Label { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Label { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LABEL => 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 Label {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BlockExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BlockExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BLOCK_EXPR => 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 BlockExpr { + pub fn block(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ReturnExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ReturnExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RETURN_EXPR => 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 ReturnExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CallExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for CallExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CALL_EXPR => 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::ArgListOwner for CallExpr {} +impl CallExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MethodCallExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MethodCallExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + METHOD_CALL_EXPR => 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::ArgListOwner for MethodCallExpr {} +impl MethodCallExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn type_arg_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct IndexExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for IndexExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + INDEX_EXPR => 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 IndexExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct FieldExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for FieldExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FIELD_EXPR => 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 FieldExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct AwaitExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for AwaitExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + AWAIT_EXPR => 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 AwaitExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TryExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TryExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TRY_EXPR => 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 TryExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CastExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for CastExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CAST_EXPR => 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 CastExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RefExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RefExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + REF_EXPR => 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 RefExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PrefixExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PrefixExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PREFIX_EXPR => 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 PrefixExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BoxExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BoxExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BOX_EXPR => 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 BoxExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RangeExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RangeExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RANGE_EXPR => 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 RangeExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BinExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BinExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BIN_EXPR => 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 BinExpr {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Literal { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Literal { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LITERAL => 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 Literal {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MatchExpr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MatchExpr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MATCH_EXPR => 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 MatchExpr { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn match_arm_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MatchArmList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MatchArmList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MATCH_ARM_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 ast::AttrsOwner for MatchArmList {} +impl MatchArmList { + pub fn arms(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MatchArm { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MatchArm { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MATCH_ARM => 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::AttrsOwner for MatchArm {} +impl MatchArm { + pub fn pats(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn guard(&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 MatchGuard { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MatchGuard { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MATCH_GUARD => 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 MatchGuard { + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[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 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 RecordField { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RecordField { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + RECORD_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 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 RefPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for RefPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + REF_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 RefPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BoxPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BoxPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BOX_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 BoxPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BindPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BindPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BIND_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 BindPat {} +impl BindPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PlaceholderPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PlaceholderPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PLACEHOLDER_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 PlaceholderPat {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct DotDotPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for DotDotPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + DOT_DOT_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 DotDotPat {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PathPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PathPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PATH_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 PathPat { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SlicePat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for SlicePat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + SLICE_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 SlicePat {} +#[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 LiteralPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for LiteralPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LITERAL_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 LiteralPat { + pub fn literal(&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 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 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 TupleStructPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TupleStructPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TUPLE_STRUCT_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 TupleStructPat { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TuplePat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TuplePat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TUPLE_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 TuplePat { + pub fn args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Visibility { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Visibility { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + VISIBILITY => 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 Visibility {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Name { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Name { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + NAME => 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 Name {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct NameRef { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for NameRef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + NAME_REF => 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 NameRef {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroCall { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MacroCall { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MACRO_CALL => 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 MacroCall {} +impl ast::AttrsOwner for MacroCall {} +impl ast::DocCommentsOwner for MacroCall {} +impl MacroCall { + pub fn token_tree(&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 Attr { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Attr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ATTR => 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 Attr { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn input(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TokenTree { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TokenTree { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TOKEN_TREE => 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 TokenTree {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeParamList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TypeParamList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TYPE_PARAM_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 TypeParamList { + pub fn type_params(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn lifetime_params(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeParam { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TypeParam { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TYPE_PARAM => 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 TypeParam {} +impl ast::AttrsOwner for TypeParam {} +impl ast::TypeBoundsOwner for TypeParam {} +impl TypeParam { + pub fn default_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConstParam { pub(crate) syntax: SyntaxNode, } @@ -581,13 +2505,13 @@ impl ConstParam { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ContinueExpr { +pub struct LifetimeParam { pub(crate) syntax: SyntaxNode, } -impl AstNode for ContinueExpr { +impl AstNode for LifetimeParam { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONTINUE_EXPR => true, + LIFETIME_PARAM => true, _ => false, } } @@ -602,15 +2526,16 @@ impl AstNode for ContinueExpr { &self.syntax } } -impl ContinueExpr {} +impl ast::AttrsOwner for LifetimeParam {} +impl LifetimeParam {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DotDotPat { +pub struct TypeBound { pub(crate) syntax: SyntaxNode, } -impl AstNode for DotDotPat { +impl AstNode for TypeBound { fn can_cast(kind: SyntaxKind) -> bool { match kind { - DOT_DOT_PAT => true, + TYPE_BOUND => true, _ => false, } } @@ -625,71 +2550,19 @@ impl AstNode for DotDotPat { &self.syntax } } -impl DotDotPat {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynTraitType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for DynTraitType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - DYN_TRAIT_TYPE => 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::TypeBoundsOwner for DynTraitType {} -impl DynTraitType {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for EnumDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - ENUM_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 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 TypeBound { + pub fn type_ref(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumVariant { +pub struct TypeBoundList { pub(crate) syntax: SyntaxNode, } -impl AstNode for EnumVariant { +impl AstNode for TypeBoundList { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ENUM_VARIANT => true, + TYPE_BOUND_LIST => true, _ => false, } } @@ -704,22 +2577,101 @@ impl AstNode for EnumVariant { &self.syntax } } -impl ast::NameOwner for EnumVariant {} -impl ast::DocCommentsOwner for EnumVariant {} -impl ast::AttrsOwner for EnumVariant {} -impl EnumVariant { +impl TypeBoundList { + pub fn bounds(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct WherePred { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for WherePred { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + WHERE_PRED => 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::TypeBoundsOwner for WherePred {} +impl WherePred { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct WhereClause { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for WhereClause { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + WHERE_CLAUSE => 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 WhereClause { + pub fn predicates(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExprStmt { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ExprStmt { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + EXPR_STMT => 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 ExprStmt { pub fn expr(&self) -> Option { AstChildren::new(&self.syntax).next() } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumVariantList { +pub struct LetStmt { pub(crate) syntax: SyntaxNode, } -impl AstNode for EnumVariantList { +impl AstNode for LetStmt { fn can_cast(kind: SyntaxKind) -> bool { match kind { - ENUM_VARIANT_LIST => true, + LET_STMT => true, _ => false, } } @@ -734,12 +2686,912 @@ impl AstNode for EnumVariantList { &self.syntax } } -impl EnumVariantList { - pub fn variants(&self) -> AstChildren { +impl ast::TypeAscriptionOwner for LetStmt {} +impl LetStmt { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn initializer(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Condition { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Condition { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CONDITION => 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 Condition { + pub fn pat(&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 Block { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Block { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BLOCK => 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::AttrsOwner for Block {} +impl ast::ModuleItemOwner for Block {} +impl Block { + pub fn statements(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ParamList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ParamList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PARAM_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 ParamList { + pub fn self_param(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn params(&self) -> AstChildren { AstChildren::new(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SelfParam { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for SelfParam { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + SELF_PARAM => 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::TypeAscriptionOwner for SelfParam {} +impl ast::AttrsOwner for SelfParam {} +impl SelfParam {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Param { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Param { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PARAM => 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::TypeAscriptionOwner for Param {} +impl ast::AttrsOwner for Param {} +impl Param { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseItem { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for UseItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + USE_ITEM => 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::AttrsOwner for UseItem {} +impl ast::VisibilityOwner for UseItem {} +impl UseItem { + pub fn use_tree(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseTree { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for UseTree { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + USE_TREE => 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 UseTree { + pub fn path(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn use_tree_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn alias(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Alias { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Alias { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ALIAS => 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 Alias {} +impl Alias {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseTreeList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for UseTreeList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + USE_TREE_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 UseTreeList { + pub fn use_trees(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExternCrateItem { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ExternCrateItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + EXTERN_CRATE_ITEM => 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::AttrsOwner for ExternCrateItem {} +impl ast::VisibilityOwner for ExternCrateItem {} +impl ExternCrateItem { + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn alias(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ArgList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ArgList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ARG_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 ArgList { + pub fn args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Path { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for Path { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PATH => 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 Path { + pub fn segment(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn qualifier(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PathSegment { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for PathSegment { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PATH_SEGMENT => 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 PathSegment { + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn type_arg_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn param_list(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn ret_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn path_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeArgList { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TypeArgList { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TYPE_ARG_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 TypeArgList { + pub fn type_args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn lifetime_args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn assoc_type_args(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeArg { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for TypeArg { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + TYPE_ARG => 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 TypeArg { + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct AssocTypeArg { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for AssocTypeArg { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ASSOC_TYPE_ARG => 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 AssocTypeArg { + pub fn name_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } + pub fn type_ref(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct LifetimeArg { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for LifetimeArg { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + LIFETIME_ARG => 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 LifetimeArg {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroItems { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MacroItems { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MACRO_ITEMS => 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::ModuleItemOwner for MacroItems {} +impl ast::FnDefOwner for MacroItems {} +impl MacroItems {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroStmts { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for MacroStmts { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + MACRO_STMTS => 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 MacroStmts { + pub fn statements(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } + pub fn expr(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum NominalDef { + StructDef(StructDef), + EnumDef(EnumDef), + UnionDef(UnionDef), +} +impl From for NominalDef { + fn from(node: StructDef) -> NominalDef { + NominalDef::StructDef(node) + } +} +impl From for NominalDef { + fn from(node: EnumDef) -> NominalDef { + NominalDef::EnumDef(node) + } +} +impl From for NominalDef { + fn from(node: UnionDef) -> NominalDef { + NominalDef::UnionDef(node) + } +} +impl AstNode for NominalDef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + STRUCT_DEF | ENUM_DEF | UNION_DEF => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), + ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), + UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + NominalDef::StructDef(it) => &it.syntax, + NominalDef::EnumDef(it) => &it.syntax, + NominalDef::UnionDef(it) => &it.syntax, + } + } +} +impl ast::NameOwner for NominalDef {} +impl ast::TypeParamsOwner for NominalDef {} +impl ast::AttrsOwner for NominalDef {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum TypeRef { + ParenType(ParenType), + TupleType(TupleType), + NeverType(NeverType), + PathType(PathType), + PointerType(PointerType), + ArrayType(ArrayType), + SliceType(SliceType), + ReferenceType(ReferenceType), + PlaceholderType(PlaceholderType), + FnPointerType(FnPointerType), + ForType(ForType), + ImplTraitType(ImplTraitType), + DynTraitType(DynTraitType), +} +impl From for TypeRef { + fn from(node: ParenType) -> TypeRef { + TypeRef::ParenType(node) + } +} +impl From for TypeRef { + fn from(node: TupleType) -> TypeRef { + TypeRef::TupleType(node) + } +} +impl From for TypeRef { + fn from(node: NeverType) -> TypeRef { + TypeRef::NeverType(node) + } +} +impl From for TypeRef { + fn from(node: PathType) -> TypeRef { + TypeRef::PathType(node) + } +} +impl From for TypeRef { + fn from(node: PointerType) -> TypeRef { + TypeRef::PointerType(node) + } +} +impl From for TypeRef { + fn from(node: ArrayType) -> TypeRef { + TypeRef::ArrayType(node) + } +} +impl From for TypeRef { + fn from(node: SliceType) -> TypeRef { + TypeRef::SliceType(node) + } +} +impl From for TypeRef { + fn from(node: ReferenceType) -> TypeRef { + TypeRef::ReferenceType(node) + } +} +impl From for TypeRef { + fn from(node: PlaceholderType) -> TypeRef { + TypeRef::PlaceholderType(node) + } +} +impl From for TypeRef { + fn from(node: FnPointerType) -> TypeRef { + TypeRef::FnPointerType(node) + } +} +impl From for TypeRef { + fn from(node: ForType) -> TypeRef { + TypeRef::ForType(node) + } +} +impl From for TypeRef { + fn from(node: ImplTraitType) -> TypeRef { + TypeRef::ImplTraitType(node) + } +} +impl From for TypeRef { + fn from(node: DynTraitType) -> TypeRef { + TypeRef::DynTraitType(node) + } +} +impl AstNode for TypeRef { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE + | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE + | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }), + TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }), + NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }), + PATH_TYPE => TypeRef::PathType(PathType { syntax }), + POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }), + ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }), + SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }), + REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }), + PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }), + FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }), + FOR_TYPE => TypeRef::ForType(ForType { syntax }), + IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }), + DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + TypeRef::ParenType(it) => &it.syntax, + TypeRef::TupleType(it) => &it.syntax, + TypeRef::NeverType(it) => &it.syntax, + TypeRef::PathType(it) => &it.syntax, + TypeRef::PointerType(it) => &it.syntax, + TypeRef::ArrayType(it) => &it.syntax, + TypeRef::SliceType(it) => &it.syntax, + TypeRef::ReferenceType(it) => &it.syntax, + TypeRef::PlaceholderType(it) => &it.syntax, + TypeRef::FnPointerType(it) => &it.syntax, + TypeRef::ForType(it) => &it.syntax, + TypeRef::ImplTraitType(it) => &it.syntax, + TypeRef::DynTraitType(it) => &it.syntax, + } + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum ModuleItem { + StructDef(StructDef), + UnionDef(UnionDef), + EnumDef(EnumDef), + FnDef(FnDef), + TraitDef(TraitDef), + TypeAliasDef(TypeAliasDef), + ImplBlock(ImplBlock), + UseItem(UseItem), + ExternCrateItem(ExternCrateItem), + ConstDef(ConstDef), + StaticDef(StaticDef), + Module(Module), +} +impl From for ModuleItem { + fn from(node: StructDef) -> ModuleItem { + ModuleItem::StructDef(node) + } +} +impl From for ModuleItem { + fn from(node: UnionDef) -> ModuleItem { + ModuleItem::UnionDef(node) + } +} +impl From for ModuleItem { + fn from(node: EnumDef) -> ModuleItem { + ModuleItem::EnumDef(node) + } +} +impl From for ModuleItem { + fn from(node: FnDef) -> ModuleItem { + ModuleItem::FnDef(node) + } +} +impl From for ModuleItem { + fn from(node: TraitDef) -> ModuleItem { + ModuleItem::TraitDef(node) + } +} +impl From for ModuleItem { + fn from(node: TypeAliasDef) -> ModuleItem { + ModuleItem::TypeAliasDef(node) + } +} +impl From for ModuleItem { + fn from(node: ImplBlock) -> ModuleItem { + ModuleItem::ImplBlock(node) + } +} +impl From for ModuleItem { + fn from(node: UseItem) -> ModuleItem { + ModuleItem::UseItem(node) + } +} +impl From for ModuleItem { + fn from(node: ExternCrateItem) -> ModuleItem { + ModuleItem::ExternCrateItem(node) + } +} +impl From for ModuleItem { + fn from(node: ConstDef) -> ModuleItem { + ModuleItem::ConstDef(node) + } +} +impl From for ModuleItem { + fn from(node: StaticDef) -> ModuleItem { + ModuleItem::StaticDef(node) + } +} +impl From for ModuleItem { + fn from(node: Module) -> ModuleItem { + ModuleItem::Module(node) + } +} +impl AstNode for ModuleItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF + | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), + UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), + ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), + FN_DEF => ModuleItem::FnDef(FnDef { syntax }), + TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), + TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }), + IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }), + USE_ITEM => ModuleItem::UseItem(UseItem { syntax }), + EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }), + CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), + STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), + MODULE => ModuleItem::Module(Module { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + ModuleItem::StructDef(it) => &it.syntax, + ModuleItem::UnionDef(it) => &it.syntax, + ModuleItem::EnumDef(it) => &it.syntax, + ModuleItem::FnDef(it) => &it.syntax, + ModuleItem::TraitDef(it) => &it.syntax, + ModuleItem::TypeAliasDef(it) => &it.syntax, + ModuleItem::ImplBlock(it) => &it.syntax, + ModuleItem::UseItem(it) => &it.syntax, + ModuleItem::ExternCrateItem(it) => &it.syntax, + ModuleItem::ConstDef(it) => &it.syntax, + ModuleItem::StaticDef(it) => &it.syntax, + ModuleItem::Module(it) => &it.syntax, + } + } +} +impl ast::AttrsOwner for ModuleItem {} +impl ast::VisibilityOwner for ModuleItem {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum ImplItem { + FnDef(FnDef), + TypeAliasDef(TypeAliasDef), + ConstDef(ConstDef), +} +impl From for ImplItem { + fn from(node: FnDef) -> ImplItem { + ImplItem::FnDef(node) + } +} +impl From for ImplItem { + fn from(node: TypeAliasDef) -> ImplItem { + ImplItem::TypeAliasDef(node) + } +} +impl From for ImplItem { + fn from(node: ConstDef) -> ImplItem { + ImplItem::ConstDef(node) + } +} +impl AstNode for ImplItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + FN_DEF => ImplItem::FnDef(FnDef { syntax }), + TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), + CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + ImplItem::FnDef(it) => &it.syntax, + ImplItem::TypeAliasDef(it) => &it.syntax, + ImplItem::ConstDef(it) => &it.syntax, + } + } +} +impl ast::AttrsOwner for ImplItem {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Expr { TupleExpr(TupleExpr), ArrayExpr(ArrayExpr), @@ -1013,1233 +3865,6 @@ impl AstNode for Expr { } } } -impl Expr {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExprStmt { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ExprStmt { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - EXPR_STMT => 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 ExprStmt { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExternCrateItem { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ExternCrateItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - EXTERN_CRATE_ITEM => 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::AttrsOwner for ExternCrateItem {} -impl ast::VisibilityOwner for ExternCrateItem {} -impl ExternCrateItem { - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn alias(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FieldExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for FieldExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FIELD_EXPR => 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 FieldExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FnDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for FnDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FN_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 FnDef {} -impl ast::NameOwner for FnDef {} -impl ast::TypeParamsOwner for FnDef {} -impl ast::AttrsOwner for FnDef {} -impl ast::DocCommentsOwner for FnDef {} -impl FnDef { - pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FnPointerType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for FnPointerType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FN_POINTER_TYPE => 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 FnPointerType { - pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ForExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ForExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FOR_EXPR => 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::LoopBodyOwner for ForExpr {} -impl ForExpr { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn iterable(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ForType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ForType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FOR_TYPE => 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 ForType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct IfExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for IfExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - IF_EXPR => 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 IfExpr { - pub fn condition(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ImplBlock { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ImplBlock { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - IMPL_BLOCK => 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::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 enum ImplItem { - FnDef(FnDef), - TypeAliasDef(TypeAliasDef), - ConstDef(ConstDef), -} -impl From for ImplItem { - fn from(node: FnDef) -> ImplItem { - ImplItem::FnDef(node) - } -} -impl From for ImplItem { - fn from(node: TypeAliasDef) -> ImplItem { - ImplItem::TypeAliasDef(node) - } -} -impl From for ImplItem { - fn from(node: ConstDef) -> ImplItem { - ImplItem::ConstDef(node) - } -} -impl AstNode for ImplItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - FN_DEF => ImplItem::FnDef(FnDef { syntax }), - TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), - CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - ImplItem::FnDef(it) => &it.syntax, - ImplItem::TypeAliasDef(it) => &it.syntax, - ImplItem::ConstDef(it) => &it.syntax, - } - } -} -impl ast::AttrsOwner for ImplItem {} -impl ImplItem {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ImplTraitType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ImplTraitType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - IMPL_TRAIT_TYPE => 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::TypeBoundsOwner for ImplTraitType {} -impl ImplTraitType {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct IndexExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for IndexExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - INDEX_EXPR => 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 IndexExpr {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ItemList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ItemList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - ITEM_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 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 Label { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Label { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LABEL => 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 Label {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LambdaExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LambdaExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LAMBDA_EXPR => 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 LambdaExpr { - 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 LetStmt { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LetStmt { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LET_STMT => 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::TypeAscriptionOwner for LetStmt {} -impl LetStmt { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn initializer(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LifetimeArg { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LifetimeArg { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LIFETIME_ARG => 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 LifetimeArg {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LifetimeParam { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LifetimeParam { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LIFETIME_PARAM => 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::AttrsOwner for LifetimeParam {} -impl LifetimeParam {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Literal { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Literal { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LITERAL => 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 Literal {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LiteralPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LiteralPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LITERAL_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 LiteralPat { - pub fn literal(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LoopExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for LoopExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - LOOP_EXPR => 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::LoopBodyOwner for LoopExpr {} -impl LoopExpr {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroCall { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MacroCall { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MACRO_CALL => 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 MacroCall {} -impl ast::AttrsOwner for MacroCall {} -impl ast::DocCommentsOwner for MacroCall {} -impl MacroCall { - pub fn token_tree(&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 MacroItems { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MacroItems { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MACRO_ITEMS => 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::ModuleItemOwner for MacroItems {} -impl ast::FnDefOwner for MacroItems {} -impl MacroItems {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroStmts { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MacroStmts { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MACRO_STMTS => 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 MacroStmts { - pub fn statements(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MatchArm { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MatchArm { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MATCH_ARM => 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::AttrsOwner for MatchArm {} -impl MatchArm { - pub fn pats(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn guard(&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 MatchArmList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MatchArmList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MATCH_ARM_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 ast::AttrsOwner for MatchArmList {} -impl MatchArmList { - pub fn arms(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MatchExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MatchExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MATCH_EXPR => 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 MatchExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn match_arm_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MatchGuard { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MatchGuard { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MATCH_GUARD => 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 MatchGuard { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MethodCallExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for MethodCallExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - METHOD_CALL_EXPR => 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::ArgListOwner for MethodCallExpr {} -impl MethodCallExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn type_arg_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Module { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Module { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MODULE => 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 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 enum ModuleItem { - StructDef(StructDef), - UnionDef(UnionDef), - EnumDef(EnumDef), - FnDef(FnDef), - TraitDef(TraitDef), - TypeAliasDef(TypeAliasDef), - ImplBlock(ImplBlock), - UseItem(UseItem), - ExternCrateItem(ExternCrateItem), - ConstDef(ConstDef), - StaticDef(StaticDef), - Module(Module), -} -impl From for ModuleItem { - fn from(node: StructDef) -> ModuleItem { - ModuleItem::StructDef(node) - } -} -impl From for ModuleItem { - fn from(node: UnionDef) -> ModuleItem { - ModuleItem::UnionDef(node) - } -} -impl From for ModuleItem { - fn from(node: EnumDef) -> ModuleItem { - ModuleItem::EnumDef(node) - } -} -impl From for ModuleItem { - fn from(node: FnDef) -> ModuleItem { - ModuleItem::FnDef(node) - } -} -impl From for ModuleItem { - fn from(node: TraitDef) -> ModuleItem { - ModuleItem::TraitDef(node) - } -} -impl From for ModuleItem { - fn from(node: TypeAliasDef) -> ModuleItem { - ModuleItem::TypeAliasDef(node) - } -} -impl From for ModuleItem { - fn from(node: ImplBlock) -> ModuleItem { - ModuleItem::ImplBlock(node) - } -} -impl From for ModuleItem { - fn from(node: UseItem) -> ModuleItem { - ModuleItem::UseItem(node) - } -} -impl From for ModuleItem { - fn from(node: ExternCrateItem) -> ModuleItem { - ModuleItem::ExternCrateItem(node) - } -} -impl From for ModuleItem { - fn from(node: ConstDef) -> ModuleItem { - ModuleItem::ConstDef(node) - } -} -impl From for ModuleItem { - fn from(node: StaticDef) -> ModuleItem { - ModuleItem::StaticDef(node) - } -} -impl From for ModuleItem { - fn from(node: Module) -> ModuleItem { - ModuleItem::Module(node) - } -} -impl AstNode for ModuleItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF - | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), - UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), - ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), - FN_DEF => ModuleItem::FnDef(FnDef { syntax }), - TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), - TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }), - IMPL_BLOCK => ModuleItem::ImplBlock(ImplBlock { syntax }), - USE_ITEM => ModuleItem::UseItem(UseItem { syntax }), - EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }), - CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), - STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), - MODULE => ModuleItem::Module(Module { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - ModuleItem::StructDef(it) => &it.syntax, - ModuleItem::UnionDef(it) => &it.syntax, - ModuleItem::EnumDef(it) => &it.syntax, - ModuleItem::FnDef(it) => &it.syntax, - ModuleItem::TraitDef(it) => &it.syntax, - ModuleItem::TypeAliasDef(it) => &it.syntax, - ModuleItem::ImplBlock(it) => &it.syntax, - ModuleItem::UseItem(it) => &it.syntax, - ModuleItem::ExternCrateItem(it) => &it.syntax, - ModuleItem::ConstDef(it) => &it.syntax, - ModuleItem::StaticDef(it) => &it.syntax, - ModuleItem::Module(it) => &it.syntax, - } - } -} -impl ast::AttrsOwner for ModuleItem {} -impl ast::VisibilityOwner for ModuleItem {} -impl ModuleItem {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Name { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Name { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAME => 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 Name {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NameRef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NameRef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NAME_REF => 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 NameRef {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NeverType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for NeverType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - NEVER_TYPE => 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 NeverType {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum NominalDef { - StructDef(StructDef), - EnumDef(EnumDef), - UnionDef(UnionDef), -} -impl From for NominalDef { - fn from(node: StructDef) -> NominalDef { - NominalDef::StructDef(node) - } -} -impl From for NominalDef { - fn from(node: EnumDef) -> NominalDef { - NominalDef::EnumDef(node) - } -} -impl From for NominalDef { - fn from(node: UnionDef) -> NominalDef { - NominalDef::UnionDef(node) - } -} -impl AstNode for NominalDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - STRUCT_DEF | ENUM_DEF | UNION_DEF => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), - ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), - UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - NominalDef::StructDef(it) => &it.syntax, - NominalDef::EnumDef(it) => &it.syntax, - NominalDef::UnionDef(it) => &it.syntax, - } - } -} -impl ast::NameOwner for NominalDef {} -impl ast::TypeParamsOwner for NominalDef {} -impl ast::AttrsOwner for NominalDef {} -impl NominalDef {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Param { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Param { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PARAM => 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::TypeAscriptionOwner for Param {} -impl ast::AttrsOwner for Param {} -impl Param { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ParamList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ParamList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PARAM_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 ParamList { - pub fn params(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn self_param(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ParenExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ParenExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PAREN_EXPR => 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 ParenExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ParenType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ParenType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PAREN_TYPE => 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 ParenType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { RefPat(RefPat), @@ -2360,807 +3985,42 @@ impl AstNode for Pat { } } } -impl Pat {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Path { - pub(crate) syntax: SyntaxNode, +pub enum AttrInput { + Literal(Literal), + TokenTree(TokenTree), } -impl AstNode for Path { +impl From for AttrInput { + fn from(node: Literal) -> AttrInput { + AttrInput::Literal(node) + } +} +impl From for AttrInput { + fn from(node: TokenTree) -> AttrInput { + AttrInput::TokenTree(node) + } +} +impl AstNode for AttrInput { fn can_cast(kind: SyntaxKind) -> bool { match kind { - PATH => true, + LITERAL | TOKEN_TREE => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } + let res = match syntax.kind() { + LITERAL => AttrInput::Literal(Literal { syntax }), + TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }), + _ => return None, + }; + Some(res) } fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl Path { - pub fn segment(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn qualifier(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PathExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PATH_EXPR => true, - _ => false, + match self { + AttrInput::Literal(it) => &it.syntax, + AttrInput::TokenTree(it) => &it.syntax, } } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } -} -impl PathExpr { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PathPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PATH_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 PathPat { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathSegment { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PathSegment { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PATH_SEGMENT => 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 PathSegment { - pub fn name_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn type_arg_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn param_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn ret_type(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn path_type(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PathType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PATH_TYPE => 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 PathType { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PlaceholderPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PlaceholderPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PLACEHOLDER_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 PlaceholderPat {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PlaceholderType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PlaceholderType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PLACEHOLDER_TYPE => 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 PlaceholderType {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PointerType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PointerType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - POINTER_TYPE => 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 PointerType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PrefixExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for PrefixExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PREFIX_EXPR => 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 PrefixExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RangeExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RangeExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RANGE_EXPR => 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 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 RecordField { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RecordField { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RECORD_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 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 RecordFieldDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RecordFieldDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RECORD_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 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 RecordFieldDefList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RecordFieldDefList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RECORD_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 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, -} -impl AstNode for RefExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - REF_EXPR => 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 RefExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RefPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RefPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - REF_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 RefPat { - pub fn pat(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ReferenceType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ReferenceType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - REFERENCE_TYPE => 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 ReferenceType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RetType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for RetType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RET_TYPE => 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 RetType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ReturnExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for ReturnExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - RETURN_EXPR => 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 ReturnExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SelfParam { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for SelfParam { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - SELF_PARAM => 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::TypeAscriptionOwner for SelfParam {} -impl ast::AttrsOwner for SelfParam {} -impl SelfParam {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SlicePat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for SlicePat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - SLICE_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 SlicePat {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SliceType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for SliceType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - SLICE_TYPE => 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 SliceType { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SourceFile { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for SourceFile { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - SOURCE_FILE => 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::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 StaticDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for StaticDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - STATIC_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 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 enum Stmt { @@ -3199,871 +4059,3 @@ impl AstNode for Stmt { } } } -impl Stmt {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StructDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for StructDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - STRUCT_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 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 TokenTree { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TokenTree { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TOKEN_TREE => 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 TokenTree {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TraitDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TraitDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TRAIT_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 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 TryBlockExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TryBlockExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TRY_BLOCK_EXPR => 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 TryBlockExpr { - pub fn body(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TryExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TryExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TRY_EXPR => 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 TryExpr { - pub fn expr(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TupleExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_EXPR => 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 TupleExpr { - pub fn exprs(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleFieldDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TupleFieldDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_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 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 TupleFieldDefList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TupleFieldDefList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_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 TupleFieldDefList { - pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TuplePat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TuplePat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_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 TuplePat { - pub fn args(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleStructPat { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TupleStructPat { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_STRUCT_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 TupleStructPat { - pub fn args(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleType { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TupleType { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TUPLE_TYPE => 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 TupleType { - pub fn fields(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeAliasDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeAliasDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_ALIAS_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 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 TypeArg { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeArg { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_ARG => 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 TypeArg { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeArgList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeArgList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_ARG_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 TypeArgList { - pub fn type_args(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn lifetime_args(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn assoc_type_args(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeBound { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeBound { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_BOUND => 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 TypeBound { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeBoundList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeBoundList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_BOUND_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 TypeBoundList { - pub fn bounds(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeParam { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeParam { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_PARAM => 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 TypeParam {} -impl ast::AttrsOwner for TypeParam {} -impl ast::TypeBoundsOwner for TypeParam {} -impl TypeParam { - pub fn default_type(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeParamList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for TypeParamList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - TYPE_PARAM_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 TypeParamList { - pub fn type_params(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } - pub fn lifetime_params(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum TypeRef { - ParenType(ParenType), - TupleType(TupleType), - NeverType(NeverType), - PathType(PathType), - PointerType(PointerType), - ArrayType(ArrayType), - SliceType(SliceType), - ReferenceType(ReferenceType), - PlaceholderType(PlaceholderType), - FnPointerType(FnPointerType), - ForType(ForType), - ImplTraitType(ImplTraitType), - DynTraitType(DynTraitType), -} -impl From for TypeRef { - fn from(node: ParenType) -> TypeRef { - TypeRef::ParenType(node) - } -} -impl From for TypeRef { - fn from(node: TupleType) -> TypeRef { - TypeRef::TupleType(node) - } -} -impl From for TypeRef { - fn from(node: NeverType) -> TypeRef { - TypeRef::NeverType(node) - } -} -impl From for TypeRef { - fn from(node: PathType) -> TypeRef { - TypeRef::PathType(node) - } -} -impl From for TypeRef { - fn from(node: PointerType) -> TypeRef { - TypeRef::PointerType(node) - } -} -impl From for TypeRef { - fn from(node: ArrayType) -> TypeRef { - TypeRef::ArrayType(node) - } -} -impl From for TypeRef { - fn from(node: SliceType) -> TypeRef { - TypeRef::SliceType(node) - } -} -impl From for TypeRef { - fn from(node: ReferenceType) -> TypeRef { - TypeRef::ReferenceType(node) - } -} -impl From for TypeRef { - fn from(node: PlaceholderType) -> TypeRef { - TypeRef::PlaceholderType(node) - } -} -impl From for TypeRef { - fn from(node: FnPointerType) -> TypeRef { - TypeRef::FnPointerType(node) - } -} -impl From for TypeRef { - fn from(node: ForType) -> TypeRef { - TypeRef::ForType(node) - } -} -impl From for TypeRef { - fn from(node: ImplTraitType) -> TypeRef { - TypeRef::ImplTraitType(node) - } -} -impl From for TypeRef { - fn from(node: DynTraitType) -> TypeRef { - TypeRef::DynTraitType(node) - } -} -impl AstNode for TypeRef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE - | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE - | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }), - TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }), - NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }), - PATH_TYPE => TypeRef::PathType(PathType { syntax }), - POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }), - ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }), - SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }), - REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }), - PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }), - FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }), - FOR_TYPE => TypeRef::ForType(ForType { syntax }), - IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }), - DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - TypeRef::ParenType(it) => &it.syntax, - TypeRef::TupleType(it) => &it.syntax, - TypeRef::NeverType(it) => &it.syntax, - TypeRef::PathType(it) => &it.syntax, - TypeRef::PointerType(it) => &it.syntax, - TypeRef::ArrayType(it) => &it.syntax, - TypeRef::SliceType(it) => &it.syntax, - TypeRef::ReferenceType(it) => &it.syntax, - TypeRef::PlaceholderType(it) => &it.syntax, - TypeRef::FnPointerType(it) => &it.syntax, - TypeRef::ForType(it) => &it.syntax, - TypeRef::ImplTraitType(it) => &it.syntax, - TypeRef::DynTraitType(it) => &it.syntax, - } - } -} -impl TypeRef {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UnionDef { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for UnionDef { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - UNION_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 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 UseItem { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for UseItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - USE_ITEM => 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::AttrsOwner for UseItem {} -impl ast::VisibilityOwner for UseItem {} -impl UseItem { - pub fn use_tree(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseTree { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for UseTree { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - USE_TREE => 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 UseTree { - pub fn path(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn use_tree_list(&self) -> Option { - AstChildren::new(&self.syntax).next() - } - pub fn alias(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseTreeList { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for UseTreeList { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - USE_TREE_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 UseTreeList { - pub fn use_trees(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Visibility { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for Visibility { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - VISIBILITY => 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 Visibility {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct WhereClause { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for WhereClause { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - WHERE_CLAUSE => 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 WhereClause { - pub fn predicates(&self) -> AstChildren { - AstChildren::new(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct WherePred { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for WherePred { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - WHERE_PRED => 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::TypeBoundsOwner for WherePred {} -impl WherePred { - pub fn type_ref(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct WhileExpr { - pub(crate) syntax: SyntaxNode, -} -impl AstNode for WhileExpr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - WHILE_EXPR => 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::LoopBodyOwner for WhileExpr {} -impl WhileExpr { - pub fn condition(&self) -> Option { - AstChildren::new(&self.syntax).next() - } -} diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index e43a724f0bc..47446a878c2 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -1,736 +1,6 @@ // Stores definitions which must be used in multiple places // See `cargo xtask codegen` (defined in xtasks/src/main.rs) Grammar( - punct: [ - (";", "SEMI"), - (",", "COMMA"), - ("(", "L_PAREN"), - (")", "R_PAREN"), - ("{", "L_CURLY"), - ("}", "R_CURLY"), - ("[", "L_BRACK"), - ("]", "R_BRACK"), - ("<", "L_ANGLE"), - (">", "R_ANGLE"), - ("@", "AT"), - ("#", "POUND"), - ("~", "TILDE"), - ("?", "QUESTION"), - ("$", "DOLLAR"), - ("&", "AMP"), - ("|", "PIPE"), - ("+", "PLUS"), - ("*", "STAR"), - ("/", "SLASH"), - ("^", "CARET"), - ("%", "PERCENT"), - ("_", "UNDERSCORE"), - (".", "DOT"), - ("..", "DOTDOT"), - ("...", "DOTDOTDOT"), - ("..=", "DOTDOTEQ"), - (":", "COLON"), - ("::", "COLONCOLON"), - ("=", "EQ"), - ("==", "EQEQ"), - ("=>", "FAT_ARROW"), - ("!", "EXCL"), - ("!=", "NEQ"), - ("-", "MINUS"), - ("->", "THIN_ARROW"), - ("<=", "LTEQ"), - (">=", "GTEQ"), - ("+=", "PLUSEQ"), - ("-=", "MINUSEQ"), - ("|=", "PIPEEQ"), - ("&=", "AMPEQ"), - ("^=", "CARETEQ"), - ("/=", "SLASHEQ"), - ("*=", "STAREQ"), - ("%=", "PERCENTEQ"), - ("&&", "AMPAMP"), - ("||", "PIPEPIPE"), - ("<<", "SHL"), - (">>", "SHR"), - ("<<=", "SHLEQ"), - (">>=", "SHREQ"), - ], - keywords: [ - "async", - "use", - "fn", - "struct", - "enum", - "trait", - "impl", - "dyn", - "true", - "false", - "as", - "extern", - "crate", - "mod", - "pub", - "self", - "super", - "in", - "where", - "for", - "loop", - "while", - "continue", - "break", - "if", - "else", - "match", - "const", - "static", - "mut", - "unsafe", - "type", - "ref", - "let", - "move", - "return", - "try", - "box", - "await", - "macro" - ], - contextual_keywords: [ - "auto", - "default", - "existential", - "union", - ], - literals: [ - "INT_NUMBER", - "FLOAT_NUMBER", - "CHAR", - "BYTE", - "STRING", - "RAW_STRING", - "BYTE_STRING", - "RAW_BYTE_STRING", - ], - tokens: [ - "ERROR", - "IDENT", - "WHITESPACE", - "LIFETIME", - "COMMENT", - "SHEBANG", - "L_DOLLAR", - "R_DOLLAR", - ], - nodes: [ - "SOURCE_FILE", - - "STRUCT_DEF", - "UNION_DEF", - "ENUM_DEF", - "FN_DEF", - "RET_TYPE", - "EXTERN_CRATE_ITEM", - "MODULE", - "USE_ITEM", - "STATIC_DEF", - "CONST_DEF", - "TRAIT_DEF", - "IMPL_BLOCK", - "TYPE_ALIAS_DEF", - "MACRO_CALL", - "TOKEN_TREE", - "MACRO_DEF", - - "PAREN_TYPE", - "TUPLE_TYPE", - "NEVER_TYPE", - "PATH_TYPE", - "POINTER_TYPE", - "ARRAY_TYPE", - "SLICE_TYPE", - "REFERENCE_TYPE", - "PLACEHOLDER_TYPE", - "FN_POINTER_TYPE", - "FOR_TYPE", - "IMPL_TRAIT_TYPE", - "DYN_TRAIT_TYPE", - - "REF_PAT", - "BOX_PAT", - "BIND_PAT", - "PLACEHOLDER_PAT", - "DOT_DOT_PAT", - "PATH_PAT", - "RECORD_PAT", - "RECORD_FIELD_PAT_LIST", - "RECORD_FIELD_PAT", - "TUPLE_STRUCT_PAT", - "TUPLE_PAT", - "SLICE_PAT", - "RANGE_PAT", - "LITERAL_PAT", - - // atoms - "TUPLE_EXPR", - "ARRAY_EXPR", - "PAREN_EXPR", - "PATH_EXPR", - "LAMBDA_EXPR", - "IF_EXPR", - "WHILE_EXPR", - "CONDITION", - "LOOP_EXPR", - "FOR_EXPR", - "CONTINUE_EXPR", - "BREAK_EXPR", - "LABEL", - "BLOCK_EXPR", - "RETURN_EXPR", - "MATCH_EXPR", - "MATCH_ARM_LIST", - "MATCH_ARM", - "MATCH_GUARD", - "RECORD_LIT", - "RECORD_FIELD_LIST", - "RECORD_FIELD", - "TRY_BLOCK_EXPR", - "BOX_EXPR", - - // postfix - "CALL_EXPR", - "INDEX_EXPR", - "METHOD_CALL_EXPR", - "FIELD_EXPR", - "AWAIT_EXPR", - "TRY_EXPR", - "CAST_EXPR", - - // unary - "REF_EXPR", - "PREFIX_EXPR", - - "RANGE_EXPR", // just weird - "BIN_EXPR", - - "BLOCK", - "EXTERN_BLOCK", - "EXTERN_ITEM_LIST", - "ENUM_VARIANT", - "RECORD_FIELD_DEF_LIST", - "RECORD_FIELD_DEF", - "TUPLE_FIELD_DEF_LIST", - "TUPLE_FIELD_DEF", - "ENUM_VARIANT_LIST", - "ITEM_LIST", - "ATTR", - "META_ITEM", // not an item actually - "USE_TREE", - "USE_TREE_LIST", - "PATH", - "PATH_SEGMENT", - "LITERAL", - "ALIAS", - "VISIBILITY", - "WHERE_CLAUSE", - "WHERE_PRED", - "ABI", - "NAME", - "NAME_REF", - - "LET_STMT", - "EXPR_STMT", - - "TYPE_PARAM_LIST", - "LIFETIME_PARAM", - "TYPE_PARAM", - "CONST_PARAM", - "TYPE_ARG_LIST", - "LIFETIME_ARG", - "TYPE_ARG", - "ASSOC_TYPE_ARG", - - "PARAM_LIST", - "PARAM", - "SELF_PARAM", - "ARG_LIST", - "TYPE_BOUND", - "TYPE_BOUND_LIST", - - // macro related - "MACRO_ITEMS", - "MACRO_STMTS", - ], ast: { - "SourceFile": ( - traits: [ "ModuleItemOwner", "FnDefOwner" ], - collections: [ - ("modules", "Module"), - ] - ), - "FnDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner" - ], - options: [ "ParamList", ["body", "BlockExpr"], "RetType" ], - ), - "RetType": (options: ["TypeRef"]), - "StructDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner" - ] - ), - "UnionDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner" - ], - options: ["RecordFieldDefList"], - ), - "RecordFieldDefList": (collections: [("fields", "RecordFieldDef")]), - "RecordFieldDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "AttrsOwner", - "DocCommentsOwner", - "TypeAscriptionOwner" - ] - ), - "TupleFieldDefList": (collections: [("fields", "TupleFieldDef")]), - "TupleFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), - "EnumDef": ( traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner" - ], options: [["variant_list", "EnumVariantList"]] ), - "EnumVariantList": ( collections: [("variants", "EnumVariant")] ), - "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ), - "TraitDef": ( - traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"], - options: ["ItemList"] - ), - "Module": ( - traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ], - options: [ "ItemList" ] - ), - "ItemList": ( - collections: [("impl_items", "ImplItem")], - traits: [ "FnDefOwner", "ModuleItemOwner" ], - ), - "ConstDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner", - "TypeAscriptionOwner", - ], - options: [ ["body","Expr"]], - ), - "StaticDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner", - "TypeAscriptionOwner", - ], - options: [ ["body","Expr"]], - ), - "TypeAliasDef": ( - traits: [ - "VisibilityOwner", - "NameOwner", - "TypeParamsOwner", - "AttrsOwner", - "DocCommentsOwner", - "TypeBoundsOwner", - ], - options: ["TypeRef"] - ), - "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]), - - "ParenType": (options: ["TypeRef"]), - "TupleType": ( collections: [("fields", "TypeRef")] ), - "NeverType": (), - "PathType": (options: ["Path"]), - "PointerType": (options: ["TypeRef"]), - "ArrayType": ( options: ["TypeRef", "Expr"] ), - "SliceType": ( options: ["TypeRef"] ), - "ReferenceType": (options: ["TypeRef"]), - "PlaceholderType": (), - "FnPointerType": (options: ["ParamList", "RetType"]), - "ForType": (options: ["TypeRef"]), - "ImplTraitType": ( - traits: ["TypeBoundsOwner"], - ), - "DynTraitType": ( - traits: ["TypeBoundsOwner"], - ), - - "TypeRef": ( enum: [ - "ParenType", - "TupleType", - "NeverType", - "PathType", - "PointerType", - "ArrayType", - "SliceType", - "ReferenceType", - "PlaceholderType", - "FnPointerType", - "ForType", - "ImplTraitType", - "DynTraitType", - ]), - - "NominalDef": ( - enum: ["StructDef", "EnumDef", "UnionDef"], - traits: [ - "NameOwner", - "TypeParamsOwner", - "AttrsOwner" - ], - ), - "ModuleItem": ( - enum: ["StructDef", "UnionDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock", - "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ], - traits: ["AttrsOwner", "VisibilityOwner"], - ), - "ImplItem": ( - enum: ["FnDef", "TypeAliasDef", "ConstDef"], - traits: ["AttrsOwner"] - ), - - "TupleExpr": ( - collections: [("exprs", "Expr")] - ), - "ArrayExpr": ( - collections: [("exprs", "Expr")] - ), - "ParenExpr": (options: ["Expr"]), - "PathExpr": (options: ["Path"]), - "LambdaExpr": ( - options: [ - "ParamList", "RetType", - ["body", "Expr"], - ] - ), - "IfExpr": ( - options: [ "Condition" ] - ), - "LoopExpr": ( - traits: ["LoopBodyOwner"], - ), - "TryBlockExpr": ( - options: [["body", "BlockExpr"]], - ), - "ForExpr": ( - traits: ["LoopBodyOwner"], - options: [ - "Pat", - ["iterable", "Expr"], - ] - ), - "WhileExpr": ( - traits: ["LoopBodyOwner"], - options: [ "Condition" ] - ), - "ContinueExpr": (), - "BreakExpr": (options: ["Expr"]), - "Label": (), - "BlockExpr": ( - options: [ "Block" ] - ), - "ReturnExpr": (options: ["Expr"]), - "MatchExpr": ( - options: [ "Expr", "MatchArmList" ], - ), - "MatchArmList": ( - collections: [ ("arms", "MatchArm") ], - traits: [ "AttrsOwner" ] - ), - "MatchArm": ( - options: [ - [ "guard", "MatchGuard" ], - "Expr", - ], - collections: [ ("pats", "Pat") ], - traits: [ "AttrsOwner" ] - ), - "MatchGuard": (options: ["Expr"]), - "RecordLit": (options: ["Path", "RecordFieldList"]), - "RecordFieldList": ( - collections: [ ("fields", "RecordField") ], - options: [["spread", "Expr"]] - ), - "RecordField": (options: ["NameRef", "Expr"]), - "CallExpr": ( - traits: ["ArgListOwner"], - options: [ "Expr" ], - ), - "MethodCallExpr": ( - traits: ["ArgListOwner"], - options: [ "Expr", "NameRef", "TypeArgList" ], - ), - "IndexExpr": (), - "FieldExpr": (options: ["Expr", "NameRef"]), - "AwaitExpr": (options: ["Expr"]), - "TryExpr": (options: ["Expr"]), - "CastExpr": (options: ["Expr", "TypeRef"]), - "RefExpr": (options: ["Expr"]), - "PrefixExpr": (options: ["Expr"]), - "BoxExpr": (options: ["Expr"]), - "RangeExpr": (), - "BinExpr": (), - - "Literal": (), - - "Expr": ( - enum: [ - "TupleExpr", - "ArrayExpr", - "ParenExpr", - "PathExpr", - "LambdaExpr", - "IfExpr", - "LoopExpr", - "ForExpr", - "WhileExpr", - "ContinueExpr", - "BreakExpr", - "Label", - "BlockExpr", - "ReturnExpr", - "MatchExpr", - "RecordLit", - "CallExpr", - "IndexExpr", - "MethodCallExpr", - "FieldExpr", - "AwaitExpr", - "TryExpr", - "TryBlockExpr", - "CastExpr", - "RefExpr", - "PrefixExpr", - "RangeExpr", - "BinExpr", - "Literal", - "MacroCall", - "BoxExpr", - ], - ), - - "RefPat": ( options: [ "Pat" ]), - "BoxPat": ( options: [ "Pat" ]), - "BindPat": ( - options: [ "Pat" ], - traits: ["NameOwner"] - ), - "PlaceholderPat": (), - "DotDotPat": (), - "PathPat": ( options: [ "Path" ] ), - "RecordPat": ( options: ["RecordFieldPatList", "Path"] ), - "RecordFieldPatList": ( - collections: [ - ("record_field_pats", "RecordFieldPat"), - ("bind_pats", "BindPat"), - ] - ), - "RecordFieldPat": ( - traits: ["NameOwner"], - options: ["Pat"] - ), - "TupleStructPat": ( - options: ["Path"], - collections: [("args", "Pat")], - ), - "TuplePat": ( collections: [("args", "Pat")] ), - "SlicePat": (), - "RangePat": (), - "LiteralPat": (options: ["Literal"]), - - "Pat": ( - enum: [ - "RefPat", - "BoxPat", - "BindPat", - "PlaceholderPat", - "DotDotPat", - "PathPat", - "RecordPat", - "TupleStructPat", - "TuplePat", - "SlicePat", - "RangePat", - "LiteralPat", - ], - ), - - "Visibility": (), - "Name": (), - "NameRef": (), - "MacroCall": ( - traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ], - options: [ "TokenTree", "Path" ], - ), - "AttrInput": ( enum: [ "Literal", "TokenTree" ] ), - "Attr": ( options: [ "Path", [ "input", "AttrInput" ] ] ), - "TokenTree": (), - "TypeParamList": ( - collections: [ - ("type_params", "TypeParam" ), - ("lifetime_params", "LifetimeParam" ), - ] - ), - "TypeParam": ( - options: [("default_type", "TypeRef")], - traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], - ), - "ConstParam": ( - options: [("default_val", "Expr")], - traits: ["NameOwner", "AttrsOwner", "TypeAscriptionOwner"], - ), - "LifetimeParam": ( - traits: ["AttrsOwner"], - ), - "TypeBound": ( - options: [ - "TypeRef", - ] - ), - "TypeBoundList": ( - collections: [ - ("bounds", "TypeBound"), - ] - ), - "WherePred": ( - options: [ - "TypeRef", - ], - traits: [ - "TypeBoundsOwner", - ], - ), - "WhereClause": ( - collections: [ - ("predicates", "WherePred"), - ], - ), - "ExprStmt": ( - options: [ ["expr", "Expr"] ] - ), - "LetStmt": ( - options: [ - ["pat", "Pat"], - ["initializer", "Expr"], - ], - traits: [ - "TypeAscriptionOwner", - ] - ), - "Condition": ( - options: [ "Pat", "Expr" ] - ), - "Stmt": ( - enum: ["ExprStmt", "LetStmt"], - ), - "Block": ( - options: [ "Expr" ], - collections: [ - ("statements", "Stmt"), - ], - traits: [ - "AttrsOwner", - "ModuleItemOwner", - ] - ), - "ParamList": ( - options: [ "SelfParam" ], - collections: [ - ("params", "Param"), - ] - ), - "SelfParam": ( - traits: [ - "TypeAscriptionOwner", - "AttrsOwner", - ] - ), - "Param": ( - options: [ "Pat" ], - traits: [ - "TypeAscriptionOwner", - "AttrsOwner", - ] - ), - "UseItem": ( - traits: ["AttrsOwner", "VisibilityOwner"], - options: [ "UseTree" ], - ), - "UseTree": ( - options: [ "Path", "UseTreeList", "Alias" ] - ), - "Alias": ( - traits: ["NameOwner"], - ), - "UseTreeList": ( - collections: [("use_trees", "UseTree")] - ), - "ExternCrateItem": ( - traits: ["AttrsOwner", "VisibilityOwner"], - options: ["NameRef", "Alias"], - ), - "ArgList": ( - collections: [ - ("args", "Expr"), - ] - ), - "Path": ( - options: [ - ["segment", "PathSegment"], - ["qualifier", "Path"], - ] - ), - "PathSegment": ( - options: [ "NameRef", "TypeArgList", "ParamList", "RetType", "PathType" ] - ), - "TypeArgList": (collections: [ - ("type_args", "TypeArg"), - ("lifetime_args", "LifetimeArg"), - ("assoc_type_args", "AssocTypeArg"), - ]), - "TypeArg": (options: ["TypeRef"]), - "AssocTypeArg": (options: ["NameRef", "TypeRef"]), - "LifetimeArg": (), - - "MacroItems": ( - traits: [ "ModuleItemOwner", "FnDefOwner" ], - ), - - "MacroStmts" : ( - options: [ "Expr" ], - collections: [ - ("statements", "Stmt"), - ], - ) }, ) diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 65cabf00533..72dd5e5812b 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -13,6 +13,4 @@ walkdir = "2.1.3" pico-args = "0.3.0" quote = "1.0.2" proc-macro2 = "1.0.1" -ron = "0.5.1" -serde = { version = "1.0.0", features = ["derive"] } anyhow = "1.0.19" diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs new file mode 100644 index 00000000000..d494a4a3832 --- /dev/null +++ b/xtask/src/ast_src.rs @@ -0,0 +1,618 @@ +pub(crate) struct KindsSrc<'a> { + pub(crate) punct: &'a [(&'a str, &'a str)], + pub(crate) keywords: &'a [&'a str], + pub(crate) contextual_keywords: &'a [&'a str], + pub(crate) literals: &'a [&'a str], + pub(crate) tokens: &'a [&'a str], + pub(crate) nodes: &'a [&'a str], +} + +pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { + punct: &[ + (";", "SEMI"), + (",", "COMMA"), + ("(", "L_PAREN"), + (")", "R_PAREN"), + ("{", "L_CURLY"), + ("}", "R_CURLY"), + ("[", "L_BRACK"), + ("]", "R_BRACK"), + ("<", "L_ANGLE"), + (">", "R_ANGLE"), + ("@", "AT"), + ("#", "POUND"), + ("~", "TILDE"), + ("?", "QUESTION"), + ("$", "DOLLAR"), + ("&", "AMP"), + ("|", "PIPE"), + ("+", "PLUS"), + ("*", "STAR"), + ("/", "SLASH"), + ("^", "CARET"), + ("%", "PERCENT"), + ("_", "UNDERSCORE"), + (".", "DOT"), + ("..", "DOTDOT"), + ("...", "DOTDOTDOT"), + ("..=", "DOTDOTEQ"), + (":", "COLON"), + ("::", "COLONCOLON"), + ("=", "EQ"), + ("==", "EQEQ"), + ("=>", "FAT_ARROW"), + ("!", "EXCL"), + ("!=", "NEQ"), + ("-", "MINUS"), + ("->", "THIN_ARROW"), + ("<=", "LTEQ"), + (">=", "GTEQ"), + ("+=", "PLUSEQ"), + ("-=", "MINUSEQ"), + ("|=", "PIPEEQ"), + ("&=", "AMPEQ"), + ("^=", "CARETEQ"), + ("/=", "SLASHEQ"), + ("*=", "STAREQ"), + ("%=", "PERCENTEQ"), + ("&&", "AMPAMP"), + ("||", "PIPEPIPE"), + ("<<", "SHL"), + (">>", "SHR"), + ("<<=", "SHLEQ"), + (">>=", "SHREQ"), + ], + keywords: &[ + "as", "async", "await", "box", "break", "const", "continue", "crate", "dyn", "else", + "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro", + "match", "mod", "move", "mut", "pub", "ref", "return", "self", "static", "struct", "super", + "trait", "true", "try", "type", "unsafe", "use", "where", "while", + ], + contextual_keywords: &["auto", "default", "existential", "union"], + literals: &[ + "INT_NUMBER", + "FLOAT_NUMBER", + "CHAR", + "BYTE", + "STRING", + "RAW_STRING", + "BYTE_STRING", + "RAW_BYTE_STRING", + ], + tokens: &[ + "ERROR", + "IDENT", + "WHITESPACE", + "LIFETIME", + "COMMENT", + "SHEBANG", + "L_DOLLAR", + "R_DOLLAR", + ], + nodes: &[ + "SOURCE_FILE", + "STRUCT_DEF", + "UNION_DEF", + "ENUM_DEF", + "FN_DEF", + "RET_TYPE", + "EXTERN_CRATE_ITEM", + "MODULE", + "USE_ITEM", + "STATIC_DEF", + "CONST_DEF", + "TRAIT_DEF", + "IMPL_BLOCK", + "TYPE_ALIAS_DEF", + "MACRO_CALL", + "TOKEN_TREE", + "MACRO_DEF", + "PAREN_TYPE", + "TUPLE_TYPE", + "NEVER_TYPE", + "PATH_TYPE", + "POINTER_TYPE", + "ARRAY_TYPE", + "SLICE_TYPE", + "REFERENCE_TYPE", + "PLACEHOLDER_TYPE", + "FN_POINTER_TYPE", + "FOR_TYPE", + "IMPL_TRAIT_TYPE", + "DYN_TRAIT_TYPE", + "REF_PAT", + "BOX_PAT", + "BIND_PAT", + "PLACEHOLDER_PAT", + "DOT_DOT_PAT", + "PATH_PAT", + "RECORD_PAT", + "RECORD_FIELD_PAT_LIST", + "RECORD_FIELD_PAT", + "TUPLE_STRUCT_PAT", + "TUPLE_PAT", + "SLICE_PAT", + "RANGE_PAT", + "LITERAL_PAT", + // atoms + "TUPLE_EXPR", + "ARRAY_EXPR", + "PAREN_EXPR", + "PATH_EXPR", + "LAMBDA_EXPR", + "IF_EXPR", + "WHILE_EXPR", + "CONDITION", + "LOOP_EXPR", + "FOR_EXPR", + "CONTINUE_EXPR", + "BREAK_EXPR", + "LABEL", + "BLOCK_EXPR", + "RETURN_EXPR", + "MATCH_EXPR", + "MATCH_ARM_LIST", + "MATCH_ARM", + "MATCH_GUARD", + "RECORD_LIT", + "RECORD_FIELD_LIST", + "RECORD_FIELD", + "TRY_BLOCK_EXPR", + "BOX_EXPR", + // postfix + "CALL_EXPR", + "INDEX_EXPR", + "METHOD_CALL_EXPR", + "FIELD_EXPR", + "AWAIT_EXPR", + "TRY_EXPR", + "CAST_EXPR", + // unary + "REF_EXPR", + "PREFIX_EXPR", + "RANGE_EXPR", // just weird + "BIN_EXPR", + "BLOCK", + "EXTERN_BLOCK", + "EXTERN_ITEM_LIST", + "ENUM_VARIANT", + "RECORD_FIELD_DEF_LIST", + "RECORD_FIELD_DEF", + "TUPLE_FIELD_DEF_LIST", + "TUPLE_FIELD_DEF", + "ENUM_VARIANT_LIST", + "ITEM_LIST", + "ATTR", + "META_ITEM", // not an item actually + "USE_TREE", + "USE_TREE_LIST", + "PATH", + "PATH_SEGMENT", + "LITERAL", + "ALIAS", + "VISIBILITY", + "WHERE_CLAUSE", + "WHERE_PRED", + "ABI", + "NAME", + "NAME_REF", + "LET_STMT", + "EXPR_STMT", + "TYPE_PARAM_LIST", + "LIFETIME_PARAM", + "TYPE_PARAM", + "CONST_PARAM", + "TYPE_ARG_LIST", + "LIFETIME_ARG", + "TYPE_ARG", + "ASSOC_TYPE_ARG", + "PARAM_LIST", + "PARAM", + "SELF_PARAM", + "ARG_LIST", + "TYPE_BOUND", + "TYPE_BOUND_LIST", + // macro related + "MACRO_ITEMS", + "MACRO_STMTS", + ], +}; + +pub(crate) struct AstSrc<'a> { + pub(crate) nodes: &'a [AstNodeSrc<'a>], + pub(crate) enums: &'a [AstEnumSrc<'a>], +} + +pub(crate) struct AstNodeSrc<'a> { + pub(crate) name: &'a str, + pub(crate) traits: &'a [&'a str], + pub(crate) fields: &'a [(&'a str, FieldSrc<&'a str>)], +} + +pub(crate) enum FieldSrc { + Shorthand, + Optional(T), + Many(T), +} + +pub(crate) struct AstEnumSrc<'a> { + pub(crate) name: &'a str, + pub(crate) traits: &'a [&'a str], + pub(crate) variants: &'a [&'a str], +} + +macro_rules! ast_nodes { + ($( + struct $name:ident$(: $($trait:ident),*)? { + $($field_name:ident $(: $ty:tt)?),*$(,)? + } + )*) => { + [$( + AstNodeSrc { + name: stringify!($name), + traits: &[$($(stringify!($trait)),*)?], + fields: &[$( + (stringify!($field_name), field_ty!($field_name $($ty)?)) + ),*], + + } + ),*] + }; +} + +macro_rules! field_ty { + ($field_name:ident) => { + FieldSrc::Shorthand + }; + ($field_name:ident [$ty:ident]) => { + FieldSrc::Many(stringify!($ty)) + }; + ($field_name:ident $ty:ident) => { + FieldSrc::Optional(stringify!($ty)) + }; +} + +macro_rules! ast_enums { + ($( + enum $name:ident $(: $($trait:ident),*)? { + $($variant:ident),*$(,)? + } + )*) => { + [$( + AstEnumSrc { + name: stringify!($name), + traits: &[$($(stringify!($trait)),*)?], + variants: &[$(stringify!($variant)),*], + + } + ),*] + }; +} + +pub(crate) const AST_SRC: AstSrc = AstSrc { + nodes: &ast_nodes! { + struct SourceFile: ModuleItemOwner, FnDefOwner { + modules: [Module], + } + + struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { + ParamList, + RetType, + body: BlockExpr, + } + + struct RetType { TypeRef } + + struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { + } + + struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { + RecordFieldDefList, + } + + struct RecordFieldDefList { fields: [RecordFieldDef] } + struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { } + + struct TupleFieldDefList { fields: [TupleFieldDef] } + struct TupleFieldDef: VisibilityOwner, AttrsOwner { + TypeRef, + } + + struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { + variant_list: EnumVariantList, + } + struct EnumVariantList { + variants: [EnumVariant], + } + struct EnumVariant: NameOwner, DocCommentsOwner, AttrsOwner { + Expr + } + + struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { + ItemList, + } + + struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { + ItemList, + } + + struct ItemList: FnDefOwner, ModuleItemOwner { + impl_items: [ImplItem], + } + + struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { + body: Expr, + } + + struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { + body: Expr, + } + + struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { + TypeRef, + } + + struct ImplBlock: TypeParamsOwner, AttrsOwner { + ItemList, + } + + struct ParenType { TypeRef } + struct TupleType { fields: [TypeRef] } + struct NeverType { } + struct PathType { Path } + struct PointerType { TypeRef } + struct ArrayType { TypeRef, Expr } + struct SliceType { TypeRef } + struct ReferenceType { TypeRef } + struct PlaceholderType { } + struct FnPointerType { ParamList, RetType } + struct ForType { TypeRef } + struct ImplTraitType: TypeBoundsOwner {} + struct DynTraitType: TypeBoundsOwner {} + + struct TupleExpr { exprs: [Expr] } + struct ArrayExpr { exprs: [Expr] } + struct ParenExpr { Expr } + struct PathExpr { Path } + struct LambdaExpr { + ParamList, + RetType, + body: Expr, + } + struct IfExpr { Condition } + struct LoopExpr: LoopBodyOwner { } + struct TryBlockExpr { body: BlockExpr } + struct ForExpr: LoopBodyOwner { + Pat, + iterable: Expr, + } + struct WhileExpr: LoopBodyOwner { Condition } + struct ContinueExpr {} + struct BreakExpr { Expr } + struct Label {} + struct BlockExpr { Block } + struct ReturnExpr { Expr } + struct CallExpr: ArgListOwner { Expr } + struct MethodCallExpr: ArgListOwner { + Expr, NameRef, TypeArgList, + } + struct IndexExpr {} + struct FieldExpr { Expr, NameRef } + struct AwaitExpr { Expr } + struct TryExpr { Expr } + struct CastExpr { Expr, TypeRef } + struct RefExpr { Expr } + struct PrefixExpr { Expr } + struct BoxExpr { Expr } + struct RangeExpr {} + struct BinExpr {} + struct Literal {} + + struct MatchExpr { Expr, MatchArmList } + struct MatchArmList: AttrsOwner { arms: [MatchArm] } + struct MatchArm: AttrsOwner { + pats: [Pat], + guard: MatchGuard, + Expr, + } + struct MatchGuard { Expr } + + struct RecordLit { Path, RecordFieldList } + struct RecordFieldList { + fields: [RecordField], + spread: Expr, + } + struct RecordField { NameRef, Expr } + + struct RefPat { Pat } + struct BoxPat { Pat } + struct BindPat: NameOwner { Pat } + struct PlaceholderPat { } + struct DotDotPat { } + struct PathPat { Path } + struct SlicePat {} + struct RangePat {} + struct LiteralPat { Literal } + + struct RecordPat { RecordFieldPatList, Path } + struct RecordFieldPatList { + record_field_pats: [RecordFieldPat], + bind_pats: [BindPat], + } + struct RecordFieldPat: NameOwner { Pat } + + struct TupleStructPat { Path, args: [Pat] } + struct TuplePat { args: [Pat] } + + struct Visibility {} + struct Name {} + struct NameRef {} + + struct MacroCall: NameOwner, AttrsOwner,DocCommentsOwner { + TokenTree, Path + } + struct Attr { Path, input: AttrInput } + struct TokenTree {} + struct TypeParamList { + type_params: [TypeParam], + lifetime_params: [LifetimeParam], + } + struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner { + default_type: TypeRef, + } + struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner { + default_val: Expr, + } + struct LifetimeParam: AttrsOwner { } + struct TypeBound { TypeRef} + struct TypeBoundList { bounds: [TypeBound] } + struct WherePred: TypeBoundsOwner { TypeRef } + struct WhereClause { predicates: [WherePred] } + struct ExprStmt { Expr } + struct LetStmt: TypeAscriptionOwner { + Pat, + initializer: Expr, + } + struct Condition { Pat, Expr } + struct Block: AttrsOwner, ModuleItemOwner { + statements: [Stmt], + Expr, + } + struct ParamList { + SelfParam, + params: [Param], + } + struct SelfParam: TypeAscriptionOwner, AttrsOwner { } + struct Param: TypeAscriptionOwner, AttrsOwner { + Pat, + } + struct UseItem: AttrsOwner, VisibilityOwner { + UseTree, + } + struct UseTree { + Path, UseTreeList, Alias + } + struct Alias: NameOwner { } + struct UseTreeList { use_trees: [UseTree] } + struct ExternCrateItem: AttrsOwner, VisibilityOwner { + NameRef, Alias, + } + struct ArgList { + args: [Expr], + } + struct Path { + segment: PathSegment, + qualifier: Path, + } + struct PathSegment { + NameRef, TypeArgList, ParamList, RetType, PathType, + } + struct TypeArgList { + type_args: [TypeArg], + lifetime_args: [LifetimeArg], + assoc_type_args: [AssocTypeArg], + } + struct TypeArg { TypeRef } + struct AssocTypeArg { NameRef, TypeRef } + struct LifetimeArg {} + + struct MacroItems: ModuleItemOwner, FnDefOwner { } + + struct MacroStmts { + statements: [Stmt], + Expr, + } + }, + enums: &ast_enums! { + enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner { + StructDef, EnumDef, UnionDef, + } + + enum TypeRef { + ParenType, + TupleType, + NeverType, + PathType, + PointerType, + ArrayType, + SliceType, + ReferenceType, + PlaceholderType, + FnPointerType, + ForType, + ImplTraitType, + DynTraitType, + } + + enum ModuleItem: AttrsOwner, VisibilityOwner { + StructDef, + UnionDef, + EnumDef, + FnDef, + TraitDef, + TypeAliasDef, + ImplBlock, + UseItem, + ExternCrateItem, + ConstDef, + StaticDef, + Module, + } + + enum ImplItem: AttrsOwner { + FnDef, TypeAliasDef, ConstDef, + } + + enum Expr { + TupleExpr, + ArrayExpr, + ParenExpr, + PathExpr, + LambdaExpr, + IfExpr, + LoopExpr, + ForExpr, + WhileExpr, + ContinueExpr, + BreakExpr, + Label, + BlockExpr, + ReturnExpr, + MatchExpr, + RecordLit, + CallExpr, + IndexExpr, + MethodCallExpr, + FieldExpr, + AwaitExpr, + TryExpr, + TryBlockExpr, + CastExpr, + RefExpr, + PrefixExpr, + RangeExpr, + BinExpr, + Literal, + MacroCall, + BoxExpr, + } + + enum Pat { + RefPat, + BoxPat, + BindPat, + PlaceholderPat, + DotDotPat, + PathPat, + RecordPat, + TupleStructPat, + TuplePat, + SlicePat, + RangePat, + LiteralPat, + } + + enum AttrInput { Literal, TokenTree } + enum Stmt { ExprStmt, LetStmt } + }, +}; diff --git a/xtask/src/boilerplate_gen.rs b/xtask/src/boilerplate_gen.rs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 53f524f42df..158cfc2d680 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -24,7 +24,6 @@ pub use self::{ gen_syntax::generate_syntax, }; -pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 88f2ac0e35e..0f50ca56933 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -3,152 +3,145 @@ //! Specifically, it generates the `SyntaxKind` enum and a number of newtype //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. -use std::{collections::BTreeMap, fs}; - use proc_macro2::{Punct, Spacing}; use quote::{format_ident, quote}; -use ron; -use serde::Deserialize; use crate::{ + ast_src::{AstSrc, FieldSrc, KindsSrc, AST_SRC, KINDS_SRC}, codegen::{self, update, Mode}, project_root, Result, }; pub fn generate_syntax(mode: Mode) -> Result<()> { - let grammar = project_root().join(codegen::GRAMMAR); - let grammar: Grammar = { - let text = fs::read_to_string(grammar)?; - ron::de::from_str(&text)? - }; - let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS); - let syntax_kinds = generate_syntax_kinds(&grammar)?; + let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; let ast_file = project_root().join(codegen::AST); - let ast = generate_ast(&grammar)?; + let ast = generate_ast(AST_SRC)?; update(ast_file.as_path(), &ast, mode)?; Ok(()) } -fn generate_ast(grammar: &Grammar) -> Result { - let nodes = grammar.ast.iter().map(|(name, ast_node)| { - let variants = - ast_node.variants.iter().map(|var| format_ident!("{}", var)).collect::>(); - let name = format_ident!("{}", name); - - let adt = if variants.is_empty() { - let kind = format_ident!("{}", to_upper_snake_case(&name.to_string())); - quote! { - #[derive(Debug, Clone, PartialEq, Eq, Hash)] - pub struct #name { - pub(crate) syntax: SyntaxNode, - } - - impl AstNode for #name { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - #kind => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } - } - } - } else { - let kinds = variants - .iter() - .map(|name| format_ident!("{}", to_upper_snake_case(&name.to_string()))) - .collect::>(); - - quote! { - #[derive(Debug, Clone, PartialEq, Eq, Hash)] - pub enum #name { - #(#variants(#variants),)* - } - - #( - impl From<#variants> for #name { - fn from(node: #variants) -> #name { - #name::#variants(node) - } - } - )* - - impl AstNode for #name { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - #(#kinds)|* => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - #( - #kinds => #name::#variants(#variants { syntax }), - )* - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - #( - #name::#variants(it) => &it.syntax, - )* - } - } - } - } - }; - - let traits = ast_node.traits.iter().map(|trait_name| { +fn generate_ast(grammar: AstSrc<'_>) -> Result { + let nodes = grammar.nodes.iter().map(|node| { + let name = format_ident!("{}", node.name); + let kind = format_ident!("{}", to_upper_snake_case(&name.to_string())); + let traits = node.traits.iter().map(|trait_name| { let trait_name = format_ident!("{}", trait_name); quote!(impl ast::#trait_name for #name {}) }); - let collections = ast_node.collections.iter().map(|(name, kind)| { - let method_name = format_ident!("{}", name); - let kind = format_ident!("{}", kind); - quote! { - pub fn #method_name(&self) -> AstChildren<#kind> { - AstChildren::new(&self.syntax) - } - } - }); + let methods = node.fields.iter().map(|(name, field)| { + let method_name = match field { + FieldSrc::Shorthand => format_ident!("{}", to_lower_snake_case(&name)), + _ => format_ident!("{}", name), + }; + let ty = match field { + FieldSrc::Optional(ty) | FieldSrc::Many(ty) => ty, + FieldSrc::Shorthand => name, + }; + let ty = format_ident!("{}", ty); - let options = ast_node.options.iter().map(|attr| { - let method_name = match attr { - Attr::Type(t) => format_ident!("{}", to_lower_snake_case(&t)), - Attr::NameType(n, _) => format_ident!("{}", n), - }; - let ty = match attr { - Attr::Type(t) | Attr::NameType(_, t) => format_ident!("{}", t), - }; - quote! { - pub fn #method_name(&self) -> Option<#ty> { - AstChildren::new(&self.syntax).next() + match field { + FieldSrc::Many(_) => { + quote! { + pub fn #method_name(&self) -> AstChildren<#ty> { + AstChildren::new(&self.syntax) + } + } + } + FieldSrc::Optional(_) | FieldSrc::Shorthand => { + quote! { + pub fn #method_name(&self) -> Option<#ty> { + AstChildren::new(&self.syntax).next() + } + } } } }); quote! { - #adt + #[derive(Debug, Clone, PartialEq, Eq, Hash)] + pub struct #name { + pub(crate) syntax: SyntaxNode, + } + impl AstNode for #name { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + #kind => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } + } #(#traits)* impl #name { - #(#collections)* - #(#options)* + #(#methods)* } } }); + let enums = grammar.enums.iter().map(|en| { + let variants = en.variants.iter().map(|var| format_ident!("{}", var)).collect::>(); + let name = format_ident!("{}", en.name); + let kinds = variants + .iter() + .map(|name| format_ident!("{}", to_upper_snake_case(&name.to_string()))) + .collect::>(); + let traits = en.traits.iter().map(|trait_name| { + let trait_name = format_ident!("{}", trait_name); + quote!(impl ast::#trait_name for #name {}) + }); + + quote! { + #[derive(Debug, Clone, PartialEq, Eq, Hash)] + pub enum #name { + #(#variants(#variants),)* + } + + #( + impl From<#variants> for #name { + fn from(node: #variants) -> #name { + #name::#variants(node) + } + } + )* + + impl AstNode for #name { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + #(#kinds)|* => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + #( + #kinds => #name::#variants(#variants { syntax }), + )* + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + #( + #name::#variants(it) => &it.syntax, + )* + } + } + } + #(#traits)* + } + }); + let ast = quote! { use crate::{ SyntaxNode, SyntaxKind::{self, *}, @@ -156,13 +149,14 @@ fn generate_ast(grammar: &Grammar) -> Result { }; #(#nodes)* + #(#enums)* }; let pretty = codegen::reformat(ast)?; Ok(pretty) } -fn generate_syntax_kinds(grammar: &Grammar) -> Result { +fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result { let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar .punct .iter() @@ -274,38 +268,6 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result { codegen::reformat(ast) } -#[derive(Deserialize, Debug)] -struct Grammar { - punct: Vec<(String, String)>, - keywords: Vec, - contextual_keywords: Vec, - literals: Vec, - tokens: Vec, - nodes: Vec, - ast: BTreeMap, -} - -#[derive(Deserialize, Debug)] -struct AstNode { - #[serde(default)] - #[serde(rename = "enum")] - variants: Vec, - - #[serde(default)] - traits: Vec, - #[serde(default)] - collections: Vec<(String, String)>, - #[serde(default)] - options: Vec, -} - -#[derive(Deserialize, Debug)] -#[serde(untagged)] -enum Attr { - Type(String), - NameType(String, String), -} - fn to_upper_snake_case(s: &str) -> String { let mut buf = String::with_capacity(s.len()); let mut prev_is_upper = None; diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 40a6682be99..51a868dee97 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here pub mod codegen; +mod ast_src; use anyhow::Context; pub use anyhow::Result;