mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00

We treat macro calls as expressions (there's appropriate Into impl), which causes problem if there's expresison and non-expression macro in the same node (like in the match arm). We fix this problem by nesting macor patterns into another node (the same way we nest path into PathExpr or PathPat). Ideally, we probably should add a similar nesting for macro expressions, but that needs some careful thinking about macros in blocks: `{ am_i_expression!() }`.
4851 lines
126 KiB
Rust
4851 lines
126 KiB
Rust
//! Generated file, do not edit by hand, see `xtask/src/codegen`
|
|
|
|
use crate::{
|
|
ast::{self, AstChildren, AstNode},
|
|
SyntaxKind::{self, *},
|
|
SyntaxNode,
|
|
};
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct SourceFile {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for SourceFile {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for SourceFile {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
SOURCE_FILE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::ModuleItemOwner for SourceFile {}
|
|
impl ast::FnDefOwner for SourceFile {}
|
|
impl SourceFile {
|
|
pub fn modules(&self) -> AstChildren<Module> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct FnDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for FnDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for FnDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FN_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for FnDef {}
|
|
impl ast::NameOwner for FnDef {}
|
|
impl ast::TypeParamsOwner for FnDef {}
|
|
impl ast::DocCommentsOwner for FnDef {}
|
|
impl ast::AttrsOwner for FnDef {}
|
|
impl FnDef {
|
|
pub fn param_list(&self) -> Option<ParamList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn ret_type(&self) -> Option<RetType> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn body(&self) -> Option<BlockExpr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RetType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RetType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RetType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RET_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RetType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct StructDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for StructDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for StructDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
STRUCT_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for StructDef {}
|
|
impl ast::NameOwner for StructDef {}
|
|
impl ast::TypeParamsOwner for StructDef {}
|
|
impl ast::AttrsOwner for StructDef {}
|
|
impl ast::DocCommentsOwner for StructDef {}
|
|
impl StructDef {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct UnionDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for UnionDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for UnionDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
UNION_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for UnionDef {}
|
|
impl ast::NameOwner for UnionDef {}
|
|
impl ast::TypeParamsOwner for UnionDef {}
|
|
impl ast::AttrsOwner for UnionDef {}
|
|
impl ast::DocCommentsOwner for UnionDef {}
|
|
impl UnionDef {
|
|
pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordFieldDefList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordFieldDefList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordFieldDefList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD_DEF_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordFieldDefList {
|
|
pub fn fields(&self) -> AstChildren<RecordFieldDef> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordFieldDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordFieldDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordFieldDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for RecordFieldDef {}
|
|
impl ast::NameOwner for RecordFieldDef {}
|
|
impl ast::AttrsOwner for RecordFieldDef {}
|
|
impl ast::DocCommentsOwner for RecordFieldDef {}
|
|
impl ast::TypeAscriptionOwner for RecordFieldDef {}
|
|
impl RecordFieldDef {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TupleFieldDefList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TupleFieldDefList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TupleFieldDefList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_FIELD_DEF_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TupleFieldDefList {
|
|
pub fn fields(&self) -> AstChildren<TupleFieldDef> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TupleFieldDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TupleFieldDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TupleFieldDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_FIELD_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for TupleFieldDef {}
|
|
impl ast::AttrsOwner for TupleFieldDef {}
|
|
impl TupleFieldDef {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct EnumDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for EnumDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for EnumDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ENUM_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for EnumDef {}
|
|
impl ast::NameOwner for EnumDef {}
|
|
impl ast::TypeParamsOwner for EnumDef {}
|
|
impl ast::AttrsOwner for EnumDef {}
|
|
impl ast::DocCommentsOwner for EnumDef {}
|
|
impl EnumDef {
|
|
pub fn variant_list(&self) -> Option<EnumVariantList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct EnumVariantList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for EnumVariantList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for EnumVariantList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ENUM_VARIANT_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl EnumVariantList {
|
|
pub fn variants(&self) -> AstChildren<EnumVariant> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct EnumVariant {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for EnumVariant {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for EnumVariant {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ENUM_VARIANT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for EnumVariant {}
|
|
impl ast::DocCommentsOwner for EnumVariant {}
|
|
impl ast::AttrsOwner for EnumVariant {}
|
|
impl EnumVariant {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TraitDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TraitDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TraitDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TRAIT_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for TraitDef {}
|
|
impl ast::NameOwner for TraitDef {}
|
|
impl ast::AttrsOwner for TraitDef {}
|
|
impl ast::DocCommentsOwner for TraitDef {}
|
|
impl ast::TypeParamsOwner for TraitDef {}
|
|
impl ast::TypeBoundsOwner for TraitDef {}
|
|
impl TraitDef {
|
|
pub fn item_list(&self) -> Option<ItemList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Module {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Module {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Module {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MODULE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for Module {}
|
|
impl ast::NameOwner for Module {}
|
|
impl ast::AttrsOwner for Module {}
|
|
impl ast::DocCommentsOwner for Module {}
|
|
impl Module {
|
|
pub fn item_list(&self) -> Option<ItemList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ItemList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ItemList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ItemList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ITEM_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::FnDefOwner for ItemList {}
|
|
impl ast::ModuleItemOwner for ItemList {}
|
|
impl ItemList {
|
|
pub fn impl_items(&self) -> AstChildren<ImplItem> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ConstDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ConstDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ConstDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CONST_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for ConstDef {}
|
|
impl ast::NameOwner for ConstDef {}
|
|
impl ast::TypeParamsOwner for ConstDef {}
|
|
impl ast::AttrsOwner for ConstDef {}
|
|
impl ast::DocCommentsOwner for ConstDef {}
|
|
impl ast::TypeAscriptionOwner for ConstDef {}
|
|
impl ConstDef {
|
|
pub fn body(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct StaticDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for StaticDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for StaticDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
STATIC_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for StaticDef {}
|
|
impl ast::NameOwner for StaticDef {}
|
|
impl ast::TypeParamsOwner for StaticDef {}
|
|
impl ast::AttrsOwner for StaticDef {}
|
|
impl ast::DocCommentsOwner for StaticDef {}
|
|
impl ast::TypeAscriptionOwner for StaticDef {}
|
|
impl StaticDef {
|
|
pub fn body(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeAliasDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeAliasDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeAliasDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_ALIAS_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::VisibilityOwner for TypeAliasDef {}
|
|
impl ast::NameOwner for TypeAliasDef {}
|
|
impl ast::TypeParamsOwner for TypeAliasDef {}
|
|
impl ast::AttrsOwner for TypeAliasDef {}
|
|
impl ast::DocCommentsOwner for TypeAliasDef {}
|
|
impl ast::TypeBoundsOwner for TypeAliasDef {}
|
|
impl TypeAliasDef {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ImplDef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ImplDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ImplDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
IMPL_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeParamsOwner for ImplDef {}
|
|
impl ast::AttrsOwner for ImplDef {}
|
|
impl ImplDef {
|
|
pub fn item_list(&self) -> Option<ItemList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ParenType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ParenType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ParenType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PAREN_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ParenType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TupleType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TupleType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TupleType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TupleType {
|
|
pub fn fields(&self) -> AstChildren<TypeRef> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct NeverType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for NeverType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for NeverType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
NEVER_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl NeverType {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PathType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PathType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PathType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PATH_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PathType {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PointerType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PointerType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PointerType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
POINTER_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PointerType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ArrayType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ArrayType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ArrayType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ARRAY_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ArrayType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct SliceType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for SliceType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for SliceType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
SLICE_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl SliceType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ReferenceType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ReferenceType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ReferenceType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
REFERENCE_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ReferenceType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PlaceholderType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PlaceholderType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PlaceholderType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PLACEHOLDER_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PlaceholderType {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct FnPointerType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for FnPointerType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for FnPointerType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FN_POINTER_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl FnPointerType {
|
|
pub fn param_list(&self) -> Option<ParamList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn ret_type(&self) -> Option<RetType> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ForType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ForType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ForType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FOR_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ForType {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ImplTraitType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ImplTraitType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ImplTraitType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
IMPL_TRAIT_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeBoundsOwner for ImplTraitType {}
|
|
impl ImplTraitType {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct DynTraitType {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for DynTraitType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for DynTraitType {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
DYN_TRAIT_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeBoundsOwner for DynTraitType {}
|
|
impl DynTraitType {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TupleExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TupleExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TupleExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TupleExpr {
|
|
pub fn exprs(&self) -> AstChildren<Expr> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ArrayExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ArrayExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ArrayExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ARRAY_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ArrayExpr {
|
|
pub fn exprs(&self) -> AstChildren<Expr> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ParenExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ParenExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ParenExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PAREN_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ParenExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PathExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PathExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PathExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PATH_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PathExpr {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LambdaExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LambdaExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LambdaExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LAMBDA_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl LambdaExpr {
|
|
pub fn param_list(&self) -> Option<ParamList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn ret_type(&self) -> Option<RetType> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn body(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct IfExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for IfExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for IfExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
IF_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl IfExpr {
|
|
pub fn condition(&self) -> Option<Condition> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LoopExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LoopExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LoopExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LOOP_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::LoopBodyOwner for LoopExpr {}
|
|
impl LoopExpr {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TryBlockExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TryBlockExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TryBlockExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TRY_BLOCK_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TryBlockExpr {
|
|
pub fn body(&self) -> Option<BlockExpr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ForExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ForExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ForExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FOR_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::LoopBodyOwner for ForExpr {}
|
|
impl ForExpr {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn iterable(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct WhileExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for WhileExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for WhileExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
WHILE_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::LoopBodyOwner for WhileExpr {}
|
|
impl WhileExpr {
|
|
pub fn condition(&self) -> Option<Condition> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ContinueExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ContinueExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ContinueExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CONTINUE_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ContinueExpr {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BreakExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BreakExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BreakExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BREAK_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl BreakExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Label {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Label {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Label {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LABEL => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Label {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BlockExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BlockExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BlockExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BLOCK_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl BlockExpr {
|
|
pub fn block(&self) -> Option<Block> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ReturnExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ReturnExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ReturnExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RETURN_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ReturnExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct CallExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for CallExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for CallExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CALL_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::ArgListOwner for CallExpr {}
|
|
impl CallExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MethodCallExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MethodCallExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MethodCallExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
METHOD_CALL_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::ArgListOwner for MethodCallExpr {}
|
|
impl MethodCallExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn type_arg_list(&self) -> Option<TypeArgList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct IndexExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for IndexExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for IndexExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
INDEX_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl IndexExpr {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct FieldExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for FieldExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for FieldExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FIELD_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl FieldExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct AwaitExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for AwaitExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for AwaitExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
AWAIT_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl AwaitExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TryExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TryExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TryExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TRY_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TryExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct CastExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for CastExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for CastExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CAST_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl CastExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RefExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RefExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RefExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
REF_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RefExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PrefixExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PrefixExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PrefixExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PREFIX_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PrefixExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BoxExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BoxExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BoxExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BOX_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl BoxExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RangeExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RangeExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RangeExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RANGE_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RangeExpr {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BinExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BinExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BinExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BIN_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl BinExpr {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Literal {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Literal {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Literal {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LITERAL => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Literal {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MatchExpr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MatchExpr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MatchExpr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MATCH_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl MatchExpr {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn match_arm_list(&self) -> Option<MatchArmList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MatchArmList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MatchArmList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MatchArmList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MATCH_ARM_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for MatchArmList {}
|
|
impl MatchArmList {
|
|
pub fn arms(&self) -> AstChildren<MatchArm> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MatchArm {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MatchArm {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MatchArm {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MATCH_ARM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for MatchArm {}
|
|
impl MatchArm {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn guard(&self) -> Option<MatchGuard> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MatchGuard {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MatchGuard {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MatchGuard {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MATCH_GUARD => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl MatchGuard {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordLit {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordLit {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordLit {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_LIT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordLit {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn record_field_list(&self) -> Option<RecordFieldList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordFieldList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordFieldList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordFieldList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordFieldList {
|
|
pub fn fields(&self) -> AstChildren<RecordField> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn spread(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordField {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordField {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordField {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordField {
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct OrPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for OrPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for OrPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
OR_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl OrPat {
|
|
pub fn pats(&self) -> AstChildren<Pat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ParenPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ParenPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ParenPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PAREN_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ParenPat {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RefPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RefPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RefPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
REF_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RefPat {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BoxPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BoxPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BoxPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BOX_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl BoxPat {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BindPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for BindPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for BindPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BIND_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for BindPat {}
|
|
impl BindPat {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PlaceholderPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PlaceholderPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PlaceholderPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PLACEHOLDER_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PlaceholderPat {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct DotDotPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for DotDotPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for DotDotPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
DOT_DOT_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl DotDotPat {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PathPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PathPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PathPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PATH_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PathPat {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct SlicePat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for SlicePat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for SlicePat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
SLICE_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl SlicePat {
|
|
pub fn args(&self) -> AstChildren<Pat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RangePat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RangePat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RangePat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RANGE_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RangePat {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LiteralPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LiteralPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LiteralPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LITERAL_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl LiteralPat {
|
|
pub fn literal(&self) -> Option<Literal> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MacroPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MacroPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MacroPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MACRO_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl MacroPat {
|
|
pub fn macro_call(&self) -> Option<MacroCall> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordPat {
|
|
pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordFieldPatList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordFieldPatList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordFieldPatList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD_PAT_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl RecordFieldPatList {
|
|
pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn bind_pats(&self) -> AstChildren<BindPat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct RecordFieldPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for RecordFieldPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for RecordFieldPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
RECORD_FIELD_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for RecordFieldPat {}
|
|
impl RecordFieldPat {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TupleStructPat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TupleStructPat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TupleStructPat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_STRUCT_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TupleStructPat {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn args(&self) -> AstChildren<Pat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TuplePat {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TuplePat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TuplePat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TuplePat {
|
|
pub fn args(&self) -> AstChildren<Pat> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Visibility {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Visibility {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Visibility {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
VISIBILITY => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Visibility {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Name {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Name {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Name {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
NAME => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Name {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct NameRef {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for NameRef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for NameRef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
NAME_REF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl NameRef {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MacroCall {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MacroCall {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MacroCall {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MACRO_CALL => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for MacroCall {}
|
|
impl ast::AttrsOwner for MacroCall {}
|
|
impl ast::DocCommentsOwner for MacroCall {}
|
|
impl MacroCall {
|
|
pub fn token_tree(&self) -> Option<TokenTree> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Attr {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Attr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Attr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ATTR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Attr {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn input(&self) -> Option<AttrInput> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TokenTree {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TokenTree {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TokenTree {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TOKEN_TREE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TokenTree {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeParamList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeParamList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeParamList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_PARAM_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TypeParamList {
|
|
pub fn type_params(&self) -> AstChildren<TypeParam> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeParam {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeParam {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeParam {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_PARAM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for TypeParam {}
|
|
impl ast::AttrsOwner for TypeParam {}
|
|
impl ast::TypeBoundsOwner for TypeParam {}
|
|
impl TypeParam {
|
|
pub fn default_type(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ConstParam {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ConstParam {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ConstParam {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CONST_PARAM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for ConstParam {}
|
|
impl ast::AttrsOwner for ConstParam {}
|
|
impl ast::TypeAscriptionOwner for ConstParam {}
|
|
impl ConstParam {
|
|
pub fn default_val(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LifetimeParam {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LifetimeParam {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LifetimeParam {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LIFETIME_PARAM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for LifetimeParam {}
|
|
impl LifetimeParam {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeBound {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeBound {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeBound {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_BOUND => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TypeBound {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeBoundList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeBoundList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeBoundList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_BOUND_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TypeBoundList {
|
|
pub fn bounds(&self) -> AstChildren<TypeBound> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct WherePred {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for WherePred {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for WherePred {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
WHERE_PRED => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeBoundsOwner for WherePred {}
|
|
impl WherePred {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct WhereClause {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for WhereClause {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for WhereClause {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
WHERE_CLAUSE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl WhereClause {
|
|
pub fn predicates(&self) -> AstChildren<WherePred> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ExprStmt {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ExprStmt {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ExprStmt {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
EXPR_STMT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ExprStmt {
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LetStmt {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LetStmt {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LetStmt {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LET_STMT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeAscriptionOwner for LetStmt {}
|
|
impl LetStmt {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn initializer(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Condition {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Condition {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Condition {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CONDITION => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Condition {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Block {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Block {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Block {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
BLOCK => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for Block {}
|
|
impl ast::ModuleItemOwner for Block {}
|
|
impl Block {
|
|
pub fn statements(&self) -> AstChildren<Stmt> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ParamList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ParamList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ParamList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PARAM_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ParamList {
|
|
pub fn self_param(&self) -> Option<SelfParam> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn params(&self) -> AstChildren<Param> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct SelfParam {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for SelfParam {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for SelfParam {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
SELF_PARAM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeAscriptionOwner for SelfParam {}
|
|
impl ast::AttrsOwner for SelfParam {}
|
|
impl SelfParam {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Param {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Param {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Param {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PARAM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::TypeAscriptionOwner for Param {}
|
|
impl ast::AttrsOwner for Param {}
|
|
impl Param {
|
|
pub fn pat(&self) -> Option<Pat> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct UseItem {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for UseItem {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for UseItem {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
USE_ITEM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for UseItem {}
|
|
impl ast::VisibilityOwner for UseItem {}
|
|
impl UseItem {
|
|
pub fn use_tree(&self) -> Option<UseTree> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct UseTree {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for UseTree {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for UseTree {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
USE_TREE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl UseTree {
|
|
pub fn path(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn use_tree_list(&self) -> Option<UseTreeList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn alias(&self) -> Option<Alias> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Alias {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Alias {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Alias {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ALIAS => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::NameOwner for Alias {}
|
|
impl Alias {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct UseTreeList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for UseTreeList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for UseTreeList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
USE_TREE_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl UseTreeList {
|
|
pub fn use_trees(&self) -> AstChildren<UseTree> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ExternCrateItem {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ExternCrateItem {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ExternCrateItem {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
EXTERN_CRATE_ITEM => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for ExternCrateItem {}
|
|
impl ast::VisibilityOwner for ExternCrateItem {}
|
|
impl ExternCrateItem {
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn alias(&self) -> Option<Alias> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ArgList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ArgList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ArgList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ARG_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ArgList {
|
|
pub fn args(&self) -> AstChildren<Expr> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Path {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for Path {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Path {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PATH => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl Path {
|
|
pub fn segment(&self) -> Option<PathSegment> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn qualifier(&self) -> Option<Path> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct PathSegment {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for PathSegment {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for PathSegment {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PATH_SEGMENT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl PathSegment {
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn type_arg_list(&self) -> Option<TypeArgList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn param_list(&self) -> Option<ParamList> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn ret_type(&self) -> Option<RetType> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn path_type(&self) -> Option<PathType> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeArgList {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeArgList {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeArgList {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_ARG_LIST => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TypeArgList {
|
|
pub fn type_args(&self) -> AstChildren<TypeArg> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn const_arg(&self) -> AstChildren<ConstArg> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct TypeArg {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for TypeArg {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeArg {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TYPE_ARG => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl TypeArg {
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct AssocTypeArg {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for AssocTypeArg {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for AssocTypeArg {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
ASSOC_TYPE_ARG => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl AssocTypeArg {
|
|
pub fn name_ref(&self) -> Option<NameRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn type_ref(&self) -> Option<TypeRef> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct LifetimeArg {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for LifetimeArg {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for LifetimeArg {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LIFETIME_ARG => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl LifetimeArg {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct ConstArg {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for ConstArg {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ConstArg {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
CONST_ARG => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ConstArg {
|
|
pub fn literal(&self) -> Option<Literal> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
pub fn block_expr(&self) -> Option<BlockExpr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MacroItems {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MacroItems {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MacroItems {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MACRO_ITEMS => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl ast::ModuleItemOwner for MacroItems {}
|
|
impl ast::FnDefOwner for MacroItems {}
|
|
impl MacroItems {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct MacroStmts {
|
|
pub(crate) syntax: SyntaxNode,
|
|
}
|
|
impl std::fmt::Display for MacroStmts {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for MacroStmts {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
MACRO_STMTS => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
if Self::can_cast(syntax.kind()) {
|
|
Some(Self { syntax })
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.syntax
|
|
}
|
|
}
|
|
impl MacroStmts {
|
|
pub fn statements(&self) -> AstChildren<Stmt> {
|
|
AstChildren::new(&self.syntax)
|
|
}
|
|
pub fn expr(&self) -> Option<Expr> {
|
|
AstChildren::new(&self.syntax).next()
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum NominalDef {
|
|
StructDef(StructDef),
|
|
EnumDef(EnumDef),
|
|
UnionDef(UnionDef),
|
|
}
|
|
impl From<StructDef> for NominalDef {
|
|
fn from(node: StructDef) -> NominalDef {
|
|
NominalDef::StructDef(node)
|
|
}
|
|
}
|
|
impl From<EnumDef> for NominalDef {
|
|
fn from(node: EnumDef) -> NominalDef {
|
|
NominalDef::EnumDef(node)
|
|
}
|
|
}
|
|
impl From<UnionDef> for NominalDef {
|
|
fn from(node: UnionDef) -> NominalDef {
|
|
NominalDef::UnionDef(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for NominalDef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for NominalDef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
|
|
ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
|
|
UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
NominalDef::StructDef(it) => &it.syntax,
|
|
NominalDef::EnumDef(it) => &it.syntax,
|
|
NominalDef::UnionDef(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
impl ast::NameOwner for NominalDef {}
|
|
impl ast::TypeParamsOwner for NominalDef {}
|
|
impl ast::AttrsOwner for NominalDef {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum TypeRef {
|
|
ParenType(ParenType),
|
|
TupleType(TupleType),
|
|
NeverType(NeverType),
|
|
PathType(PathType),
|
|
PointerType(PointerType),
|
|
ArrayType(ArrayType),
|
|
SliceType(SliceType),
|
|
ReferenceType(ReferenceType),
|
|
PlaceholderType(PlaceholderType),
|
|
FnPointerType(FnPointerType),
|
|
ForType(ForType),
|
|
ImplTraitType(ImplTraitType),
|
|
DynTraitType(DynTraitType),
|
|
}
|
|
impl From<ParenType> for TypeRef {
|
|
fn from(node: ParenType) -> TypeRef {
|
|
TypeRef::ParenType(node)
|
|
}
|
|
}
|
|
impl From<TupleType> for TypeRef {
|
|
fn from(node: TupleType) -> TypeRef {
|
|
TypeRef::TupleType(node)
|
|
}
|
|
}
|
|
impl From<NeverType> for TypeRef {
|
|
fn from(node: NeverType) -> TypeRef {
|
|
TypeRef::NeverType(node)
|
|
}
|
|
}
|
|
impl From<PathType> for TypeRef {
|
|
fn from(node: PathType) -> TypeRef {
|
|
TypeRef::PathType(node)
|
|
}
|
|
}
|
|
impl From<PointerType> for TypeRef {
|
|
fn from(node: PointerType) -> TypeRef {
|
|
TypeRef::PointerType(node)
|
|
}
|
|
}
|
|
impl From<ArrayType> for TypeRef {
|
|
fn from(node: ArrayType) -> TypeRef {
|
|
TypeRef::ArrayType(node)
|
|
}
|
|
}
|
|
impl From<SliceType> for TypeRef {
|
|
fn from(node: SliceType) -> TypeRef {
|
|
TypeRef::SliceType(node)
|
|
}
|
|
}
|
|
impl From<ReferenceType> for TypeRef {
|
|
fn from(node: ReferenceType) -> TypeRef {
|
|
TypeRef::ReferenceType(node)
|
|
}
|
|
}
|
|
impl From<PlaceholderType> for TypeRef {
|
|
fn from(node: PlaceholderType) -> TypeRef {
|
|
TypeRef::PlaceholderType(node)
|
|
}
|
|
}
|
|
impl From<FnPointerType> for TypeRef {
|
|
fn from(node: FnPointerType) -> TypeRef {
|
|
TypeRef::FnPointerType(node)
|
|
}
|
|
}
|
|
impl From<ForType> for TypeRef {
|
|
fn from(node: ForType) -> TypeRef {
|
|
TypeRef::ForType(node)
|
|
}
|
|
}
|
|
impl From<ImplTraitType> for TypeRef {
|
|
fn from(node: ImplTraitType) -> TypeRef {
|
|
TypeRef::ImplTraitType(node)
|
|
}
|
|
}
|
|
impl From<DynTraitType> for TypeRef {
|
|
fn from(node: DynTraitType) -> TypeRef {
|
|
TypeRef::DynTraitType(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for TypeRef {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for TypeRef {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
|
|
| SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
|
|
| IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }),
|
|
TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }),
|
|
NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }),
|
|
PATH_TYPE => TypeRef::PathType(PathType { syntax }),
|
|
POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }),
|
|
ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }),
|
|
SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }),
|
|
REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }),
|
|
PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }),
|
|
FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }),
|
|
FOR_TYPE => TypeRef::ForType(ForType { syntax }),
|
|
IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }),
|
|
DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
TypeRef::ParenType(it) => &it.syntax,
|
|
TypeRef::TupleType(it) => &it.syntax,
|
|
TypeRef::NeverType(it) => &it.syntax,
|
|
TypeRef::PathType(it) => &it.syntax,
|
|
TypeRef::PointerType(it) => &it.syntax,
|
|
TypeRef::ArrayType(it) => &it.syntax,
|
|
TypeRef::SliceType(it) => &it.syntax,
|
|
TypeRef::ReferenceType(it) => &it.syntax,
|
|
TypeRef::PlaceholderType(it) => &it.syntax,
|
|
TypeRef::FnPointerType(it) => &it.syntax,
|
|
TypeRef::ForType(it) => &it.syntax,
|
|
TypeRef::ImplTraitType(it) => &it.syntax,
|
|
TypeRef::DynTraitType(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum ModuleItem {
|
|
StructDef(StructDef),
|
|
UnionDef(UnionDef),
|
|
EnumDef(EnumDef),
|
|
FnDef(FnDef),
|
|
TraitDef(TraitDef),
|
|
TypeAliasDef(TypeAliasDef),
|
|
ImplDef(ImplDef),
|
|
UseItem(UseItem),
|
|
ExternCrateItem(ExternCrateItem),
|
|
ConstDef(ConstDef),
|
|
StaticDef(StaticDef),
|
|
Module(Module),
|
|
MacroCall(MacroCall),
|
|
}
|
|
impl From<StructDef> for ModuleItem {
|
|
fn from(node: StructDef) -> ModuleItem {
|
|
ModuleItem::StructDef(node)
|
|
}
|
|
}
|
|
impl From<UnionDef> for ModuleItem {
|
|
fn from(node: UnionDef) -> ModuleItem {
|
|
ModuleItem::UnionDef(node)
|
|
}
|
|
}
|
|
impl From<EnumDef> for ModuleItem {
|
|
fn from(node: EnumDef) -> ModuleItem {
|
|
ModuleItem::EnumDef(node)
|
|
}
|
|
}
|
|
impl From<FnDef> for ModuleItem {
|
|
fn from(node: FnDef) -> ModuleItem {
|
|
ModuleItem::FnDef(node)
|
|
}
|
|
}
|
|
impl From<TraitDef> for ModuleItem {
|
|
fn from(node: TraitDef) -> ModuleItem {
|
|
ModuleItem::TraitDef(node)
|
|
}
|
|
}
|
|
impl From<TypeAliasDef> for ModuleItem {
|
|
fn from(node: TypeAliasDef) -> ModuleItem {
|
|
ModuleItem::TypeAliasDef(node)
|
|
}
|
|
}
|
|
impl From<ImplDef> for ModuleItem {
|
|
fn from(node: ImplDef) -> ModuleItem {
|
|
ModuleItem::ImplDef(node)
|
|
}
|
|
}
|
|
impl From<UseItem> for ModuleItem {
|
|
fn from(node: UseItem) -> ModuleItem {
|
|
ModuleItem::UseItem(node)
|
|
}
|
|
}
|
|
impl From<ExternCrateItem> for ModuleItem {
|
|
fn from(node: ExternCrateItem) -> ModuleItem {
|
|
ModuleItem::ExternCrateItem(node)
|
|
}
|
|
}
|
|
impl From<ConstDef> for ModuleItem {
|
|
fn from(node: ConstDef) -> ModuleItem {
|
|
ModuleItem::ConstDef(node)
|
|
}
|
|
}
|
|
impl From<StaticDef> for ModuleItem {
|
|
fn from(node: StaticDef) -> ModuleItem {
|
|
ModuleItem::StaticDef(node)
|
|
}
|
|
}
|
|
impl From<Module> for ModuleItem {
|
|
fn from(node: Module) -> ModuleItem {
|
|
ModuleItem::Module(node)
|
|
}
|
|
}
|
|
impl From<MacroCall> for ModuleItem {
|
|
fn from(node: MacroCall) -> ModuleItem {
|
|
ModuleItem::MacroCall(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for ModuleItem {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ModuleItem {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
|
|
| USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
|
|
UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
|
|
ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
|
|
FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
|
|
TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
|
|
TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
|
|
IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }),
|
|
USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
|
|
EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
|
|
CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
|
|
STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
|
|
MODULE => ModuleItem::Module(Module { syntax }),
|
|
MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
ModuleItem::StructDef(it) => &it.syntax,
|
|
ModuleItem::UnionDef(it) => &it.syntax,
|
|
ModuleItem::EnumDef(it) => &it.syntax,
|
|
ModuleItem::FnDef(it) => &it.syntax,
|
|
ModuleItem::TraitDef(it) => &it.syntax,
|
|
ModuleItem::TypeAliasDef(it) => &it.syntax,
|
|
ModuleItem::ImplDef(it) => &it.syntax,
|
|
ModuleItem::UseItem(it) => &it.syntax,
|
|
ModuleItem::ExternCrateItem(it) => &it.syntax,
|
|
ModuleItem::ConstDef(it) => &it.syntax,
|
|
ModuleItem::StaticDef(it) => &it.syntax,
|
|
ModuleItem::Module(it) => &it.syntax,
|
|
ModuleItem::MacroCall(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for ModuleItem {}
|
|
impl ast::VisibilityOwner for ModuleItem {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum ImplItem {
|
|
FnDef(FnDef),
|
|
TypeAliasDef(TypeAliasDef),
|
|
ConstDef(ConstDef),
|
|
}
|
|
impl From<FnDef> for ImplItem {
|
|
fn from(node: FnDef) -> ImplItem {
|
|
ImplItem::FnDef(node)
|
|
}
|
|
}
|
|
impl From<TypeAliasDef> for ImplItem {
|
|
fn from(node: TypeAliasDef) -> ImplItem {
|
|
ImplItem::TypeAliasDef(node)
|
|
}
|
|
}
|
|
impl From<ConstDef> for ImplItem {
|
|
fn from(node: ConstDef) -> ImplItem {
|
|
ImplItem::ConstDef(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for ImplItem {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for ImplItem {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
FN_DEF => ImplItem::FnDef(FnDef { syntax }),
|
|
TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }),
|
|
CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
ImplItem::FnDef(it) => &it.syntax,
|
|
ImplItem::TypeAliasDef(it) => &it.syntax,
|
|
ImplItem::ConstDef(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
impl ast::AttrsOwner for ImplItem {}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Expr {
|
|
TupleExpr(TupleExpr),
|
|
ArrayExpr(ArrayExpr),
|
|
ParenExpr(ParenExpr),
|
|
PathExpr(PathExpr),
|
|
LambdaExpr(LambdaExpr),
|
|
IfExpr(IfExpr),
|
|
LoopExpr(LoopExpr),
|
|
ForExpr(ForExpr),
|
|
WhileExpr(WhileExpr),
|
|
ContinueExpr(ContinueExpr),
|
|
BreakExpr(BreakExpr),
|
|
Label(Label),
|
|
BlockExpr(BlockExpr),
|
|
ReturnExpr(ReturnExpr),
|
|
MatchExpr(MatchExpr),
|
|
RecordLit(RecordLit),
|
|
CallExpr(CallExpr),
|
|
IndexExpr(IndexExpr),
|
|
MethodCallExpr(MethodCallExpr),
|
|
FieldExpr(FieldExpr),
|
|
AwaitExpr(AwaitExpr),
|
|
TryExpr(TryExpr),
|
|
TryBlockExpr(TryBlockExpr),
|
|
CastExpr(CastExpr),
|
|
RefExpr(RefExpr),
|
|
PrefixExpr(PrefixExpr),
|
|
RangeExpr(RangeExpr),
|
|
BinExpr(BinExpr),
|
|
Literal(Literal),
|
|
MacroCall(MacroCall),
|
|
BoxExpr(BoxExpr),
|
|
}
|
|
impl From<TupleExpr> for Expr {
|
|
fn from(node: TupleExpr) -> Expr {
|
|
Expr::TupleExpr(node)
|
|
}
|
|
}
|
|
impl From<ArrayExpr> for Expr {
|
|
fn from(node: ArrayExpr) -> Expr {
|
|
Expr::ArrayExpr(node)
|
|
}
|
|
}
|
|
impl From<ParenExpr> for Expr {
|
|
fn from(node: ParenExpr) -> Expr {
|
|
Expr::ParenExpr(node)
|
|
}
|
|
}
|
|
impl From<PathExpr> for Expr {
|
|
fn from(node: PathExpr) -> Expr {
|
|
Expr::PathExpr(node)
|
|
}
|
|
}
|
|
impl From<LambdaExpr> for Expr {
|
|
fn from(node: LambdaExpr) -> Expr {
|
|
Expr::LambdaExpr(node)
|
|
}
|
|
}
|
|
impl From<IfExpr> for Expr {
|
|
fn from(node: IfExpr) -> Expr {
|
|
Expr::IfExpr(node)
|
|
}
|
|
}
|
|
impl From<LoopExpr> for Expr {
|
|
fn from(node: LoopExpr) -> Expr {
|
|
Expr::LoopExpr(node)
|
|
}
|
|
}
|
|
impl From<ForExpr> for Expr {
|
|
fn from(node: ForExpr) -> Expr {
|
|
Expr::ForExpr(node)
|
|
}
|
|
}
|
|
impl From<WhileExpr> for Expr {
|
|
fn from(node: WhileExpr) -> Expr {
|
|
Expr::WhileExpr(node)
|
|
}
|
|
}
|
|
impl From<ContinueExpr> for Expr {
|
|
fn from(node: ContinueExpr) -> Expr {
|
|
Expr::ContinueExpr(node)
|
|
}
|
|
}
|
|
impl From<BreakExpr> for Expr {
|
|
fn from(node: BreakExpr) -> Expr {
|
|
Expr::BreakExpr(node)
|
|
}
|
|
}
|
|
impl From<Label> for Expr {
|
|
fn from(node: Label) -> Expr {
|
|
Expr::Label(node)
|
|
}
|
|
}
|
|
impl From<BlockExpr> for Expr {
|
|
fn from(node: BlockExpr) -> Expr {
|
|
Expr::BlockExpr(node)
|
|
}
|
|
}
|
|
impl From<ReturnExpr> for Expr {
|
|
fn from(node: ReturnExpr) -> Expr {
|
|
Expr::ReturnExpr(node)
|
|
}
|
|
}
|
|
impl From<MatchExpr> for Expr {
|
|
fn from(node: MatchExpr) -> Expr {
|
|
Expr::MatchExpr(node)
|
|
}
|
|
}
|
|
impl From<RecordLit> for Expr {
|
|
fn from(node: RecordLit) -> Expr {
|
|
Expr::RecordLit(node)
|
|
}
|
|
}
|
|
impl From<CallExpr> for Expr {
|
|
fn from(node: CallExpr) -> Expr {
|
|
Expr::CallExpr(node)
|
|
}
|
|
}
|
|
impl From<IndexExpr> for Expr {
|
|
fn from(node: IndexExpr) -> Expr {
|
|
Expr::IndexExpr(node)
|
|
}
|
|
}
|
|
impl From<MethodCallExpr> for Expr {
|
|
fn from(node: MethodCallExpr) -> Expr {
|
|
Expr::MethodCallExpr(node)
|
|
}
|
|
}
|
|
impl From<FieldExpr> for Expr {
|
|
fn from(node: FieldExpr) -> Expr {
|
|
Expr::FieldExpr(node)
|
|
}
|
|
}
|
|
impl From<AwaitExpr> for Expr {
|
|
fn from(node: AwaitExpr) -> Expr {
|
|
Expr::AwaitExpr(node)
|
|
}
|
|
}
|
|
impl From<TryExpr> for Expr {
|
|
fn from(node: TryExpr) -> Expr {
|
|
Expr::TryExpr(node)
|
|
}
|
|
}
|
|
impl From<TryBlockExpr> for Expr {
|
|
fn from(node: TryBlockExpr) -> Expr {
|
|
Expr::TryBlockExpr(node)
|
|
}
|
|
}
|
|
impl From<CastExpr> for Expr {
|
|
fn from(node: CastExpr) -> Expr {
|
|
Expr::CastExpr(node)
|
|
}
|
|
}
|
|
impl From<RefExpr> for Expr {
|
|
fn from(node: RefExpr) -> Expr {
|
|
Expr::RefExpr(node)
|
|
}
|
|
}
|
|
impl From<PrefixExpr> for Expr {
|
|
fn from(node: PrefixExpr) -> Expr {
|
|
Expr::PrefixExpr(node)
|
|
}
|
|
}
|
|
impl From<RangeExpr> for Expr {
|
|
fn from(node: RangeExpr) -> Expr {
|
|
Expr::RangeExpr(node)
|
|
}
|
|
}
|
|
impl From<BinExpr> for Expr {
|
|
fn from(node: BinExpr) -> Expr {
|
|
Expr::BinExpr(node)
|
|
}
|
|
}
|
|
impl From<Literal> for Expr {
|
|
fn from(node: Literal) -> Expr {
|
|
Expr::Literal(node)
|
|
}
|
|
}
|
|
impl From<MacroCall> for Expr {
|
|
fn from(node: MacroCall) -> Expr {
|
|
Expr::MacroCall(node)
|
|
}
|
|
}
|
|
impl From<BoxExpr> for Expr {
|
|
fn from(node: BoxExpr) -> Expr {
|
|
Expr::BoxExpr(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for Expr {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Expr {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
|
|
| LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
|
|
| BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
|
|
| METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
|
|
| CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
|
|
| BOX_EXPR => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
|
|
ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
|
|
PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
|
|
PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
|
|
LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
|
|
IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
|
|
LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
|
|
FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
|
|
WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
|
|
CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
|
|
BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
|
|
LABEL => Expr::Label(Label { syntax }),
|
|
BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
|
|
RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
|
|
MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
|
|
RECORD_LIT => Expr::RecordLit(RecordLit { syntax }),
|
|
CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
|
|
INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
|
|
METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
|
|
FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
|
|
AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
|
|
TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
|
|
TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
|
|
CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
|
|
REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
|
|
PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
|
|
RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }),
|
|
BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
|
|
LITERAL => Expr::Literal(Literal { syntax }),
|
|
MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
|
|
BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
Expr::TupleExpr(it) => &it.syntax,
|
|
Expr::ArrayExpr(it) => &it.syntax,
|
|
Expr::ParenExpr(it) => &it.syntax,
|
|
Expr::PathExpr(it) => &it.syntax,
|
|
Expr::LambdaExpr(it) => &it.syntax,
|
|
Expr::IfExpr(it) => &it.syntax,
|
|
Expr::LoopExpr(it) => &it.syntax,
|
|
Expr::ForExpr(it) => &it.syntax,
|
|
Expr::WhileExpr(it) => &it.syntax,
|
|
Expr::ContinueExpr(it) => &it.syntax,
|
|
Expr::BreakExpr(it) => &it.syntax,
|
|
Expr::Label(it) => &it.syntax,
|
|
Expr::BlockExpr(it) => &it.syntax,
|
|
Expr::ReturnExpr(it) => &it.syntax,
|
|
Expr::MatchExpr(it) => &it.syntax,
|
|
Expr::RecordLit(it) => &it.syntax,
|
|
Expr::CallExpr(it) => &it.syntax,
|
|
Expr::IndexExpr(it) => &it.syntax,
|
|
Expr::MethodCallExpr(it) => &it.syntax,
|
|
Expr::FieldExpr(it) => &it.syntax,
|
|
Expr::AwaitExpr(it) => &it.syntax,
|
|
Expr::TryExpr(it) => &it.syntax,
|
|
Expr::TryBlockExpr(it) => &it.syntax,
|
|
Expr::CastExpr(it) => &it.syntax,
|
|
Expr::RefExpr(it) => &it.syntax,
|
|
Expr::PrefixExpr(it) => &it.syntax,
|
|
Expr::RangeExpr(it) => &it.syntax,
|
|
Expr::BinExpr(it) => &it.syntax,
|
|
Expr::Literal(it) => &it.syntax,
|
|
Expr::MacroCall(it) => &it.syntax,
|
|
Expr::BoxExpr(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Pat {
|
|
OrPat(OrPat),
|
|
ParenPat(ParenPat),
|
|
RefPat(RefPat),
|
|
BoxPat(BoxPat),
|
|
BindPat(BindPat),
|
|
PlaceholderPat(PlaceholderPat),
|
|
DotDotPat(DotDotPat),
|
|
PathPat(PathPat),
|
|
RecordPat(RecordPat),
|
|
TupleStructPat(TupleStructPat),
|
|
TuplePat(TuplePat),
|
|
SlicePat(SlicePat),
|
|
RangePat(RangePat),
|
|
LiteralPat(LiteralPat),
|
|
MacroPat(MacroPat),
|
|
}
|
|
impl From<OrPat> for Pat {
|
|
fn from(node: OrPat) -> Pat {
|
|
Pat::OrPat(node)
|
|
}
|
|
}
|
|
impl From<ParenPat> for Pat {
|
|
fn from(node: ParenPat) -> Pat {
|
|
Pat::ParenPat(node)
|
|
}
|
|
}
|
|
impl From<RefPat> for Pat {
|
|
fn from(node: RefPat) -> Pat {
|
|
Pat::RefPat(node)
|
|
}
|
|
}
|
|
impl From<BoxPat> for Pat {
|
|
fn from(node: BoxPat) -> Pat {
|
|
Pat::BoxPat(node)
|
|
}
|
|
}
|
|
impl From<BindPat> for Pat {
|
|
fn from(node: BindPat) -> Pat {
|
|
Pat::BindPat(node)
|
|
}
|
|
}
|
|
impl From<PlaceholderPat> for Pat {
|
|
fn from(node: PlaceholderPat) -> Pat {
|
|
Pat::PlaceholderPat(node)
|
|
}
|
|
}
|
|
impl From<DotDotPat> for Pat {
|
|
fn from(node: DotDotPat) -> Pat {
|
|
Pat::DotDotPat(node)
|
|
}
|
|
}
|
|
impl From<PathPat> for Pat {
|
|
fn from(node: PathPat) -> Pat {
|
|
Pat::PathPat(node)
|
|
}
|
|
}
|
|
impl From<RecordPat> for Pat {
|
|
fn from(node: RecordPat) -> Pat {
|
|
Pat::RecordPat(node)
|
|
}
|
|
}
|
|
impl From<TupleStructPat> for Pat {
|
|
fn from(node: TupleStructPat) -> Pat {
|
|
Pat::TupleStructPat(node)
|
|
}
|
|
}
|
|
impl From<TuplePat> for Pat {
|
|
fn from(node: TuplePat) -> Pat {
|
|
Pat::TuplePat(node)
|
|
}
|
|
}
|
|
impl From<SlicePat> for Pat {
|
|
fn from(node: SlicePat) -> Pat {
|
|
Pat::SlicePat(node)
|
|
}
|
|
}
|
|
impl From<RangePat> for Pat {
|
|
fn from(node: RangePat) -> Pat {
|
|
Pat::RangePat(node)
|
|
}
|
|
}
|
|
impl From<LiteralPat> for Pat {
|
|
fn from(node: LiteralPat) -> Pat {
|
|
Pat::LiteralPat(node)
|
|
}
|
|
}
|
|
impl From<MacroPat> for Pat {
|
|
fn from(node: MacroPat) -> Pat {
|
|
Pat::MacroPat(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for Pat {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Pat {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
|
|
| PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
|
|
| LITERAL_PAT | MACRO_PAT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
OR_PAT => Pat::OrPat(OrPat { syntax }),
|
|
PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
|
|
REF_PAT => Pat::RefPat(RefPat { syntax }),
|
|
BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
|
|
BIND_PAT => Pat::BindPat(BindPat { syntax }),
|
|
PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
|
|
DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
|
|
PATH_PAT => Pat::PathPat(PathPat { syntax }),
|
|
RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
|
|
TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
|
|
TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
|
|
SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
|
|
RANGE_PAT => Pat::RangePat(RangePat { syntax }),
|
|
LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
|
|
MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
Pat::OrPat(it) => &it.syntax,
|
|
Pat::ParenPat(it) => &it.syntax,
|
|
Pat::RefPat(it) => &it.syntax,
|
|
Pat::BoxPat(it) => &it.syntax,
|
|
Pat::BindPat(it) => &it.syntax,
|
|
Pat::PlaceholderPat(it) => &it.syntax,
|
|
Pat::DotDotPat(it) => &it.syntax,
|
|
Pat::PathPat(it) => &it.syntax,
|
|
Pat::RecordPat(it) => &it.syntax,
|
|
Pat::TupleStructPat(it) => &it.syntax,
|
|
Pat::TuplePat(it) => &it.syntax,
|
|
Pat::SlicePat(it) => &it.syntax,
|
|
Pat::RangePat(it) => &it.syntax,
|
|
Pat::LiteralPat(it) => &it.syntax,
|
|
Pat::MacroPat(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum AttrInput {
|
|
Literal(Literal),
|
|
TokenTree(TokenTree),
|
|
}
|
|
impl From<Literal> for AttrInput {
|
|
fn from(node: Literal) -> AttrInput {
|
|
AttrInput::Literal(node)
|
|
}
|
|
}
|
|
impl From<TokenTree> for AttrInput {
|
|
fn from(node: TokenTree) -> AttrInput {
|
|
AttrInput::TokenTree(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for AttrInput {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for AttrInput {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
LITERAL | TOKEN_TREE => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
LITERAL => AttrInput::Literal(Literal { syntax }),
|
|
TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
AttrInput::Literal(it) => &it.syntax,
|
|
AttrInput::TokenTree(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Stmt {
|
|
ExprStmt(ExprStmt),
|
|
LetStmt(LetStmt),
|
|
}
|
|
impl From<ExprStmt> for Stmt {
|
|
fn from(node: ExprStmt) -> Stmt {
|
|
Stmt::ExprStmt(node)
|
|
}
|
|
}
|
|
impl From<LetStmt> for Stmt {
|
|
fn from(node: LetStmt) -> Stmt {
|
|
Stmt::LetStmt(node)
|
|
}
|
|
}
|
|
impl std::fmt::Display for Stmt {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
std::fmt::Display::fmt(self.syntax(), f)
|
|
}
|
|
}
|
|
impl AstNode for Stmt {
|
|
fn can_cast(kind: SyntaxKind) -> bool {
|
|
match kind {
|
|
EXPR_STMT | LET_STMT => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|
let res = match syntax.kind() {
|
|
EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
|
|
LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
|
|
_ => return None,
|
|
};
|
|
Some(res)
|
|
}
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
match self {
|
|
Stmt::ExprStmt(it) => &it.syntax,
|
|
Stmt::LetStmt(it) => &it.syntax,
|
|
}
|
|
}
|
|
}
|