From 426112c97e587dfdaa79bcec0d4a37bef3c6b474 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 14 Sep 2019 17:05:12 -0700 Subject: Add `DotDotPat` to AST This is modeled on `PlaceholderPat`. --- crates/ra_syntax/src/ast/generated.rs | 37 +++++++++++++++++++++++++++++++++-- crates/ra_syntax/src/grammar.ron | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index a8a231ef3..591ac8ca3 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -532,6 +532,29 @@ impl AstNode for ContinueExpr { } impl ContinueExpr {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct DotDotPat { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for DotDotPat { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + DOT_DOT_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 DotDotPat {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DynTraitType { pub(crate) syntax: SyntaxNode, } @@ -2128,6 +2151,7 @@ pub enum Pat { BoxPat(BoxPat), BindPat(BindPat), PlaceholderPat(PlaceholderPat), + DotDotPat(DotDotPat), PathPat(PathPat), RecordPat(RecordPat), TupleStructPat(TupleStructPat), @@ -2156,6 +2180,11 @@ impl From for Pat { Pat::PlaceholderPat(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) @@ -2194,8 +2223,10 @@ impl From for Pat { impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - REF_PAT | BOX_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 | DOT_DOT_PAT | PATH_PAT + | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => { + true + } _ => false, } } @@ -2205,6 +2236,7 @@ impl AstNode for Pat { 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 }), @@ -2222,6 +2254,7 @@ impl AstNode for Pat { 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, diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 8f064711d..08cc6eeea 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -161,6 +161,7 @@ Grammar( "BOX_PAT", "BIND_PAT", "PLACEHOLDER_PAT", + "DOT_DOT_PAT", "PATH_PAT", "RECORD_PAT", "RECORD_FIELD_PAT_LIST", @@ -532,6 +533,7 @@ Grammar( traits: ["NameOwner"] ), "PlaceholderPat": (), + "DotDotPat": (), "PathPat": ( options: [ "Path" ] ), "RecordPat": ( options: ["RecordFieldPatList", "Path"] ), "RecordFieldPatList": ( @@ -559,6 +561,7 @@ Grammar( "BoxPat", "BindPat", "PlaceholderPat", + "DotDotPat", "PathPat", "RecordPat", "TupleStructPat", -- cgit v1.2.3