diff --git a/crates/cairo-lang-doc/src/parser.rs b/crates/cairo-lang-doc/src/parser.rs index 90d630503ab..3d2a0e2b58a 100644 --- a/crates/cairo-lang-doc/src/parser.rs +++ b/crates/cairo-lang-doc/src/parser.rs @@ -14,7 +14,6 @@ use cairo_lang_semantic::items::functions::GenericFunctionId; use cairo_lang_semantic::resolve::{AsSegments, ResolvedGenericItem, Resolver}; use cairo_lang_syntax::node::ast::{Expr, ExprPath, ItemModule}; use cairo_lang_syntax::node::helpers::GetIdentifier; -use cairo_lang_syntax::node::kind::SyntaxKind; use cairo_lang_syntax::node::{SyntaxNode, TypedSyntaxNode}; use cairo_lang_utils::Intern; use pulldown_cmark::{ @@ -230,9 +229,9 @@ impl<'a> DocumentationCommentParser<'a> { // Get the stack (bottom-up) of submodule names in the file containing the node, in the main // module, that lead to the node. iter::successors(node.parent(), SyntaxNode::parent) - .filter(|node| node.kind(syntax_db) == SyntaxKind::ItemModule) - .map(|node| { - ItemModule::from_syntax_node(syntax_db, node) + .filter_map(|node| ItemModule::cast(syntax_db, node)) + .map(|item_module| { + item_module .stable_ptr() .name_green(syntax_db) .identifier(syntax_db) diff --git a/crates/cairo-lang-formatter/src/formatter_impl.rs b/crates/cairo-lang-formatter/src/formatter_impl.rs index 52535fa1f35..f9fb1682d20 100644 --- a/crates/cairo-lang-formatter/src/formatter_impl.rs +++ b/crates/cairo-lang-formatter/src/formatter_impl.rs @@ -1081,13 +1081,10 @@ impl<'a> FormatterImpl<'a> { /// Returns whether the node has only whitespace trivia. fn has_only_whitespace_trivia(&self, node: &SyntaxNode) -> bool { node.descendants(self.db).all(|descendant| { - if descendant.kind(self.db) == SyntaxKind::Trivia { - ast::Trivia::from_syntax_node(self.db, descendant) - .elements(self.db) - .into_iter() - .all(|element| { - matches!(element, ast::Trivium::Whitespace(_) | ast::Trivium::Newline(_)) - }) + if let Some(trivia) = ast::Trivia::cast(self.db, descendant) { + trivia.elements(self.db).into_iter().all(|element| { + matches!(element, ast::Trivium::Whitespace(_) | ast::Trivium::Newline(_)) + }) } else { true } diff --git a/crates/cairo-lang-plugins/src/plugins/generate_trait.rs b/crates/cairo-lang-plugins/src/plugins/generate_trait.rs index c7661704549..fc838b1c000 100644 --- a/crates/cairo-lang-plugins/src/plugins/generate_trait.rs +++ b/crates/cairo-lang-plugins/src/plugins/generate_trait.rs @@ -7,7 +7,6 @@ use cairo_lang_defs::plugin::{ use cairo_lang_syntax::attribute::structured::{AttributeArgVariant, AttributeStructurize}; use cairo_lang_syntax::node::db::SyntaxGroup; use cairo_lang_syntax::node::helpers::{BodyItems, GenericParamEx, QueryAttrs}; -use cairo_lang_syntax::node::kind::SyntaxKind; use cairo_lang_syntax::node::{Terminal, TypedSyntaxNode, ast}; #[derive(Debug, Default)] @@ -160,10 +159,7 @@ fn generate_trait_for_impl(db: &dyn SyntaxGroup, impl_ast: ast::ItemImpl) -> Plu for node in db.get_children(signature.parameters(db).node.clone()).iter().cloned() { - if node.kind(db) != SyntaxKind::Param { - builder.add_node(node); - } else { - let param = ast::Param::from_syntax_node(db, node); + if let Some(param) = ast::Param::cast(db, node.clone()) { for modifier in param.modifiers(db).elements(db) { // `mut` modifiers are only relevant for impls, not traits. if !matches!(modifier, ast::Modifier::Mut(_)) { @@ -172,6 +168,8 @@ fn generate_trait_for_impl(db: &dyn SyntaxGroup, impl_ast: ast::ItemImpl) -> Plu } builder.add_node(param.name(db).as_syntax_node()); builder.add_node(param.type_clause(db).as_syntax_node()); + } else { + builder.add_node(node); } } let rparen = signature.rparen(db); diff --git a/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs b/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs index de34c310d46..3c293fa9bae 100644 --- a/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs +++ b/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs @@ -10,9 +10,8 @@ use cairo_lang_plugins::plugins::HasItemsInCfgEx; use cairo_lang_syntax::node::ast::MaybeModuleBody; use cairo_lang_syntax::node::db::SyntaxGroup; use cairo_lang_syntax::node::helpers::{BodyItems, QueryAttrs}; -use cairo_lang_syntax::node::kind::SyntaxKind; use cairo_lang_syntax::node::{SyntaxNode, Terminal, TypedSyntaxNode, ast}; -use cairo_lang_utils::{extract_matches, require}; +use cairo_lang_utils::extract_matches; use self::component::generate_component_specific_code; use self::contract::generate_contract_specific_code; @@ -244,8 +243,7 @@ fn grand_grand_parent_starknet_module( // Get the containing module node. The parent is the item list, the grand parent is the module // body, and the grand grand parent is the module. let module_node = item_node.parent()?.parent()?.parent()?; - require(module_node.kind(db) == SyntaxKind::ItemModule)?; - let module_ast = ast::ItemModule::from_syntax_node(db, module_node); + let module_ast = ast::ItemModule::cast(db, module_node)?; let (module_kind, attr) = StarknetModuleKind::from_module(db, &module_ast)?; Some((module_ast, module_kind, attr)) } diff --git a/crates/cairo-lang-syntax-codegen/src/generator.rs b/crates/cairo-lang-syntax-codegen/src/generator.rs index 2182703963e..a00f15db7b6 100644 --- a/crates/cairo-lang-syntax-codegen/src/generator.rs +++ b/crates/cairo-lang-syntax-codegen/src/generator.rs @@ -366,6 +366,13 @@ fn gen_common_list_code(name: &str, green_name: &str, ptr_name: &str) -> rust::T fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::$name { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -390,6 +397,7 @@ fn gen_enum_code( let green_name = format!("{name}Green"); let mut enum_body = quote! {}; let mut from_node_body = quote! {}; + let mut cast_body = quote! {}; let mut ptr_conversions = quote! {}; let mut green_conversions = quote! {}; for variant in &variants { @@ -402,6 +410,9 @@ fn gen_enum_code( from_node_body.extend(quote! { SyntaxKind::$k => $(&name)::$n($k::from_syntax_node(db, node)), }); + cast_body.extend(quote! { + SyntaxKind::$k => Some($(&name)::$n($k::from_syntax_node(db, node))), + }); let variant_ptr = format!("{k}Ptr"); ptr_conversions.extend(quote! { impl From<$(&variant_ptr)> for $(&ptr_name) { @@ -469,6 +480,13 @@ fn gen_enum_code( $[str]($[const](&name))), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + $cast_body + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { $(for v in &variants => $(&name)::$(&v.name)(x) => x.as_syntax_node(),) @@ -556,6 +574,12 @@ fn gen_token_code(name: String) -> rust::Tokens { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -706,6 +730,14 @@ fn gen_struct_code(name: String, members: Vec, is_terminal: bool) -> rus let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::$(&name) { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index f57b3a59fea..ea4aca9380b 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -76,6 +76,9 @@ impl TypedSyntaxNode for Trivia { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::Trivia { Some(Self(ElementList::new(node))) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -216,6 +219,33 @@ impl TypedSyntaxNode for Trivium { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Trivium"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TokenSingleLineComment => { + Some(Trivium::SingleLineComment(TokenSingleLineComment::from_syntax_node(db, node))) + } + SyntaxKind::TokenSingleLineDocComment => Some(Trivium::SingleLineDocComment( + TokenSingleLineDocComment::from_syntax_node(db, node), + )), + SyntaxKind::TokenSingleLineInnerComment => Some(Trivium::SingleLineInnerComment( + TokenSingleLineInnerComment::from_syntax_node(db, node), + )), + SyntaxKind::TokenWhitespace => { + Some(Trivium::Whitespace(TokenWhitespace::from_syntax_node(db, node))) + } + SyntaxKind::TokenNewline => { + Some(Trivium::Newline(TokenNewline::from_syntax_node(db, node))) + } + SyntaxKind::TokenSkipped => { + Some(Trivium::Skipped(TokenSkipped::from_syntax_node(db, node))) + } + SyntaxKind::TriviumSkippedNode => { + Some(Trivium::SkippedNode(TriviumSkippedNode::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Trivium::SingleLineComment(x) => x.as_syntax_node(), @@ -605,6 +635,61 @@ impl TypedSyntaxNode for Expr { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Expr"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ExprPath => Some(Expr::Path(ExprPath::from_syntax_node(db, node))), + SyntaxKind::TerminalLiteralNumber => { + Some(Expr::Literal(TerminalLiteralNumber::from_syntax_node(db, node))) + } + SyntaxKind::TerminalShortString => { + Some(Expr::ShortString(TerminalShortString::from_syntax_node(db, node))) + } + SyntaxKind::TerminalString => { + Some(Expr::String(TerminalString::from_syntax_node(db, node))) + } + SyntaxKind::TerminalFalse => { + Some(Expr::False(TerminalFalse::from_syntax_node(db, node))) + } + SyntaxKind::TerminalTrue => Some(Expr::True(TerminalTrue::from_syntax_node(db, node))), + SyntaxKind::ExprParenthesized => { + Some(Expr::Parenthesized(ExprParenthesized::from_syntax_node(db, node))) + } + SyntaxKind::ExprUnary => Some(Expr::Unary(ExprUnary::from_syntax_node(db, node))), + SyntaxKind::ExprBinary => Some(Expr::Binary(ExprBinary::from_syntax_node(db, node))), + SyntaxKind::ExprListParenthesized => { + Some(Expr::Tuple(ExprListParenthesized::from_syntax_node(db, node))) + } + SyntaxKind::ExprFunctionCall => { + Some(Expr::FunctionCall(ExprFunctionCall::from_syntax_node(db, node))) + } + SyntaxKind::ExprStructCtorCall => { + Some(Expr::StructCtorCall(ExprStructCtorCall::from_syntax_node(db, node))) + } + SyntaxKind::ExprBlock => Some(Expr::Block(ExprBlock::from_syntax_node(db, node))), + SyntaxKind::ExprMatch => Some(Expr::Match(ExprMatch::from_syntax_node(db, node))), + SyntaxKind::ExprIf => Some(Expr::If(ExprIf::from_syntax_node(db, node))), + SyntaxKind::ExprLoop => Some(Expr::Loop(ExprLoop::from_syntax_node(db, node))), + SyntaxKind::ExprWhile => Some(Expr::While(ExprWhile::from_syntax_node(db, node))), + SyntaxKind::ExprFor => Some(Expr::For(ExprFor::from_syntax_node(db, node))), + SyntaxKind::ExprClosure => Some(Expr::Closure(ExprClosure::from_syntax_node(db, node))), + SyntaxKind::ExprErrorPropagate => { + Some(Expr::ErrorPropagate(ExprErrorPropagate::from_syntax_node(db, node))) + } + SyntaxKind::ExprFieldInitShorthand => { + Some(Expr::FieldInitShorthand(ExprFieldInitShorthand::from_syntax_node(db, node))) + } + SyntaxKind::ExprIndexed => Some(Expr::Indexed(ExprIndexed::from_syntax_node(db, node))), + SyntaxKind::ExprInlineMacro => { + Some(Expr::InlineMacro(ExprInlineMacro::from_syntax_node(db, node))) + } + SyntaxKind::ExprFixedSizeArray => { + Some(Expr::FixedSizeArray(ExprFixedSizeArray::from_syntax_node(db, node))) + } + SyntaxKind::ExprMissing => Some(Expr::Missing(ExprMissing::from_syntax_node(db, node))), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Expr::Path(x) => x.as_syntax_node(), @@ -759,6 +844,13 @@ impl TypedSyntaxNode for ExprList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ExprList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -850,6 +942,10 @@ impl TypedSyntaxNode for Arg { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::Arg { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -938,6 +1034,21 @@ impl TypedSyntaxNode for ArgClause { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "ArgClause"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ArgClauseUnnamed => { + Some(ArgClause::Unnamed(ArgClauseUnnamed::from_syntax_node(db, node))) + } + SyntaxKind::ArgClauseNamed => { + Some(ArgClause::Named(ArgClauseNamed::from_syntax_node(db, node))) + } + SyntaxKind::ArgClauseFieldInitShorthand => Some(ArgClause::FieldInitShorthand( + ArgClauseFieldInitShorthand::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { ArgClause::Unnamed(x) => x.as_syntax_node(), @@ -1053,6 +1164,14 @@ impl TypedSyntaxNode for ArgClauseNamed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgClauseNamed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1136,6 +1255,14 @@ impl TypedSyntaxNode for ArgClauseUnnamed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgClauseUnnamed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1230,6 +1357,14 @@ impl TypedSyntaxNode for ArgClauseFieldInitShorthand { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgClauseFieldInitShorthand { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1316,6 +1451,14 @@ impl TypedSyntaxNode for ExprFieldInitShorthand { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprFieldInitShorthand { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1411,6 +1554,9 @@ impl TypedSyntaxNode for ArgList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ArgList { Some(Self(ElementList::new(node))) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1486,6 +1632,10 @@ impl TypedSyntaxNode for ExprMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprMissing { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1560,6 +1710,18 @@ impl TypedSyntaxNode for PathSegment { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "PathSegment"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::PathSegmentWithGenericArgs => Some(PathSegment::WithGenericArgs( + PathSegmentWithGenericArgs::from_syntax_node(db, node), + )), + SyntaxKind::PathSegmentSimple => { + Some(PathSegment::Simple(PathSegmentSimple::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { PathSegment::WithGenericArgs(x) => x.as_syntax_node(), @@ -1655,6 +1817,14 @@ impl TypedSyntaxNode for PathSegmentSimple { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PathSegmentSimple { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1732,6 +1902,18 @@ impl TypedSyntaxNode for OptionTerminalColonColon { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionTerminalColonColonEmpty => Some(OptionTerminalColonColon::Empty( + OptionTerminalColonColonEmpty::from_syntax_node(db, node), + )), + SyntaxKind::TerminalColonColon => Some(OptionTerminalColonColon::TerminalColonColon( + TerminalColonColon::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionTerminalColonColon::Empty(x) => x.as_syntax_node(), @@ -1816,6 +1998,14 @@ impl TypedSyntaxNode for OptionTerminalColonColonEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionTerminalColonColonEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -1916,6 +2106,14 @@ impl TypedSyntaxNode for PathSegmentWithGenericArgs { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PathSegmentWithGenericArgs { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -2011,6 +2209,13 @@ impl TypedSyntaxNode for ExprPath { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ExprPath { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -2111,6 +2316,14 @@ impl TypedSyntaxNode for ExprParenthesized { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprParenthesized { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -2202,6 +2415,10 @@ impl TypedSyntaxNode for ExprUnary { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprUnary { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -2314,6 +2531,27 @@ impl TypedSyntaxNode for UnaryOperator { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "UnaryOperator"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalNot => { + Some(UnaryOperator::Not(TerminalNot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalBitNot => { + Some(UnaryOperator::BitNot(TerminalBitNot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMinus => { + Some(UnaryOperator::Minus(TerminalMinus::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAt => { + Some(UnaryOperator::At(TerminalAt::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMul => { + Some(UnaryOperator::Desnap(TerminalMul::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { UnaryOperator::Not(x) => x.as_syntax_node(), @@ -2433,6 +2671,10 @@ impl TypedSyntaxNode for ExprBinary { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprBinary { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -2803,6 +3045,87 @@ impl TypedSyntaxNode for BinaryOperator { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalDot => { + Some(BinaryOperator::Dot(TerminalDot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalNot => { + Some(BinaryOperator::Not(TerminalNot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMul => { + Some(BinaryOperator::Mul(TerminalMul::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMulEq => { + Some(BinaryOperator::MulEq(TerminalMulEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDiv => { + Some(BinaryOperator::Div(TerminalDiv::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDivEq => { + Some(BinaryOperator::DivEq(TerminalDivEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMod => { + Some(BinaryOperator::Mod(TerminalMod::from_syntax_node(db, node))) + } + SyntaxKind::TerminalModEq => { + Some(BinaryOperator::ModEq(TerminalModEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalPlus => { + Some(BinaryOperator::Plus(TerminalPlus::from_syntax_node(db, node))) + } + SyntaxKind::TerminalPlusEq => { + Some(BinaryOperator::PlusEq(TerminalPlusEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMinus => { + Some(BinaryOperator::Minus(TerminalMinus::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMinusEq => { + Some(BinaryOperator::MinusEq(TerminalMinusEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEqEq => { + Some(BinaryOperator::EqEq(TerminalEqEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalNeq => { + Some(BinaryOperator::Neq(TerminalNeq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEq => { + Some(BinaryOperator::Eq(TerminalEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAnd => { + Some(BinaryOperator::And(TerminalAnd::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAndAnd => { + Some(BinaryOperator::AndAnd(TerminalAndAnd::from_syntax_node(db, node))) + } + SyntaxKind::TerminalOr => { + Some(BinaryOperator::Or(TerminalOr::from_syntax_node(db, node))) + } + SyntaxKind::TerminalOrOr => { + Some(BinaryOperator::OrOr(TerminalOrOr::from_syntax_node(db, node))) + } + SyntaxKind::TerminalXor => { + Some(BinaryOperator::Xor(TerminalXor::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLE => { + Some(BinaryOperator::LE(TerminalLE::from_syntax_node(db, node))) + } + SyntaxKind::TerminalGE => { + Some(BinaryOperator::GE(TerminalGE::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLT => { + Some(BinaryOperator::LT(TerminalLT::from_syntax_node(db, node))) + } + SyntaxKind::TerminalGT => { + Some(BinaryOperator::GT(TerminalGT::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDotDot => { + Some(BinaryOperator::DotDot(TerminalDotDot::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { BinaryOperator::Dot(x) => x.as_syntax_node(), @@ -2962,6 +3285,14 @@ impl TypedSyntaxNode for ExprListParenthesized { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprListParenthesized { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3053,6 +3384,14 @@ impl TypedSyntaxNode for ExprFunctionCall { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprFunctionCall { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3153,6 +3492,14 @@ impl TypedSyntaxNode for ArgListParenthesized { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgListParenthesized { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3230,6 +3577,20 @@ impl TypedSyntaxNode for OptionArgListParenthesized { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionArgListParenthesizedEmpty => Some(OptionArgListParenthesized::Empty( + OptionArgListParenthesizedEmpty::from_syntax_node(db, node), + )), + SyntaxKind::ArgListParenthesized => { + Some(OptionArgListParenthesized::ArgListParenthesized( + ArgListParenthesized::from_syntax_node(db, node), + )) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionArgListParenthesized::Empty(x) => x.as_syntax_node(), @@ -3317,6 +3678,14 @@ impl TypedSyntaxNode for OptionArgListParenthesizedEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionArgListParenthesizedEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3408,6 +3777,14 @@ impl TypedSyntaxNode for ExprStructCtorCall { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprStructCtorCall { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3508,6 +3885,14 @@ impl TypedSyntaxNode for StructArgListBraced { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StructArgListBraced { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3608,6 +3993,10 @@ impl TypedSyntaxNode for ExprBlock { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprBlock { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3720,6 +4109,10 @@ impl TypedSyntaxNode for ExprMatch { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprMatch { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3815,6 +4208,13 @@ impl TypedSyntaxNode for MatchArms { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::MatchArms { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -3915,6 +4315,10 @@ impl TypedSyntaxNode for MatchArm { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::MatchArm { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4021,6 +4425,10 @@ impl TypedSyntaxNode for ExprIf { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprIf { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4091,6 +4499,18 @@ impl TypedSyntaxNode for Condition { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Condition"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ConditionLet => { + Some(Condition::Let(ConditionLet::from_syntax_node(db, node))) + } + SyntaxKind::ConditionExpr => { + Some(Condition::Expr(ConditionExpr::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Condition::Let(x) => x.as_syntax_node(), @@ -4206,6 +4626,10 @@ impl TypedSyntaxNode for ConditionLet { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ConditionLet { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4289,6 +4713,14 @@ impl TypedSyntaxNode for ConditionExpr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ConditionExpr { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4359,6 +4791,14 @@ impl TypedSyntaxNode for BlockOrIf { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "BlockOrIf"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ExprBlock => Some(BlockOrIf::Block(ExprBlock::from_syntax_node(db, node))), + SyntaxKind::ExprIf => Some(BlockOrIf::If(ExprIf::from_syntax_node(db, node))), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { BlockOrIf::Block(x) => x.as_syntax_node(), @@ -4459,6 +4899,10 @@ impl TypedSyntaxNode for ExprLoop { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprLoop { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4559,6 +5003,10 @@ impl TypedSyntaxNode for ExprWhile { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprWhile { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4688,6 +5136,10 @@ impl TypedSyntaxNode for ExprFor { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprFor { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4779,6 +5231,10 @@ impl TypedSyntaxNode for ElseClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ElseClause { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -4856,6 +5312,18 @@ impl TypedSyntaxNode for OptionElseClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionElseClauseEmpty => { + Some(OptionElseClause::Empty(OptionElseClauseEmpty::from_syntax_node(db, node))) + } + SyntaxKind::ElseClause => { + Some(OptionElseClause::ElseClause(ElseClause::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionElseClause::Empty(x) => x.as_syntax_node(), @@ -4940,6 +5408,14 @@ impl TypedSyntaxNode for OptionElseClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionElseClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5031,6 +5507,14 @@ impl TypedSyntaxNode for ExprErrorPropagate { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprErrorPropagate { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5137,6 +5621,10 @@ impl TypedSyntaxNode for ExprIndexed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprIndexed { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5237,6 +5725,14 @@ impl TypedSyntaxNode for ExprInlineMacro { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprInlineMacro { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5343,6 +5839,14 @@ impl TypedSyntaxNode for ExprFixedSizeArray { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprFixedSizeArray { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5434,6 +5938,14 @@ impl TypedSyntaxNode for FixedSizeArraySize { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::FixedSizeArraySize { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5511,6 +6023,18 @@ impl TypedSyntaxNode for OptionFixedSizeArraySize { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionFixedSizeArraySizeEmpty => Some(OptionFixedSizeArraySize::Empty( + OptionFixedSizeArraySizeEmpty::from_syntax_node(db, node), + )), + SyntaxKind::FixedSizeArraySize => Some(OptionFixedSizeArraySize::FixedSizeArraySize( + FixedSizeArraySize::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionFixedSizeArraySize::Empty(x) => x.as_syntax_node(), @@ -5595,6 +6119,14 @@ impl TypedSyntaxNode for OptionFixedSizeArraySizeEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionFixedSizeArraySizeEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5701,6 +6233,10 @@ impl TypedSyntaxNode for ExprClosure { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprClosure { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5778,6 +6314,18 @@ impl TypedSyntaxNode for ClosureParamWrapper { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalOrOr => { + Some(ClosureParamWrapper::Nullary(TerminalOrOr::from_syntax_node(db, node))) + } + SyntaxKind::ClosureParamWrapperNAry => { + Some(ClosureParamWrapper::NAry(ClosureParamWrapperNAry::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { ClosureParamWrapper::Nullary(x) => x.as_syntax_node(), @@ -5887,6 +6435,14 @@ impl TypedSyntaxNode for ClosureParamWrapperNAry { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ClosureParamWrapperNAry { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -5978,6 +6534,14 @@ impl TypedSyntaxNode for StructArgExpr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StructArgExpr { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6055,6 +6619,18 @@ impl TypedSyntaxNode for OptionStructArgExpr { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionStructArgExprEmpty => Some(OptionStructArgExpr::Empty( + OptionStructArgExprEmpty::from_syntax_node(db, node), + )), + SyntaxKind::StructArgExpr => { + Some(OptionStructArgExpr::StructArgExpr(StructArgExpr::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionStructArgExpr::Empty(x) => x.as_syntax_node(), @@ -6139,6 +6715,14 @@ impl TypedSyntaxNode for OptionStructArgExprEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionStructArgExprEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6242,6 +6826,14 @@ impl TypedSyntaxNode for StructArgSingle { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StructArgSingle { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6333,6 +6925,14 @@ impl TypedSyntaxNode for StructArgTail { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StructArgTail { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6407,6 +7007,18 @@ impl TypedSyntaxNode for StructArg { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "StructArg"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::StructArgSingle => { + Some(StructArg::StructArgSingle(StructArgSingle::from_syntax_node(db, node))) + } + SyntaxKind::StructArgTail => { + Some(StructArg::StructArgTail(StructArgTail::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { StructArg::StructArgSingle(x) => x.as_syntax_node(), @@ -6511,6 +7123,13 @@ impl TypedSyntaxNode for StructArgList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::StructArgList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6611,6 +7230,14 @@ impl TypedSyntaxNode for ArgListBraced { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgListBraced { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6711,6 +7338,14 @@ impl TypedSyntaxNode for ArgListBracketed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ArgListBracketed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -6815,6 +7450,24 @@ impl TypedSyntaxNode for WrappedArgList { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ArgListBracketed => { + Some(WrappedArgList::BracketedArgList(ArgListBracketed::from_syntax_node(db, node))) + } + SyntaxKind::ArgListParenthesized => Some(WrappedArgList::ParenthesizedArgList( + ArgListParenthesized::from_syntax_node(db, node), + )), + SyntaxKind::ArgListBraced => { + Some(WrappedArgList::BracedArgList(ArgListBraced::from_syntax_node(db, node))) + } + SyntaxKind::WrappedArgListMissing => { + Some(WrappedArgList::Missing(WrappedArgListMissing::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { WrappedArgList::BracketedArgList(x) => x.as_syntax_node(), @@ -6907,6 +7560,14 @@ impl TypedSyntaxNode for WrappedArgListMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::WrappedArgListMissing { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7109,6 +7770,44 @@ impl TypedSyntaxNode for Pattern { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Pattern"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalUnderscore => { + Some(Pattern::Underscore(TerminalUnderscore::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLiteralNumber => { + Some(Pattern::Literal(TerminalLiteralNumber::from_syntax_node(db, node))) + } + SyntaxKind::TerminalFalse => { + Some(Pattern::False(TerminalFalse::from_syntax_node(db, node))) + } + SyntaxKind::TerminalTrue => { + Some(Pattern::True(TerminalTrue::from_syntax_node(db, node))) + } + SyntaxKind::TerminalShortString => { + Some(Pattern::ShortString(TerminalShortString::from_syntax_node(db, node))) + } + SyntaxKind::TerminalString => { + Some(Pattern::String(TerminalString::from_syntax_node(db, node))) + } + SyntaxKind::PatternIdentifier => { + Some(Pattern::Identifier(PatternIdentifier::from_syntax_node(db, node))) + } + SyntaxKind::PatternStruct => { + Some(Pattern::Struct(PatternStruct::from_syntax_node(db, node))) + } + SyntaxKind::PatternTuple => { + Some(Pattern::Tuple(PatternTuple::from_syntax_node(db, node))) + } + SyntaxKind::PatternEnum => Some(Pattern::Enum(PatternEnum::from_syntax_node(db, node))), + SyntaxKind::PatternFixedSizeArray => { + Some(Pattern::FixedSizeArray(PatternFixedSizeArray::from_syntax_node(db, node))) + } + SyntaxKind::ExprPath => Some(Pattern::Path(ExprPath::from_syntax_node(db, node))), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Pattern::Underscore(x) => x.as_syntax_node(), @@ -7242,6 +7941,14 @@ impl TypedSyntaxNode for PatternIdentifier { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternIdentifier { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7348,6 +8055,14 @@ impl TypedSyntaxNode for PatternStruct { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternStruct { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7443,6 +8158,13 @@ impl TypedSyntaxNode for PatternStructParamList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::PatternStructParamList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7543,6 +8265,10 @@ impl TypedSyntaxNode for PatternTuple { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternTuple { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7643,6 +8369,14 @@ impl TypedSyntaxNode for PatternFixedSizeArray { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternFixedSizeArray { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7738,6 +8472,13 @@ impl TypedSyntaxNode for PatternList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::PatternList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7833,6 +8574,13 @@ impl TypedSyntaxNode for PatternListOr { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::PatternListOr { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -7924,6 +8672,21 @@ impl TypedSyntaxNode for PatternStructParam { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::PatternIdentifier => { + Some(PatternStructParam::Single(PatternIdentifier::from_syntax_node(db, node))) + } + SyntaxKind::PatternStructParamWithExpr => Some(PatternStructParam::WithExpr( + PatternStructParamWithExpr::from_syntax_node(db, node), + )), + SyntaxKind::TerminalDotDot => { + Some(PatternStructParam::Tail(TerminalDotDot::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { PatternStructParam::Single(x) => x.as_syntax_node(), @@ -8045,6 +8808,14 @@ impl TypedSyntaxNode for PatternStructParamWithExpr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternStructParamWithExpr { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8139,6 +8910,10 @@ impl TypedSyntaxNode for PatternEnum { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternEnum { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8239,6 +9014,14 @@ impl TypedSyntaxNode for PatternEnumInnerPattern { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::PatternEnumInnerPattern { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8318,6 +9101,22 @@ impl TypedSyntaxNode for OptionPatternEnumInnerPattern { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionPatternEnumInnerPatternEmpty => { + Some(OptionPatternEnumInnerPattern::Empty( + OptionPatternEnumInnerPatternEmpty::from_syntax_node(db, node), + )) + } + SyntaxKind::PatternEnumInnerPattern => { + Some(OptionPatternEnumInnerPattern::PatternEnumInnerPattern( + PatternEnumInnerPattern::from_syntax_node(db, node), + )) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionPatternEnumInnerPattern::Empty(x) => x.as_syntax_node(), @@ -8405,6 +9204,14 @@ impl TypedSyntaxNode for OptionPatternEnumInnerPatternEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionPatternEnumInnerPatternEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8496,6 +9303,10 @@ impl TypedSyntaxNode for TypeClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TypeClause { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8573,6 +9384,18 @@ impl TypedSyntaxNode for OptionTypeClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionTypeClauseEmpty => { + Some(OptionTypeClause::Empty(OptionTypeClauseEmpty::from_syntax_node(db, node))) + } + SyntaxKind::TypeClause => { + Some(OptionTypeClause::TypeClause(TypeClause::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionTypeClause::Empty(x) => x.as_syntax_node(), @@ -8657,6 +9480,14 @@ impl TypedSyntaxNode for OptionTypeClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionTypeClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8748,6 +9579,14 @@ impl TypedSyntaxNode for ReturnTypeClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ReturnTypeClause { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -8825,6 +9664,18 @@ impl TypedSyntaxNode for OptionReturnTypeClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionReturnTypeClauseEmpty => Some(OptionReturnTypeClause::Empty( + OptionReturnTypeClauseEmpty::from_syntax_node(db, node), + )), + SyntaxKind::ReturnTypeClause => Some(OptionReturnTypeClause::ReturnTypeClause( + ReturnTypeClause::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionReturnTypeClause::Empty(x) => x.as_syntax_node(), @@ -8909,6 +9760,14 @@ impl TypedSyntaxNode for OptionReturnTypeClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionReturnTypeClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9047,6 +9906,33 @@ impl TypedSyntaxNode for Statement { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Statement"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::StatementLet => { + Some(Statement::Let(StatementLet::from_syntax_node(db, node))) + } + SyntaxKind::StatementExpr => { + Some(Statement::Expr(StatementExpr::from_syntax_node(db, node))) + } + SyntaxKind::StatementContinue => { + Some(Statement::Continue(StatementContinue::from_syntax_node(db, node))) + } + SyntaxKind::StatementReturn => { + Some(Statement::Return(StatementReturn::from_syntax_node(db, node))) + } + SyntaxKind::StatementBreak => { + Some(Statement::Break(StatementBreak::from_syntax_node(db, node))) + } + SyntaxKind::StatementItem => { + Some(Statement::Item(StatementItem::from_syntax_node(db, node))) + } + SyntaxKind::StatementMissing => { + Some(Statement::Missing(StatementMissing::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Statement::Let(x) => x.as_syntax_node(), @@ -9139,6 +10025,13 @@ impl TypedSyntaxNode for StatementList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::StatementList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9214,6 +10107,14 @@ impl TypedSyntaxNode for StatementMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementMissing { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9348,6 +10249,10 @@ impl TypedSyntaxNode for StatementLet { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementLet { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9425,6 +10330,18 @@ impl TypedSyntaxNode for OptionTerminalSemicolon { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionTerminalSemicolonEmpty => Some(OptionTerminalSemicolon::Empty( + OptionTerminalSemicolonEmpty::from_syntax_node(db, node), + )), + SyntaxKind::TerminalSemicolon => Some(OptionTerminalSemicolon::TerminalSemicolon( + TerminalSemicolon::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionTerminalSemicolon::Empty(x) => x.as_syntax_node(), @@ -9509,6 +10426,14 @@ impl TypedSyntaxNode for OptionTerminalSemicolonEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionTerminalSemicolonEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9609,6 +10534,14 @@ impl TypedSyntaxNode for StatementExpr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementExpr { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9709,6 +10642,14 @@ impl TypedSyntaxNode for StatementContinue { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementContinue { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9792,6 +10733,10 @@ impl TypedSyntaxNode for ExprClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ExprClause { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -9869,6 +10814,18 @@ impl TypedSyntaxNode for OptionExprClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionExprClauseEmpty => { + Some(OptionExprClause::Empty(OptionExprClauseEmpty::from_syntax_node(db, node))) + } + SyntaxKind::ExprClause => { + Some(OptionExprClause::ExprClause(ExprClause::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionExprClause::Empty(x) => x.as_syntax_node(), @@ -9953,6 +10910,14 @@ impl TypedSyntaxNode for OptionExprClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionExprClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10059,6 +11024,14 @@ impl TypedSyntaxNode for StatementReturn { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementReturn { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10165,6 +11138,14 @@ impl TypedSyntaxNode for StatementBreak { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementBreak { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10248,6 +11229,14 @@ impl TypedSyntaxNode for StatementItem { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::StatementItem { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10357,6 +11346,10 @@ impl TypedSyntaxNode for Param { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::Param { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10426,6 +11419,13 @@ impl TypedSyntaxNode for ModifierList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ModifierList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10496,6 +11496,14 @@ impl TypedSyntaxNode for Modifier { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Modifier"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalRef => Some(Modifier::Ref(TerminalRef::from_syntax_node(db, node))), + SyntaxKind::TerminalMut => Some(Modifier::Mut(TerminalMut::from_syntax_node(db, node))), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Modifier::Ref(x) => x.as_syntax_node(), @@ -10600,6 +11608,13 @@ impl TypedSyntaxNode for ParamList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ParamList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10706,6 +11721,14 @@ impl TypedSyntaxNode for ImplicitsClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ImplicitsClause { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10801,6 +11824,13 @@ impl TypedSyntaxNode for ImplicitsList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ImplicitsList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -10878,6 +11908,18 @@ impl TypedSyntaxNode for OptionImplicitsClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionImplicitsClauseEmpty => Some(OptionImplicitsClause::Empty( + OptionImplicitsClauseEmpty::from_syntax_node(db, node), + )), + SyntaxKind::ImplicitsClause => Some(OptionImplicitsClause::ImplicitsClause( + ImplicitsClause::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionImplicitsClause::Empty(x) => x.as_syntax_node(), @@ -10962,6 +12004,14 @@ impl TypedSyntaxNode for OptionImplicitsClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionImplicitsClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11039,6 +12089,18 @@ impl TypedSyntaxNode for OptionTerminalNoPanic { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionTerminalNoPanicEmpty => Some(OptionTerminalNoPanic::Empty( + OptionTerminalNoPanicEmpty::from_syntax_node(db, node), + )), + SyntaxKind::TerminalNoPanic => Some(OptionTerminalNoPanic::TerminalNoPanic( + TerminalNoPanic::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionTerminalNoPanic::Empty(x) => x.as_syntax_node(), @@ -11123,6 +12185,14 @@ impl TypedSyntaxNode for OptionTerminalNoPanicEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionTerminalNoPanicEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11200,6 +12270,18 @@ impl TypedSyntaxNode for OptionTerminalConst { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionTerminalConstEmpty => Some(OptionTerminalConst::Empty( + OptionTerminalConstEmpty::from_syntax_node(db, node), + )), + SyntaxKind::TerminalConst => { + Some(OptionTerminalConst::TerminalConst(TerminalConst::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionTerminalConst::Empty(x) => x.as_syntax_node(), @@ -11284,6 +12366,14 @@ impl TypedSyntaxNode for OptionTerminalConstEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionTerminalConstEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11409,6 +12499,14 @@ impl TypedSyntaxNode for FunctionSignature { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::FunctionSignature { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11524,6 +12622,10 @@ impl TypedSyntaxNode for Member { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::Member { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11619,6 +12721,13 @@ impl TypedSyntaxNode for MemberList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::MemberList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11728,6 +12837,10 @@ impl TypedSyntaxNode for Variant { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::Variant { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -11823,6 +12936,13 @@ impl TypedSyntaxNode for VariantList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::VariantList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12067,6 +13187,49 @@ impl TypedSyntaxNode for ModuleItem { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "ModuleItem"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ItemConstant => { + Some(ModuleItem::Constant(ItemConstant::from_syntax_node(db, node))) + } + SyntaxKind::ItemModule => { + Some(ModuleItem::Module(ItemModule::from_syntax_node(db, node))) + } + SyntaxKind::ItemUse => Some(ModuleItem::Use(ItemUse::from_syntax_node(db, node))), + SyntaxKind::FunctionWithBody => { + Some(ModuleItem::FreeFunction(FunctionWithBody::from_syntax_node(db, node))) + } + SyntaxKind::ItemExternFunction => { + Some(ModuleItem::ExternFunction(ItemExternFunction::from_syntax_node(db, node))) + } + SyntaxKind::ItemExternType => { + Some(ModuleItem::ExternType(ItemExternType::from_syntax_node(db, node))) + } + SyntaxKind::ItemTrait => Some(ModuleItem::Trait(ItemTrait::from_syntax_node(db, node))), + SyntaxKind::ItemImpl => Some(ModuleItem::Impl(ItemImpl::from_syntax_node(db, node))), + SyntaxKind::ItemImplAlias => { + Some(ModuleItem::ImplAlias(ItemImplAlias::from_syntax_node(db, node))) + } + SyntaxKind::ItemStruct => { + Some(ModuleItem::Struct(ItemStruct::from_syntax_node(db, node))) + } + SyntaxKind::ItemEnum => Some(ModuleItem::Enum(ItemEnum::from_syntax_node(db, node))), + SyntaxKind::ItemTypeAlias => { + Some(ModuleItem::TypeAlias(ItemTypeAlias::from_syntax_node(db, node))) + } + SyntaxKind::ItemInlineMacro => { + Some(ModuleItem::InlineMacro(ItemInlineMacro::from_syntax_node(db, node))) + } + SyntaxKind::ItemHeaderDoc => { + Some(ModuleItem::HeaderDoc(ItemHeaderDoc::from_syntax_node(db, node))) + } + SyntaxKind::ModuleItemMissing => { + Some(ModuleItem::Missing(ModuleItemMissing::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { ModuleItem::Constant(x) => x.as_syntax_node(), @@ -12175,6 +13338,13 @@ impl TypedSyntaxNode for ModuleItemList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ModuleItemList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12250,6 +13420,14 @@ impl TypedSyntaxNode for ModuleItemMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ModuleItemMissing { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12362,6 +13540,10 @@ impl TypedSyntaxNode for Attribute { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::Attribute { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12431,6 +13613,13 @@ impl TypedSyntaxNode for AttributeList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::AttributeList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12506,6 +13695,14 @@ impl TypedSyntaxNode for VisibilityDefault { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::VisibilityDefault { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12606,6 +13803,14 @@ impl TypedSyntaxNode for VisibilityPubArgumentClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::VisibilityPubArgumentClause { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12687,6 +13892,22 @@ impl TypedSyntaxNode for OptionVisibilityPubArgumentClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionVisibilityPubArgumentClauseEmpty => { + Some(OptionVisibilityPubArgumentClause::Empty( + OptionVisibilityPubArgumentClauseEmpty::from_syntax_node(db, node), + )) + } + SyntaxKind::VisibilityPubArgumentClause => { + Some(OptionVisibilityPubArgumentClause::VisibilityPubArgumentClause( + VisibilityPubArgumentClause::from_syntax_node(db, node), + )) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionVisibilityPubArgumentClause::Empty(x) => x.as_syntax_node(), @@ -12776,6 +13997,14 @@ impl TypedSyntaxNode for OptionVisibilityPubArgumentClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionVisibilityPubArgumentClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12870,6 +14099,14 @@ impl TypedSyntaxNode for VisibilityPub { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::VisibilityPub { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -12942,6 +14179,18 @@ impl TypedSyntaxNode for Visibility { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Visibility"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::VisibilityDefault => { + Some(Visibility::Default(VisibilityDefault::from_syntax_node(db, node))) + } + SyntaxKind::VisibilityPub => { + Some(Visibility::Pub(VisibilityPub::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { Visibility::Default(x) => x.as_syntax_node(), @@ -13072,6 +14321,10 @@ impl TypedSyntaxNode for ItemModule { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemModule { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13146,6 +14399,18 @@ impl TypedSyntaxNode for MaybeModuleBody { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ModuleBody => { + Some(MaybeModuleBody::Some(ModuleBody::from_syntax_node(db, node))) + } + SyntaxKind::TerminalSemicolon => { + Some(MaybeModuleBody::None(TerminalSemicolon::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { MaybeModuleBody::Some(x) => x.as_syntax_node(), @@ -13255,6 +14520,10 @@ impl TypedSyntaxNode for ModuleBody { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ModuleBody { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13377,6 +14646,14 @@ impl TypedSyntaxNode for FunctionDeclaration { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::FunctionDeclaration { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13525,6 +14802,10 @@ impl TypedSyntaxNode for ItemConstant { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemConstant { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13640,6 +14921,14 @@ impl TypedSyntaxNode for FunctionWithBody { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::FunctionWithBody { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13762,6 +15051,14 @@ impl TypedSyntaxNode for ItemExternFunction { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemExternFunction { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -13903,6 +15200,14 @@ impl TypedSyntaxNode for ItemExternType { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemExternType { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14031,6 +15336,10 @@ impl TypedSyntaxNode for ItemTrait { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemTrait { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14105,6 +15414,18 @@ impl TypedSyntaxNode for MaybeTraitBody { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TraitBody => { + Some(MaybeTraitBody::Some(TraitBody::from_syntax_node(db, node))) + } + SyntaxKind::TerminalSemicolon => { + Some(MaybeTraitBody::None(TerminalSemicolon::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { MaybeTraitBody::Some(x) => x.as_syntax_node(), @@ -14214,6 +15535,10 @@ impl TypedSyntaxNode for TraitBody { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitBody { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14283,6 +15608,13 @@ impl TypedSyntaxNode for TraitItemList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::TraitItemList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14395,6 +15727,27 @@ impl TypedSyntaxNode for TraitItem { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "TraitItem"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TraitItemFunction => { + Some(TraitItem::Function(TraitItemFunction::from_syntax_node(db, node))) + } + SyntaxKind::TraitItemType => { + Some(TraitItem::Type(TraitItemType::from_syntax_node(db, node))) + } + SyntaxKind::TraitItemConstant => { + Some(TraitItem::Constant(TraitItemConstant::from_syntax_node(db, node))) + } + SyntaxKind::TraitItemImpl => { + Some(TraitItem::Impl(TraitItemImpl::from_syntax_node(db, node))) + } + SyntaxKind::TraitItemMissing => { + Some(TraitItem::Missing(TraitItemMissing::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { TraitItem::Function(x) => x.as_syntax_node(), @@ -14489,6 +15842,14 @@ impl TypedSyntaxNode for TraitItemMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitItemMissing { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14598,6 +15959,14 @@ impl TypedSyntaxNode for TraitItemFunction { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitItemFunction { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14720,6 +16089,14 @@ impl TypedSyntaxNode for TraitItemType { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitItemType { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14842,6 +16219,14 @@ impl TypedSyntaxNode for TraitItemConstant { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitItemConstant { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -14970,6 +16355,14 @@ impl TypedSyntaxNode for TraitItemImpl { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TraitItemImpl { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15047,6 +16440,18 @@ impl TypedSyntaxNode for MaybeTraitFunctionBody { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ExprBlock => { + Some(MaybeTraitFunctionBody::Some(ExprBlock::from_syntax_node(db, node))) + } + SyntaxKind::TerminalSemicolon => { + Some(MaybeTraitFunctionBody::None(TerminalSemicolon::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { MaybeTraitFunctionBody::Some(x) => x.as_syntax_node(), @@ -15204,6 +16609,10 @@ impl TypedSyntaxNode for ItemImpl { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemImpl { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15316,6 +16725,14 @@ impl TypedSyntaxNode for ItemInlineMacro { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemInlineMacro { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15399,6 +16816,14 @@ impl TypedSyntaxNode for ItemHeaderDoc { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemHeaderDoc { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15471,6 +16896,16 @@ impl TypedSyntaxNode for MaybeImplBody { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "MaybeImplBody"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::ImplBody => Some(MaybeImplBody::Some(ImplBody::from_syntax_node(db, node))), + SyntaxKind::TerminalSemicolon => { + Some(MaybeImplBody::None(TerminalSemicolon::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { MaybeImplBody::Some(x) => x.as_syntax_node(), @@ -15580,6 +17015,10 @@ impl TypedSyntaxNode for ImplBody { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ImplBody { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15649,6 +17088,13 @@ impl TypedSyntaxNode for ImplItemList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::ImplItemList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -15849,6 +17295,42 @@ impl TypedSyntaxNode for ImplItem { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "ImplItem"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::FunctionWithBody => { + Some(ImplItem::Function(FunctionWithBody::from_syntax_node(db, node))) + } + SyntaxKind::ItemTypeAlias => { + Some(ImplItem::Type(ItemTypeAlias::from_syntax_node(db, node))) + } + SyntaxKind::ItemConstant => { + Some(ImplItem::Constant(ItemConstant::from_syntax_node(db, node))) + } + SyntaxKind::ItemImplAlias => { + Some(ImplItem::Impl(ItemImplAlias::from_syntax_node(db, node))) + } + SyntaxKind::ItemModule => { + Some(ImplItem::Module(ItemModule::from_syntax_node(db, node))) + } + SyntaxKind::ItemUse => Some(ImplItem::Use(ItemUse::from_syntax_node(db, node))), + SyntaxKind::ItemExternFunction => { + Some(ImplItem::ExternFunction(ItemExternFunction::from_syntax_node(db, node))) + } + SyntaxKind::ItemExternType => { + Some(ImplItem::ExternType(ItemExternType::from_syntax_node(db, node))) + } + SyntaxKind::ItemTrait => Some(ImplItem::Trait(ItemTrait::from_syntax_node(db, node))), + SyntaxKind::ItemStruct => { + Some(ImplItem::Struct(ItemStruct::from_syntax_node(db, node))) + } + SyntaxKind::ItemEnum => Some(ImplItem::Enum(ItemEnum::from_syntax_node(db, node))), + SyntaxKind::ImplItemMissing => { + Some(ImplItem::Missing(ImplItemMissing::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { ImplItem::Function(x) => x.as_syntax_node(), @@ -15957,6 +17439,14 @@ impl TypedSyntaxNode for ImplItemMissing { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ImplItemMissing { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16105,6 +17595,14 @@ impl TypedSyntaxNode for ItemImplAlias { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemImplAlias { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16253,6 +17751,10 @@ impl TypedSyntaxNode for ItemStruct { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemStruct { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16401,6 +17903,10 @@ impl TypedSyntaxNode for ItemEnum { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemEnum { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16549,6 +18055,14 @@ impl TypedSyntaxNode for ItemTypeAlias { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemTypeAlias { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16671,6 +18185,10 @@ impl TypedSyntaxNode for ItemUse { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::ItemUse { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16765,6 +18283,20 @@ impl TypedSyntaxNode for UsePath { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "UsePath"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::UsePathLeaf => Some(UsePath::Leaf(UsePathLeaf::from_syntax_node(db, node))), + SyntaxKind::UsePathSingle => { + Some(UsePath::Single(UsePathSingle::from_syntax_node(db, node))) + } + SyntaxKind::UsePathMulti => { + Some(UsePath::Multi(UsePathMulti::from_syntax_node(db, node))) + } + SyntaxKind::UsePathStar => Some(UsePath::Star(UsePathStar::from_syntax_node(db, node))), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { UsePath::Leaf(x) => x.as_syntax_node(), @@ -16890,6 +18422,10 @@ impl TypedSyntaxNode for UsePathLeaf { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::UsePathLeaf { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -16990,6 +18526,14 @@ impl TypedSyntaxNode for UsePathSingle { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::UsePathSingle { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17090,6 +18634,10 @@ impl TypedSyntaxNode for UsePathMulti { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::UsePathMulti { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17173,6 +18721,10 @@ impl TypedSyntaxNode for UsePathStar { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::UsePathStar { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17268,6 +18820,13 @@ impl TypedSyntaxNode for UsePathList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::UsePathList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17368,6 +18927,10 @@ impl TypedSyntaxNode for AliasClause { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::AliasClause { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17445,6 +19008,18 @@ impl TypedSyntaxNode for OptionAliasClause { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionAliasClauseEmpty => { + Some(OptionAliasClause::Empty(OptionAliasClauseEmpty::from_syntax_node(db, node))) + } + SyntaxKind::AliasClause => { + Some(OptionAliasClause::AliasClause(AliasClause::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionAliasClause::Empty(x) => x.as_syntax_node(), @@ -17529,6 +19104,14 @@ impl TypedSyntaxNode for OptionAliasClauseEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionAliasClauseEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17603,6 +19186,18 @@ impl TypedSyntaxNode for GenericArg { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "GenericArg"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::GenericArgUnnamed => { + Some(GenericArg::Unnamed(GenericArgUnnamed::from_syntax_node(db, node))) + } + SyntaxKind::GenericArgNamed => { + Some(GenericArg::Named(GenericArgNamed::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { GenericArg::Unnamed(x) => x.as_syntax_node(), @@ -17712,6 +19307,14 @@ impl TypedSyntaxNode for GenericArgNamed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericArgNamed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17795,6 +19398,14 @@ impl TypedSyntaxNode for GenericArgUnnamed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericArgUnnamed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -17871,6 +19482,18 @@ impl TypedSyntaxNode for GenericArgValue { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::GenericArgValueExpr => { + Some(GenericArgValue::Expr(GenericArgValueExpr::from_syntax_node(db, node))) + } + SyntaxKind::TerminalUnderscore => { + Some(GenericArgValue::Underscore(TerminalUnderscore::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { GenericArgValue::Expr(x) => x.as_syntax_node(), @@ -17963,6 +19586,14 @@ impl TypedSyntaxNode for GenericArgValueExpr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericArgValueExpr { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18063,6 +19694,10 @@ impl TypedSyntaxNode for GenericArgs { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericArgs { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18158,6 +19793,13 @@ impl TypedSyntaxNode for GenericArgList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::GenericArgList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18258,6 +19900,14 @@ impl TypedSyntaxNode for AssociatedItemConstraint { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::AssociatedItemConstraint { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18361,6 +20011,14 @@ impl TypedSyntaxNode for AssociatedItemConstraints { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::AssociatedItemConstraints { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18456,6 +20114,13 @@ impl TypedSyntaxNode for AssociatedItemConstraintList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::AssociatedItemConstraintList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18537,6 +20202,22 @@ impl TypedSyntaxNode for OptionAssociatedItemConstraints { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionAssociatedItemConstraintsEmpty => { + Some(OptionAssociatedItemConstraints::Empty( + OptionAssociatedItemConstraintsEmpty::from_syntax_node(db, node), + )) + } + SyntaxKind::AssociatedItemConstraints => { + Some(OptionAssociatedItemConstraints::AssociatedItemConstraints( + AssociatedItemConstraints::from_syntax_node(db, node), + )) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionAssociatedItemConstraints::Empty(x) => x.as_syntax_node(), @@ -18626,6 +20307,14 @@ impl TypedSyntaxNode for OptionAssociatedItemConstraintsEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionAssociatedItemConstraintsEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18705,6 +20394,22 @@ impl TypedSyntaxNode for OptionWrappedGenericParamList { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::OptionWrappedGenericParamListEmpty => { + Some(OptionWrappedGenericParamList::Empty( + OptionWrappedGenericParamListEmpty::from_syntax_node(db, node), + )) + } + SyntaxKind::WrappedGenericParamList => { + Some(OptionWrappedGenericParamList::WrappedGenericParamList( + WrappedGenericParamList::from_syntax_node(db, node), + )) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { OptionWrappedGenericParamList::Empty(x) => x.as_syntax_node(), @@ -18792,6 +20497,14 @@ impl TypedSyntaxNode for OptionWrappedGenericParamListEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::OptionWrappedGenericParamListEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18892,6 +20605,14 @@ impl TypedSyntaxNode for WrappedGenericParamList { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::WrappedGenericParamList { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -18987,6 +20708,13 @@ impl TypedSyntaxNode for GenericParamList { fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { Self(ElementList::new(node)) } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == SyntaxKind::GenericParamList { + Some(Self(ElementList::new(node))) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19103,6 +20831,27 @@ impl TypedSyntaxNode for GenericParam { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "GenericParam"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::GenericParamType => { + Some(GenericParam::Type(GenericParamType::from_syntax_node(db, node))) + } + SyntaxKind::GenericParamConst => { + Some(GenericParam::Const(GenericParamConst::from_syntax_node(db, node))) + } + SyntaxKind::GenericParamImplNamed => { + Some(GenericParam::ImplNamed(GenericParamImplNamed::from_syntax_node(db, node))) + } + SyntaxKind::GenericParamImplAnonymous => Some(GenericParam::ImplAnonymous( + GenericParamImplAnonymous::from_syntax_node(db, node), + )), + SyntaxKind::GenericParamNegativeImpl => Some(GenericParam::NegativeImpl( + GenericParamNegativeImpl::from_syntax_node(db, node), + )), + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { GenericParam::Type(x) => x.as_syntax_node(), @@ -19214,6 +20963,14 @@ impl TypedSyntaxNode for GenericParamType { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericParamType { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19329,6 +21086,14 @@ impl TypedSyntaxNode for GenericParamConst { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericParamConst { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19451,6 +21216,14 @@ impl TypedSyntaxNode for GenericParamImplNamed { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericParamImplNamed { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19551,6 +21324,14 @@ impl TypedSyntaxNode for GenericParamImplAnonymous { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericParamImplAnonymous { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19642,6 +21423,14 @@ impl TypedSyntaxNode for GenericParamNegativeImpl { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::GenericParamNegativeImpl { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19725,6 +21514,14 @@ impl TypedSyntaxNode for TriviumSkippedNode { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TriviumSkippedNode { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19799,6 +21596,18 @@ impl TypedSyntaxNode for SkippedNode { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "SkippedNode"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::AttributeList => { + Some(SkippedNode::AttributeList(AttributeList::from_syntax_node(db, node))) + } + SyntaxKind::VisibilityPub => { + Some(SkippedNode::VisibilityPub(VisibilityPub::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { SkippedNode::AttributeList(x) => x.as_syntax_node(), @@ -19883,6 +21692,12 @@ impl TypedSyntaxNode for TokenIdentifier { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -19985,6 +21800,14 @@ impl TypedSyntaxNode for TerminalIdentifier { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalIdentifier { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20061,6 +21884,12 @@ impl TypedSyntaxNode for TokenLiteralNumber { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20163,6 +21992,14 @@ impl TypedSyntaxNode for TerminalLiteralNumber { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLiteralNumber { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20238,6 +22075,12 @@ impl TypedSyntaxNode for TokenShortString { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20340,6 +22183,14 @@ impl TypedSyntaxNode for TerminalShortString { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalShortString { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20415,6 +22266,12 @@ impl TypedSyntaxNode for TokenString { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20517,6 +22374,14 @@ impl TypedSyntaxNode for TerminalString { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalString { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20592,6 +22457,12 @@ impl TypedSyntaxNode for TokenAs { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20694,6 +22565,10 @@ impl TypedSyntaxNode for TerminalAs { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalAs { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20769,6 +22644,12 @@ impl TypedSyntaxNode for TokenConst { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20871,6 +22752,14 @@ impl TypedSyntaxNode for TerminalConst { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalConst { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -20946,6 +22835,12 @@ impl TypedSyntaxNode for TokenElse { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21048,6 +22943,10 @@ impl TypedSyntaxNode for TerminalElse { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalElse { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21123,6 +23022,12 @@ impl TypedSyntaxNode for TokenEnum { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21225,6 +23130,10 @@ impl TypedSyntaxNode for TerminalEnum { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalEnum { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21300,6 +23209,12 @@ impl TypedSyntaxNode for TokenExtern { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21402,6 +23317,14 @@ impl TypedSyntaxNode for TerminalExtern { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalExtern { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21477,6 +23400,12 @@ impl TypedSyntaxNode for TokenFalse { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21579,6 +23508,14 @@ impl TypedSyntaxNode for TerminalFalse { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalFalse { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21654,6 +23591,12 @@ impl TypedSyntaxNode for TokenFunction { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21756,6 +23699,14 @@ impl TypedSyntaxNode for TerminalFunction { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalFunction { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21831,6 +23782,12 @@ impl TypedSyntaxNode for TokenIf { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -21933,6 +23890,10 @@ impl TypedSyntaxNode for TerminalIf { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalIf { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22008,6 +23969,12 @@ impl TypedSyntaxNode for TokenWhile { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22110,6 +24077,14 @@ impl TypedSyntaxNode for TerminalWhile { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalWhile { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22185,6 +24160,12 @@ impl TypedSyntaxNode for TokenFor { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22287,6 +24268,10 @@ impl TypedSyntaxNode for TerminalFor { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalFor { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22362,6 +24347,12 @@ impl TypedSyntaxNode for TokenLoop { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22464,6 +24455,10 @@ impl TypedSyntaxNode for TerminalLoop { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLoop { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22539,6 +24534,12 @@ impl TypedSyntaxNode for TokenImpl { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22641,6 +24642,10 @@ impl TypedSyntaxNode for TerminalImpl { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalImpl { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22716,6 +24721,12 @@ impl TypedSyntaxNode for TokenImplicits { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22818,6 +24829,14 @@ impl TypedSyntaxNode for TerminalImplicits { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalImplicits { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22893,6 +24912,12 @@ impl TypedSyntaxNode for TokenLet { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -22995,6 +25020,10 @@ impl TypedSyntaxNode for TerminalLet { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLet { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23070,6 +25099,12 @@ impl TypedSyntaxNode for TokenMatch { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23172,6 +25207,14 @@ impl TypedSyntaxNode for TerminalMatch { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMatch { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23247,6 +25290,12 @@ impl TypedSyntaxNode for TokenModule { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23349,6 +25398,14 @@ impl TypedSyntaxNode for TerminalModule { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalModule { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23424,6 +25481,12 @@ impl TypedSyntaxNode for TokenMut { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23526,6 +25589,10 @@ impl TypedSyntaxNode for TerminalMut { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMut { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23601,6 +25668,12 @@ impl TypedSyntaxNode for TokenNoPanic { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23703,6 +25776,14 @@ impl TypedSyntaxNode for TerminalNoPanic { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalNoPanic { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23778,6 +25859,12 @@ impl TypedSyntaxNode for TokenOf { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23880,6 +25967,10 @@ impl TypedSyntaxNode for TerminalOf { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalOf { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -23955,6 +26046,12 @@ impl TypedSyntaxNode for TokenRef { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24057,6 +26154,10 @@ impl TypedSyntaxNode for TerminalRef { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalRef { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24132,6 +26233,12 @@ impl TypedSyntaxNode for TokenContinue { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24234,6 +26341,14 @@ impl TypedSyntaxNode for TerminalContinue { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalContinue { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24309,6 +26424,12 @@ impl TypedSyntaxNode for TokenReturn { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24411,6 +26532,14 @@ impl TypedSyntaxNode for TerminalReturn { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalReturn { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24486,6 +26615,12 @@ impl TypedSyntaxNode for TokenBreak { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24588,6 +26723,14 @@ impl TypedSyntaxNode for TerminalBreak { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalBreak { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24663,6 +26806,12 @@ impl TypedSyntaxNode for TokenStruct { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24765,6 +26914,14 @@ impl TypedSyntaxNode for TerminalStruct { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalStruct { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24840,6 +26997,12 @@ impl TypedSyntaxNode for TokenTrait { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -24942,6 +27105,14 @@ impl TypedSyntaxNode for TerminalTrait { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalTrait { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25017,6 +27188,12 @@ impl TypedSyntaxNode for TokenTrue { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25119,6 +27296,10 @@ impl TypedSyntaxNode for TerminalTrue { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalTrue { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25194,6 +27375,12 @@ impl TypedSyntaxNode for TokenType { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25296,6 +27483,10 @@ impl TypedSyntaxNode for TerminalType { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalType { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25371,6 +27562,12 @@ impl TypedSyntaxNode for TokenUse { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25473,6 +27670,10 @@ impl TypedSyntaxNode for TerminalUse { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalUse { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25548,6 +27749,12 @@ impl TypedSyntaxNode for TokenPub { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25650,6 +27857,10 @@ impl TypedSyntaxNode for TerminalPub { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalPub { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25725,6 +27936,12 @@ impl TypedSyntaxNode for TokenAnd { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25827,6 +28044,10 @@ impl TypedSyntaxNode for TerminalAnd { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalAnd { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -25902,6 +28123,12 @@ impl TypedSyntaxNode for TokenAndAnd { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26004,6 +28231,14 @@ impl TypedSyntaxNode for TerminalAndAnd { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalAndAnd { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26079,6 +28314,12 @@ impl TypedSyntaxNode for TokenArrow { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26181,6 +28422,14 @@ impl TypedSyntaxNode for TerminalArrow { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalArrow { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26256,6 +28505,12 @@ impl TypedSyntaxNode for TokenAt { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26358,6 +28613,10 @@ impl TypedSyntaxNode for TerminalAt { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalAt { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26434,6 +28693,12 @@ impl TypedSyntaxNode for TokenBadCharacters { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26536,6 +28801,14 @@ impl TypedSyntaxNode for TerminalBadCharacters { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalBadCharacters { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26611,6 +28884,12 @@ impl TypedSyntaxNode for TokenColon { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26713,6 +28992,14 @@ impl TypedSyntaxNode for TerminalColon { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalColon { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26788,6 +29075,12 @@ impl TypedSyntaxNode for TokenColonColon { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26890,6 +29183,14 @@ impl TypedSyntaxNode for TerminalColonColon { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalColonColon { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -26965,6 +29266,12 @@ impl TypedSyntaxNode for TokenComma { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27067,6 +29374,14 @@ impl TypedSyntaxNode for TerminalComma { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalComma { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27142,6 +29457,12 @@ impl TypedSyntaxNode for TokenDiv { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27244,6 +29565,10 @@ impl TypedSyntaxNode for TerminalDiv { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalDiv { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27319,6 +29644,12 @@ impl TypedSyntaxNode for TokenDivEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27421,6 +29752,14 @@ impl TypedSyntaxNode for TerminalDivEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalDivEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27496,6 +29835,12 @@ impl TypedSyntaxNode for TokenDot { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27598,6 +29943,10 @@ impl TypedSyntaxNode for TerminalDot { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalDot { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27673,6 +30022,12 @@ impl TypedSyntaxNode for TokenDotDot { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27775,6 +30130,14 @@ impl TypedSyntaxNode for TerminalDotDot { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalDotDot { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27850,6 +30213,12 @@ impl TypedSyntaxNode for TokenEndOfFile { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -27952,6 +30321,14 @@ impl TypedSyntaxNode for TerminalEndOfFile { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalEndOfFile { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28027,6 +30404,12 @@ impl TypedSyntaxNode for TokenEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28129,6 +30512,10 @@ impl TypedSyntaxNode for TerminalEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalEq { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28204,6 +30591,12 @@ impl TypedSyntaxNode for TokenEqEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28306,6 +30699,10 @@ impl TypedSyntaxNode for TerminalEqEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalEqEq { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28381,6 +30778,12 @@ impl TypedSyntaxNode for TokenGE { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28483,6 +30886,10 @@ impl TypedSyntaxNode for TerminalGE { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalGE { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28558,6 +30965,12 @@ impl TypedSyntaxNode for TokenGT { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28660,6 +31073,10 @@ impl TypedSyntaxNode for TerminalGT { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalGT { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28735,6 +31152,12 @@ impl TypedSyntaxNode for TokenHash { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28837,6 +31260,10 @@ impl TypedSyntaxNode for TerminalHash { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalHash { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -28912,6 +31339,12 @@ impl TypedSyntaxNode for TokenLBrace { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29014,6 +31447,14 @@ impl TypedSyntaxNode for TerminalLBrace { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLBrace { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29089,6 +31530,12 @@ impl TypedSyntaxNode for TokenLBrack { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29191,6 +31638,14 @@ impl TypedSyntaxNode for TerminalLBrack { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLBrack { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29266,6 +31721,12 @@ impl TypedSyntaxNode for TokenLE { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29368,6 +31829,10 @@ impl TypedSyntaxNode for TerminalLE { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLE { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29443,6 +31908,12 @@ impl TypedSyntaxNode for TokenLParen { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29545,6 +32016,14 @@ impl TypedSyntaxNode for TerminalLParen { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLParen { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29620,6 +32099,12 @@ impl TypedSyntaxNode for TokenLT { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29722,6 +32207,10 @@ impl TypedSyntaxNode for TerminalLT { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalLT { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29797,6 +32286,12 @@ impl TypedSyntaxNode for TokenMatchArrow { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29899,6 +32394,14 @@ impl TypedSyntaxNode for TerminalMatchArrow { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMatchArrow { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -29974,6 +32477,12 @@ impl TypedSyntaxNode for TokenMinus { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30076,6 +32585,14 @@ impl TypedSyntaxNode for TerminalMinus { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMinus { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30151,6 +32668,12 @@ impl TypedSyntaxNode for TokenMinusEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30253,6 +32776,14 @@ impl TypedSyntaxNode for TerminalMinusEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMinusEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30328,6 +32859,12 @@ impl TypedSyntaxNode for TokenMod { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30430,6 +32967,10 @@ impl TypedSyntaxNode for TerminalMod { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMod { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30505,6 +33046,12 @@ impl TypedSyntaxNode for TokenModEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30607,6 +33154,14 @@ impl TypedSyntaxNode for TerminalModEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalModEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30682,6 +33237,12 @@ impl TypedSyntaxNode for TokenMul { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30784,6 +33345,10 @@ impl TypedSyntaxNode for TerminalMul { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMul { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30859,6 +33424,12 @@ impl TypedSyntaxNode for TokenMulEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30961,6 +33532,14 @@ impl TypedSyntaxNode for TerminalMulEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalMulEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31036,6 +33615,12 @@ impl TypedSyntaxNode for TokenNeq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31138,6 +33723,10 @@ impl TypedSyntaxNode for TerminalNeq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalNeq { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31213,6 +33802,12 @@ impl TypedSyntaxNode for TokenNot { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31315,6 +33910,10 @@ impl TypedSyntaxNode for TerminalNot { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalNot { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31390,6 +33989,12 @@ impl TypedSyntaxNode for TokenBitNot { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31492,6 +34097,14 @@ impl TypedSyntaxNode for TerminalBitNot { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalBitNot { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31567,6 +34180,12 @@ impl TypedSyntaxNode for TokenOr { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31669,6 +34288,10 @@ impl TypedSyntaxNode for TerminalOr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalOr { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31744,6 +34367,12 @@ impl TypedSyntaxNode for TokenOrOr { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31846,6 +34475,10 @@ impl TypedSyntaxNode for TerminalOrOr { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalOrOr { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -31921,6 +34554,12 @@ impl TypedSyntaxNode for TokenPlus { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32023,6 +34662,10 @@ impl TypedSyntaxNode for TerminalPlus { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalPlus { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32098,6 +34741,12 @@ impl TypedSyntaxNode for TokenPlusEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32200,6 +34849,14 @@ impl TypedSyntaxNode for TerminalPlusEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalPlusEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32275,6 +34932,12 @@ impl TypedSyntaxNode for TokenQuestionMark { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32377,6 +35040,14 @@ impl TypedSyntaxNode for TerminalQuestionMark { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalQuestionMark { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32452,6 +35123,12 @@ impl TypedSyntaxNode for TokenRBrace { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32554,6 +35231,14 @@ impl TypedSyntaxNode for TerminalRBrace { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalRBrace { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32629,6 +35314,12 @@ impl TypedSyntaxNode for TokenRBrack { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32731,6 +35422,14 @@ impl TypedSyntaxNode for TerminalRBrack { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalRBrack { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32806,6 +35505,12 @@ impl TypedSyntaxNode for TokenRParen { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32908,6 +35613,14 @@ impl TypedSyntaxNode for TerminalRParen { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalRParen { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -32983,6 +35696,12 @@ impl TypedSyntaxNode for TokenSemicolon { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33085,6 +35804,14 @@ impl TypedSyntaxNode for TerminalSemicolon { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalSemicolon { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33160,6 +35887,12 @@ impl TypedSyntaxNode for TokenUnderscore { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33262,6 +35995,14 @@ impl TypedSyntaxNode for TerminalUnderscore { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalUnderscore { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33337,6 +36078,12 @@ impl TypedSyntaxNode for TokenXor { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33439,6 +36186,10 @@ impl TypedSyntaxNode for TerminalXor { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalXor { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33530,6 +36281,10 @@ impl TypedSyntaxNode for SyntaxFile { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::SyntaxFile { Some(Self::from_syntax_node(db, node)) } else { None } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33605,6 +36360,12 @@ impl TypedSyntaxNode for TokenEmpty { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33707,6 +36468,14 @@ impl TypedSyntaxNode for TerminalEmpty { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalEmpty { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33783,6 +36552,12 @@ impl TypedSyntaxNode for TokenSingleLineComment { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33859,6 +36634,12 @@ impl TypedSyntaxNode for TokenSingleLineInnerComment { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -33935,6 +36716,12 @@ impl TypedSyntaxNode for TokenSingleLineDocComment { ), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -34010,6 +36797,12 @@ impl TypedSyntaxNode for TokenWhitespace { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -34085,6 +36878,12 @@ impl TypedSyntaxNode for TokenNewline { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -34160,6 +36959,12 @@ impl TypedSyntaxNode for TokenMissing { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -34235,6 +37040,12 @@ impl TypedSyntaxNode for TokenSkipped { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -35353,6 +38164,246 @@ impl TypedSyntaxNode for TokenNode { _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "TokenNode"), } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + match kind { + SyntaxKind::TerminalIdentifier => { + Some(TokenNode::TerminalIdentifier(TerminalIdentifier::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLiteralNumber => Some(TokenNode::TerminalLiteralNumber( + TerminalLiteralNumber::from_syntax_node(db, node), + )), + SyntaxKind::TerminalShortString => Some(TokenNode::TerminalShortString( + TerminalShortString::from_syntax_node(db, node), + )), + SyntaxKind::TerminalString => { + Some(TokenNode::TerminalString(TerminalString::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAs => { + Some(TokenNode::TerminalAs(TerminalAs::from_syntax_node(db, node))) + } + SyntaxKind::TerminalConst => { + Some(TokenNode::TerminalConst(TerminalConst::from_syntax_node(db, node))) + } + SyntaxKind::TerminalElse => { + Some(TokenNode::TerminalElse(TerminalElse::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEnum => { + Some(TokenNode::TerminalEnum(TerminalEnum::from_syntax_node(db, node))) + } + SyntaxKind::TerminalExtern => { + Some(TokenNode::TerminalExtern(TerminalExtern::from_syntax_node(db, node))) + } + SyntaxKind::TerminalFalse => { + Some(TokenNode::TerminalFalse(TerminalFalse::from_syntax_node(db, node))) + } + SyntaxKind::TerminalFunction => { + Some(TokenNode::TerminalFunction(TerminalFunction::from_syntax_node(db, node))) + } + SyntaxKind::TerminalIf => { + Some(TokenNode::TerminalIf(TerminalIf::from_syntax_node(db, node))) + } + SyntaxKind::TerminalWhile => { + Some(TokenNode::TerminalWhile(TerminalWhile::from_syntax_node(db, node))) + } + SyntaxKind::TerminalFor => { + Some(TokenNode::TerminalFor(TerminalFor::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLoop => { + Some(TokenNode::TerminalLoop(TerminalLoop::from_syntax_node(db, node))) + } + SyntaxKind::TerminalImpl => { + Some(TokenNode::TerminalImpl(TerminalImpl::from_syntax_node(db, node))) + } + SyntaxKind::TerminalImplicits => { + Some(TokenNode::TerminalImplicits(TerminalImplicits::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLet => { + Some(TokenNode::TerminalLet(TerminalLet::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMatch => { + Some(TokenNode::TerminalMatch(TerminalMatch::from_syntax_node(db, node))) + } + SyntaxKind::TerminalModule => { + Some(TokenNode::TerminalModule(TerminalModule::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMut => { + Some(TokenNode::TerminalMut(TerminalMut::from_syntax_node(db, node))) + } + SyntaxKind::TerminalNoPanic => { + Some(TokenNode::TerminalNoPanic(TerminalNoPanic::from_syntax_node(db, node))) + } + SyntaxKind::TerminalOf => { + Some(TokenNode::TerminalOf(TerminalOf::from_syntax_node(db, node))) + } + SyntaxKind::TerminalRef => { + Some(TokenNode::TerminalRef(TerminalRef::from_syntax_node(db, node))) + } + SyntaxKind::TerminalContinue => { + Some(TokenNode::TerminalContinue(TerminalContinue::from_syntax_node(db, node))) + } + SyntaxKind::TerminalReturn => { + Some(TokenNode::TerminalReturn(TerminalReturn::from_syntax_node(db, node))) + } + SyntaxKind::TerminalBreak => { + Some(TokenNode::TerminalBreak(TerminalBreak::from_syntax_node(db, node))) + } + SyntaxKind::TerminalStruct => { + Some(TokenNode::TerminalStruct(TerminalStruct::from_syntax_node(db, node))) + } + SyntaxKind::TerminalTrait => { + Some(TokenNode::TerminalTrait(TerminalTrait::from_syntax_node(db, node))) + } + SyntaxKind::TerminalTrue => { + Some(TokenNode::TerminalTrue(TerminalTrue::from_syntax_node(db, node))) + } + SyntaxKind::TerminalType => { + Some(TokenNode::TerminalType(TerminalType::from_syntax_node(db, node))) + } + SyntaxKind::TerminalUse => { + Some(TokenNode::TerminalUse(TerminalUse::from_syntax_node(db, node))) + } + SyntaxKind::TerminalPub => { + Some(TokenNode::TerminalPub(TerminalPub::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAnd => { + Some(TokenNode::TerminalAnd(TerminalAnd::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAndAnd => { + Some(TokenNode::TerminalAndAnd(TerminalAndAnd::from_syntax_node(db, node))) + } + SyntaxKind::TerminalArrow => { + Some(TokenNode::TerminalArrow(TerminalArrow::from_syntax_node(db, node))) + } + SyntaxKind::TerminalAt => { + Some(TokenNode::TerminalAt(TerminalAt::from_syntax_node(db, node))) + } + SyntaxKind::TerminalBadCharacters => Some(TokenNode::TerminalBadCharacters( + TerminalBadCharacters::from_syntax_node(db, node), + )), + SyntaxKind::TerminalColon => { + Some(TokenNode::TerminalColon(TerminalColon::from_syntax_node(db, node))) + } + SyntaxKind::TerminalColonColon => { + Some(TokenNode::TerminalColonColon(TerminalColonColon::from_syntax_node(db, node))) + } + SyntaxKind::TerminalComma => { + Some(TokenNode::TerminalComma(TerminalComma::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDiv => { + Some(TokenNode::TerminalDiv(TerminalDiv::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDivEq => { + Some(TokenNode::TerminalDivEq(TerminalDivEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDot => { + Some(TokenNode::TerminalDot(TerminalDot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalDotDot => { + Some(TokenNode::TerminalDotDot(TerminalDotDot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEndOfFile => { + Some(TokenNode::TerminalEndOfFile(TerminalEndOfFile::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEq => { + Some(TokenNode::TerminalEq(TerminalEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEqEq => { + Some(TokenNode::TerminalEqEq(TerminalEqEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalGE => { + Some(TokenNode::TerminalGE(TerminalGE::from_syntax_node(db, node))) + } + SyntaxKind::TerminalGT => { + Some(TokenNode::TerminalGT(TerminalGT::from_syntax_node(db, node))) + } + SyntaxKind::TerminalHash => { + Some(TokenNode::TerminalHash(TerminalHash::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLBrace => { + Some(TokenNode::TerminalLBrace(TerminalLBrace::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLBrack => { + Some(TokenNode::TerminalLBrack(TerminalLBrack::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLE => { + Some(TokenNode::TerminalLE(TerminalLE::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLParen => { + Some(TokenNode::TerminalLParen(TerminalLParen::from_syntax_node(db, node))) + } + SyntaxKind::TerminalLT => { + Some(TokenNode::TerminalLT(TerminalLT::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMatchArrow => { + Some(TokenNode::TerminalMatchArrow(TerminalMatchArrow::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMinus => { + Some(TokenNode::TerminalMinus(TerminalMinus::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMinusEq => { + Some(TokenNode::TerminalMinusEq(TerminalMinusEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMod => { + Some(TokenNode::TerminalMod(TerminalMod::from_syntax_node(db, node))) + } + SyntaxKind::TerminalModEq => { + Some(TokenNode::TerminalModEq(TerminalModEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMul => { + Some(TokenNode::TerminalMul(TerminalMul::from_syntax_node(db, node))) + } + SyntaxKind::TerminalMulEq => { + Some(TokenNode::TerminalMulEq(TerminalMulEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalNeq => { + Some(TokenNode::TerminalNeq(TerminalNeq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalNot => { + Some(TokenNode::TerminalNot(TerminalNot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalBitNot => { + Some(TokenNode::TerminalBitNot(TerminalBitNot::from_syntax_node(db, node))) + } + SyntaxKind::TerminalOr => { + Some(TokenNode::TerminalOr(TerminalOr::from_syntax_node(db, node))) + } + SyntaxKind::TerminalOrOr => { + Some(TokenNode::TerminalOrOr(TerminalOrOr::from_syntax_node(db, node))) + } + SyntaxKind::TerminalPlus => { + Some(TokenNode::TerminalPlus(TerminalPlus::from_syntax_node(db, node))) + } + SyntaxKind::TerminalPlusEq => { + Some(TokenNode::TerminalPlusEq(TerminalPlusEq::from_syntax_node(db, node))) + } + SyntaxKind::TerminalQuestionMark => Some(TokenNode::TerminalQuestionMark( + TerminalQuestionMark::from_syntax_node(db, node), + )), + SyntaxKind::TerminalRBrace => { + Some(TokenNode::TerminalRBrace(TerminalRBrace::from_syntax_node(db, node))) + } + SyntaxKind::TerminalRBrack => { + Some(TokenNode::TerminalRBrack(TerminalRBrack::from_syntax_node(db, node))) + } + SyntaxKind::TerminalRParen => { + Some(TokenNode::TerminalRParen(TerminalRParen::from_syntax_node(db, node))) + } + SyntaxKind::TerminalSemicolon => { + Some(TokenNode::TerminalSemicolon(TerminalSemicolon::from_syntax_node(db, node))) + } + SyntaxKind::TerminalUnderscore => { + Some(TokenNode::TerminalUnderscore(TerminalUnderscore::from_syntax_node(db, node))) + } + SyntaxKind::TerminalXor => { + Some(TokenNode::TerminalXor(TerminalXor::from_syntax_node(db, node))) + } + SyntaxKind::TerminalEmpty => { + Some(TokenNode::TerminalEmpty(TerminalEmpty::from_syntax_node(db, node))) + } + _ => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { match self { TokenNode::TerminalIdentifier(x) => x.as_syntax_node(), diff --git a/crates/cairo-lang-syntax/src/node/mod.rs b/crates/cairo-lang-syntax/src/node/mod.rs index c4ef7d26c43..6758ac0e7a5 100644 --- a/crates/cairo-lang-syntax/src/node/mod.rs +++ b/crates/cairo-lang-syntax/src/node/mod.rs @@ -228,26 +228,21 @@ impl SyntaxNode { green::GreenNodeDetails::Token(text) => buffer.push_str(text), green::GreenNodeDetails::Node { .. } => { for child in db.get_children(self.clone()).iter() { - let kind = child.kind(db); - - if matches!(kind, SyntaxKind::Trivia) { - ast::Trivia::from_syntax_node(db, child.clone()) - .elements(db) - .iter() - .for_each(|element| { - if !matches!( - element, - ast::Trivium::SingleLineComment(_) - | ast::Trivium::SingleLineDocComment(_) - | ast::Trivium::SingleLineInnerComment(_) - ) { - buffer.push_str( - &element - .as_syntax_node() - .get_text_without_all_comment_trivia(db), - ); - } - }); + if let Some(trivia) = ast::Trivia::cast(db, child.clone()) { + trivia.elements(db).iter().for_each(|element| { + if !matches!( + element, + ast::Trivium::SingleLineComment(_) + | ast::Trivium::SingleLineDocComment(_) + | ast::Trivium::SingleLineInnerComment(_) + ) { + buffer.push_str( + &element + .as_syntax_node() + .get_text_without_all_comment_trivia(db), + ); + } + }); } else { buffer .push_str(&SyntaxNode::get_text_without_all_comment_trivia(child, db)); @@ -317,14 +312,14 @@ impl SyntaxNode { /// Trait for the typed view of the syntax tree. All the internal node implementations are under /// the ast module. -pub trait TypedSyntaxNode { +pub trait TypedSyntaxNode: Sized { /// The relevant SyntaxKind. None for enums. const OPTIONAL_KIND: Option; type StablePtr: TypedStablePtr; type Green; fn missing(db: &dyn SyntaxGroup) -> Self::Green; - // TODO(spapini): Make this return an Option, if the kind is wrong. fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self; + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option; fn as_syntax_node(&self) -> SyntaxNode; fn stable_ptr(&self) -> Self::StablePtr; } @@ -345,6 +340,14 @@ pub trait Terminal: TypedSyntaxNode { ) -> ::Green; /// Returns the text of the token of this terminal (excluding the trivia). fn text(&self, db: &dyn SyntaxGroup) -> SmolStr; + /// Casts a syntax node to this terminal type's token and then walks up to return the terminal. + fn cast_token(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + if node.kind(db) == Self::TokenType::OPTIONAL_KIND? { + Some(Self::from_syntax_node(db, node.parent()?)) + } else { + None + } + } } /// Trait for stable pointers to syntax nodes.