From 8c8d0bb34f5495e0f260b5aaf3685ecb98406f32 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 9 Feb 2020 18:57:01 +0000 Subject: Add or- and parenthesized-patterns --- crates/ra_syntax/src/ast/generated.rs | 81 ++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 435135f92..8d640642d 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1759,8 +1759,8 @@ impl AstNode for MatchArm { } impl ast::AttrsOwner for MatchArm {} impl MatchArm { - pub fn pats(&self) -> AstChildren { - AstChildren::new(&self.syntax) + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() } pub fn guard(&self) -> Option { AstChildren::new(&self.syntax).next() @@ -1887,6 +1887,60 @@ impl RecordField { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct OrPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for OrPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + OR_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl OrPat { + pub fn pats(&self) -> AstChildren { + AstChildren::new(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ParenPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ParenPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + PAREN_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl ParenPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RefPat { pub(crate) syntax: SyntaxNode, } @@ -3900,6 +3954,8 @@ impl AstNode for Expr { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { + OrPat(OrPat), + ParenPat(ParenPat), RefPat(RefPat), BoxPat(BoxPat), BindPat(BindPat), @@ -3913,6 +3969,16 @@ pub enum Pat { RangePat(RangePat), LiteralPat(LiteralPat), } +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: RefPat) -> Pat { Pat::RefPat(node) @@ -3976,15 +4042,16 @@ impl From for Pat { impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - 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 => { - true - } + 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 => 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 }), @@ -4003,6 +4070,8 @@ impl AstNode for Pat { } 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, -- cgit v1.2.3