From 572f1c08b6ba43bdd57c5cb99f79a08ecd821c1c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:49:26 +0200 Subject: [PATCH] Minor gramamr reorder --- crates/ra_syntax/src/ast/generated/nodes.rs | 921 ++++++++++---------- xtask/src/codegen/rust.ungram | 138 +-- 2 files changed, 529 insertions(+), 530 deletions(-) diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 6ce9c4adc5..66821a31c2 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -6,6 +6,20 @@ use crate::{ SyntaxNode, SyntaxToken, T, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Name { + pub(crate) syntax: SyntaxNode, +} +impl Name { + pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct NameRef { + pub(crate) syntax: SyntaxNode, +} +impl NameRef { + pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Path { pub(crate) syntax: SyntaxNode, } @@ -33,13 +47,6 @@ impl PathSegment { pub fn r_angle_token(&self) -> Option { support::token(&self.syntax, T![>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NameRef { - pub(crate) syntax: SyntaxNode, -} -impl NameRef { - pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct GenericArgList { pub(crate) syntax: SyntaxNode, } @@ -116,13 +123,16 @@ impl TypeBoundList { pub fn bounds(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SourceFile { +pub struct MacroCall { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for SourceFile {} -impl ast::ModuleItemOwner for SourceFile {} -impl SourceFile { - pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } +impl ast::AttrsOwner for MacroCall {} +impl ast::NameOwner for MacroCall {} +impl MacroCall { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn token_tree(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Attr { @@ -139,6 +149,41 @@ impl Attr { pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TokenTree { + pub(crate) syntax: SyntaxNode, +} +impl TokenTree { + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroItems { + pub(crate) syntax: SyntaxNode, +} +impl ast::ModuleItemOwner for MacroItems {} +impl MacroItems {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroStmts { + pub(crate) syntax: SyntaxNode, +} +impl MacroStmts { + pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SourceFile { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for SourceFile {} +impl ast::ModuleItemOwner for SourceFile {} +impl SourceFile { + pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Const { pub(crate) syntax: SyntaxNode, } @@ -228,18 +273,6 @@ impl Impl { pub fn assoc_item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroCall { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for MacroCall {} -impl ast::NameOwner for MacroCall {} -impl MacroCall { - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } - pub fn token_tree(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Module { pub(crate) syntax: SyntaxNode, } @@ -349,13 +382,6 @@ impl Visibility { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Name { - pub(crate) syntax: SyntaxNode, -} -impl Name { - pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ItemList { pub(crate) syntax: SyntaxNode, } @@ -589,18 +615,6 @@ pub struct Literal { impl ast::AttrsOwner for Literal {} impl Literal {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TokenTree { - pub(crate) syntax: SyntaxNode, -} -impl TokenTree { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExprStmt { pub(crate) syntax: SyntaxNode, } @@ -1097,39 +1111,6 @@ impl TypeBound { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct OrPat { - pub(crate) syntax: SyntaxNode, -} -impl OrPat { - pub fn pats(&self) -> AstChildren { support::children(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ParenPat { - pub(crate) syntax: SyntaxNode, -} -impl ParenPat { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn pat(&self) -> Option { support::child(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RefPat { - pub(crate) syntax: SyntaxNode, -} -impl RefPat { - pub fn amp_token(&self) -> Option { support::token(&self.syntax, T![&]) } - pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } - pub fn pat(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BoxPat { - pub(crate) syntax: SyntaxNode, -} -impl BoxPat { - pub fn box_token(&self) -> Option { support::token(&self.syntax, T![box]) } - pub fn path(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BindPat { pub(crate) syntax: SyntaxNode, } @@ -1142,11 +1123,12 @@ impl BindPat { pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PlaceholderPat { +pub struct BoxPat { pub(crate) syntax: SyntaxNode, } -impl PlaceholderPat { - pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } +impl BoxPat { + pub fn box_token(&self) -> Option { support::token(&self.syntax, T![box]) } + pub fn path(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DotDotPat { @@ -1156,30 +1138,6 @@ impl DotDotPat { pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathPat { - pub(crate) syntax: SyntaxNode, -} -impl PathPat { - pub fn path(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SlicePat { - pub(crate) syntax: SyntaxNode, -} -impl SlicePat { - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } - pub fn args(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RangePat { - pub(crate) syntax: SyntaxNode, -} -impl RangePat { - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } - pub fn dotdoteq_token(&self) -> Option { support::token(&self.syntax, T![..=]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LiteralPat { pub(crate) syntax: SyntaxNode, } @@ -1194,6 +1152,41 @@ impl MacroPat { pub fn macro_call(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct OrPat { + pub(crate) syntax: SyntaxNode, +} +impl OrPat { + pub fn pats(&self) -> AstChildren { support::children(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ParenPat { + pub(crate) syntax: SyntaxNode, +} +impl ParenPat { + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PathPat { + pub(crate) syntax: SyntaxNode, +} +impl PathPat { + pub fn path(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct PlaceholderPat { + pub(crate) syntax: SyntaxNode, +} +impl PlaceholderPat { + pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RangePat { + pub(crate) syntax: SyntaxNode, +} +impl RangePat {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordPat { pub(crate) syntax: SyntaxNode, } @@ -1204,6 +1197,43 @@ impl RecordPat { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RefPat { + pub(crate) syntax: SyntaxNode, +} +impl RefPat { + pub fn amp_token(&self) -> Option { support::token(&self.syntax, T![&]) } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SlicePat { + pub(crate) syntax: SyntaxNode, +} +impl SlicePat { + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } + pub fn args(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TuplePat { + pub(crate) syntax: SyntaxNode, +} +impl TuplePat { + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn args(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TupleStructPat { + pub(crate) syntax: SyntaxNode, +} +impl TupleStructPat { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn args(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordFieldPatList { pub(crate) syntax: SyntaxNode, } @@ -1227,39 +1257,6 @@ impl RecordFieldPat { pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleStructPat { - pub(crate) syntax: SyntaxNode, -} -impl TupleStructPat { - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn args(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TuplePat { - pub(crate) syntax: SyntaxNode, -} -impl TuplePat { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn args(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroItems { - pub(crate) syntax: SyntaxNode, -} -impl ast::ModuleItemOwner for MacroItems {} -impl MacroItems {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroStmts { - pub(crate) syntax: SyntaxNode, -} -impl MacroStmts { - pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum GenericArg { TypeArg(TypeArg), AssocTypeArg(AssocTypeArg), @@ -1334,22 +1331,28 @@ pub enum Item { } impl ast::AttrsOwner for Item {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Stmt { + ExprStmt(ExprStmt), + Item(Item), + LetStmt(LetStmt), +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { - OrPat(OrPat), - ParenPat(ParenPat), - RefPat(RefPat), - BoxPat(BoxPat), BindPat(BindPat), - PlaceholderPat(PlaceholderPat), + BoxPat(BoxPat), DotDotPat(DotDotPat), - PathPat(PathPat), - RecordPat(RecordPat), - TupleStructPat(TupleStructPat), - TuplePat(TuplePat), - SlicePat(SlicePat), - RangePat(RangePat), LiteralPat(LiteralPat), MacroPat(MacroPat), + OrPat(OrPat), + ParenPat(ParenPat), + PathPat(PathPat), + PlaceholderPat(PlaceholderPat), + RangePat(RangePat), + RecordPat(RecordPat), + RefPat(RefPat), + SlicePat(SlicePat), + TuplePat(TuplePat), + TupleStructPat(TupleStructPat), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum FieldList { @@ -1390,11 +1393,27 @@ pub enum GenericParam { TypeParam(TypeParam), } impl ast::AttrsOwner for GenericParam {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Stmt { - ExprStmt(ExprStmt), - Item(Item), - LetStmt(LetStmt), +impl AstNode for Name { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for NameRef { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl AstNode for Path { fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } @@ -1418,17 +1437,6 @@ impl AstNode for PathSegment { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for NameRef { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for GenericArgList { fn can_cast(kind: SyntaxKind) -> bool { kind == GENERIC_ARG_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -1528,8 +1536,8 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for SourceFile { - fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } +impl AstNode for MacroCall { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1550,6 +1558,50 @@ impl AstNode for Attr { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for TokenTree { + fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for MacroItems { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for MacroStmts { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for SourceFile { + fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for Const { fn can_cast(kind: SyntaxKind) -> bool { kind == CONST } fn cast(syntax: SyntaxNode) -> Option { @@ -1616,17 +1668,6 @@ impl AstNode for Impl { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroCall { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for Module { fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } fn cast(syntax: SyntaxNode) -> Option { @@ -1715,17 +1756,6 @@ impl AstNode for Visibility { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Name { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for ItemList { fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -1979,17 +2009,6 @@ impl AstNode for Literal { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TokenTree { - fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for ExprStmt { fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } fn cast(syntax: SyntaxNode) -> Option { @@ -2540,30 +2559,8 @@ impl AstNode for TypeBound { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for OrPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == OR_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for ParenPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for RefPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == REF_PAT } +impl AstNode for BindPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2584,28 +2581,6 @@ impl AstNode for BoxPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for BindPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for PlaceholderPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for DotDotPat { fn can_cast(kind: SyntaxKind) -> bool { kind == DOT_DOT_PAT } fn cast(syntax: SyntaxNode) -> Option { @@ -2617,39 +2592,6 @@ impl AstNode for DotDotPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for PathPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for SlicePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for RangePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for LiteralPat { fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL_PAT } fn cast(syntax: SyntaxNode) -> Option { @@ -2672,6 +2614,61 @@ impl AstNode for MacroPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for OrPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == OR_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for ParenPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for PathPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for PlaceholderPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for RangePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for RecordPat { fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } fn cast(syntax: SyntaxNode) -> Option { @@ -2683,6 +2680,50 @@ impl AstNode for RecordPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for RefPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == REF_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for SlicePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for TuplePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for TupleStructPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_STRUCT_PAT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for RecordFieldPatList { fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -2705,50 +2746,6 @@ impl AstNode for RecordFieldPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TupleStructPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_STRUCT_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for TuplePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for MacroItems { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for MacroStmts { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl From for GenericArg { fn from(node: TypeArg) -> GenericArg { GenericArg::TypeArg(node) } } @@ -3133,98 +3130,107 @@ impl AstNode for Item { } } } -impl From for Pat { - fn from(node: OrPat) -> Pat { Pat::OrPat(node) } +impl From for Stmt { + fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } } -impl From for Pat { - fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } +impl From for Stmt { + fn from(node: Item) -> Stmt { Stmt::Item(node) } } -impl From for Pat { - fn from(node: RefPat) -> Pat { Pat::RefPat(node) } -} -impl From for Pat { - fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } +impl From for Stmt { + fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } } impl From for Pat { fn from(node: BindPat) -> Pat { Pat::BindPat(node) } } -impl From for Pat { - fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +impl From for Pat { + fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } } impl From for Pat { fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) } } -impl From for Pat { - fn from(node: PathPat) -> Pat { Pat::PathPat(node) } -} -impl From for Pat { - fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } -} -impl From for Pat { - fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } -} -impl From for Pat { - fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } -} -impl From for Pat { - fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } -} -impl From for Pat { - fn from(node: RangePat) -> Pat { Pat::RangePat(node) } -} impl From for Pat { fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } } impl From for Pat { fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } } +impl From for Pat { + fn from(node: OrPat) -> Pat { Pat::OrPat(node) } +} +impl From for Pat { + fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } +} +impl From for Pat { + fn from(node: PathPat) -> Pat { Pat::PathPat(node) } +} +impl From for Pat { + fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +} +impl From for Pat { + fn from(node: RangePat) -> Pat { Pat::RangePat(node) } +} +impl From for Pat { + fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } +} +impl From for Pat { + fn from(node: RefPat) -> Pat { Pat::RefPat(node) } +} +impl From for Pat { + fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } +} +impl From for Pat { + fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } +} +impl From for Pat { + fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } +} impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT - | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT - | LITERAL_PAT | MACRO_PAT => true, + BIND_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT + | PATH_PAT | PLACEHOLDER_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT + | TUPLE_PAT | TUPLE_STRUCT_PAT => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - OR_PAT => Pat::OrPat(OrPat { syntax }), - PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), - REF_PAT => Pat::RefPat(RefPat { syntax }), - BOX_PAT => Pat::BoxPat(BoxPat { syntax }), BIND_PAT => Pat::BindPat(BindPat { syntax }), - PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + BOX_PAT => Pat::BoxPat(BoxPat { 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 }), + OR_PAT => Pat::OrPat(OrPat { syntax }), + PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), + PATH_PAT => Pat::PathPat(PathPat { syntax }), + PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + RANGE_PAT => Pat::RangePat(RangePat { syntax }), + RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), + REF_PAT => Pat::RefPat(RefPat { syntax }), + SLICE_PAT => Pat::SlicePat(SlicePat { syntax }), + TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), + TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { 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::BoxPat(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, + Pat::OrPat(it) => &it.syntax, + Pat::ParenPat(it) => &it.syntax, + Pat::PathPat(it) => &it.syntax, + Pat::PlaceholderPat(it) => &it.syntax, + Pat::RangePat(it) => &it.syntax, + Pat::RecordPat(it) => &it.syntax, + Pat::RefPat(it) => &it.syntax, + Pat::SlicePat(it) => &it.syntax, + Pat::TuplePat(it) => &it.syntax, + Pat::TupleStructPat(it) => &it.syntax, } } } @@ -3393,15 +3399,6 @@ impl AstNode for GenericParam { } } } -impl From for Stmt { - fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } -} -impl From for Stmt { - fn from(node: Item) -> Stmt { Stmt::Item(node) } -} -impl From for Stmt { - fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } -} impl std::fmt::Display for GenericArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3422,6 +3419,11 @@ impl std::fmt::Display for Item { std::fmt::Display::fmt(self.syntax(), f) } } +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 std::fmt::Display for Pat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3452,7 +3454,12 @@ impl std::fmt::Display for GenericParam { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Stmt { +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 std::fmt::Display for NameRef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3467,11 +3474,6 @@ impl std::fmt::Display for PathSegment { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for GenericArgList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3517,7 +3519,7 @@ impl std::fmt::Display for TypeBoundList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for SourceFile { +impl std::fmt::Display for MacroCall { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3527,6 +3529,26 @@ impl std::fmt::Display for Attr { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for TokenTree { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +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 std::fmt::Display for MacroStmts { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for SourceFile { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Const { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3557,11 +3579,6 @@ impl std::fmt::Display for Impl { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for Module { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3602,11 +3619,6 @@ impl std::fmt::Display for Visibility { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for ItemList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3722,11 +3734,6 @@ impl std::fmt::Display for Literal { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TokenTree { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for ExprStmt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3977,17 +3984,7 @@ impl std::fmt::Display for TypeBound { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for ParenPat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for RefPat { +impl std::fmt::Display for BindPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3997,36 +3994,11 @@ impl std::fmt::Display for BoxPat { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for PlaceholderPat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} 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 std::fmt::Display for PathPat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -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 std::fmt::Display for RangePat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for LiteralPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4037,11 +4009,56 @@ impl std::fmt::Display for MacroPat { std::fmt::Display::fmt(self.syntax(), f) } } +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 std::fmt::Display for ParenPat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +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 std::fmt::Display for PlaceholderPat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +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 std::fmt::Display for RecordPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } +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 std::fmt::Display for SlicePat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +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 std::fmt::Display for TupleStructPat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for RecordFieldPatList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4052,23 +4069,3 @@ impl std::fmt::Display for RecordFieldPat { std::fmt::Display::fmt(self.syntax(), f) } } -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 std::fmt::Display for TuplePat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -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 std::fmt::Display for MacroStmts { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 2e3b45011b..27bf563b65 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -1,3 +1,9 @@ +Name = + 'ident' + +NameRef = + 'ident' | 'int_number' + Path = (qualifier:Path '::')? segment:PathSegment @@ -29,6 +35,21 @@ LifetimeArg = ConstArg = Expr +MacroCall = + Attr* Path '!' Name? TokenTree ';'? + +TokenTree = + '(' ')' +| '{' '}' +| '[' ']' + +MacroItems = + Item* + +MacroStmts = + statements:Stmt* + Expr? + SourceFile = 'shebang'? Attr* @@ -475,41 +496,37 @@ TypeBound = 'lifetime' | '?'? Type -OrPat = - Pat* - -ParenPat = - '(' Pat ')' - -RefPat = - '&' 'mut'? Pat - -BoxPat = - 'box' Path - -BindPat = - Attr* 'ref'? 'mut'? Name ('@' Pat)? - -PlaceholderPat = - '_' - -DotDotPat = - '..' - -PathPat = - Path - -SlicePat = - '[' args:Pat* ']' - -RangePat = - '..' | '..=' +Pat = + BindPat +| BoxPat +| DotDotPat +| LiteralPat +| MacroPat +| OrPat +| ParenPat +| PathPat +| PlaceholderPat +| RangePat +| RecordPat +| RefPat +| SlicePat +| TuplePat +| TupleStructPat LiteralPat = Literal -MacroPat = - MacroCall +PathPat = + Path + +PlaceholderPat = + '_' + +RangePat = + start:Pat op:('..' | '..=') end:Pat + +RefPat = + '&' 'mut'? Pat RecordPat = Path RecordFieldPatList @@ -522,46 +539,31 @@ RecordFieldPatList = '}' RecordFieldPat = - Attr* NameRef ':' Pat + Attr* (NameRef ':')? Pat + +OrPat = + Pat* + +ParenPat = + '(' Pat ')' + +BoxPat = + 'box' Path + +BindPat = + Attr* 'ref'? 'mut'? Name ('@' Pat)? + +DotDotPat = + '..' + +SlicePat = + '[' args:Pat* ']' + +MacroPat = + MacroCall TupleStructPat = Path '(' args:Pat* ')' TuplePat = '(' args:Pat* ')' - -Name = - 'ident' - -NameRef = - 'ident' | 'int_number' - -MacroCall = - Attr* Path '!' Name? TokenTree ';'? - -TokenTree = - '(' ')' | '{' '}' | '[' ']' - -MacroItems = - Item* - -MacroStmts = - statements:Stmt* - Expr? - -Pat = - OrPat -| ParenPat -| RefPat -| BoxPat -| BindPat -| PlaceholderPat -| DotDotPat -| PathPat -| RecordPat -| TupleStructPat -| TuplePat -| SlicePat -| RangePat -| LiteralPat -| MacroPat