From e6f3790106fdfa2aaf6a0510c737fd05939345e7 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 23 Aug 2019 13:04:58 -0700 Subject: Add `BoxPat` variant --- crates/ra_parser/src/syntax_kind/generated.rs | 1 + crates/ra_syntax/src/ast/generated.rs | 39 +++++++++++++++++++++++++-- crates/ra_syntax/src/grammar.ron | 3 +++ 3 files changed, 41 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index f15e98e68..8ba29ebf8 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -149,6 +149,7 @@ pub enum SyntaxKind { IMPL_TRAIT_TYPE, DYN_TRAIT_TYPE, REF_PAT, + BOX_PAT, BIND_PAT, PLACEHOLDER_PAT, PATH_PAT, diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 07cc3e0db..90480b6ca 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -307,6 +307,33 @@ impl BlockExpr { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BoxPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for BoxPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + BOX_PAT => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl BoxPat { + pub fn pat(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BreakExpr { pub(crate) syntax: SyntaxNode, } @@ -2063,6 +2090,7 @@ impl ParenType { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { RefPat(RefPat), + BoxPat(BoxPat), BindPat(BindPat), PlaceholderPat(PlaceholderPat), PathPat(PathPat), @@ -2078,6 +2106,11 @@ impl From for Pat { Pat::RefPat(node) } } +impl From for Pat { + fn from(node: BoxPat) -> Pat { + Pat::BoxPat(node) + } +} impl From for Pat { fn from(node: BindPat) -> Pat { Pat::BindPat(node) @@ -2126,14 +2159,15 @@ impl From for Pat { impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT - | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, + REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_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() { REF_PAT => Pat::RefPat(RefPat { syntax }), + BOX_PAT => Pat::BoxPat(BoxPat { syntax }), BIND_PAT => Pat::BindPat(BindPat { syntax }), PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), PATH_PAT => Pat::PathPat(PathPat { syntax }), @@ -2150,6 +2184,7 @@ impl AstNode for Pat { fn syntax(&self) -> &SyntaxNode { match self { Pat::RefPat(it) => &it.syntax, + Pat::BoxPat(it) => &it.syntax, Pat::BindPat(it) => &it.syntax, Pat::PlaceholderPat(it) => &it.syntax, Pat::PathPat(it) => &it.syntax, diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 4659192cd..1836862fe 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -158,6 +158,7 @@ Grammar( "DYN_TRAIT_TYPE", "REF_PAT", + "BOX_PAT", "BIND_PAT", "PLACEHOLDER_PAT", "PATH_PAT", @@ -523,6 +524,7 @@ Grammar( ), "RefPat": ( options: [ "Pat" ]), + "BoxPat": ( options: [ "Pat" ]), "BindPat": ( options: [ "Pat" ], traits: ["NameOwner"] @@ -552,6 +554,7 @@ Grammar( "Pat": ( enum: [ "RefPat", + "BoxPat", "BindPat", "PlaceholderPat", "PathPat", -- cgit v1.2.3