aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-25 10:47:44 +0100
committerGitHub <[email protected]>2019-08-25 10:47:44 +0100
commit866b41ddd86cbe9c3e8d9cb2896477bab060a044 (patch)
tree2108601228076d62e833b732de52e182b8be4a0b /crates/ra_syntax/src
parentfdece911fe8e2f3c22760ea22038a6d00cb70dfa (diff)
parentc93903e9c7f64be2edcae0dfe62d8390514658b1 (diff)
Merge #1733
1733: Parse arbitrarily complex `box` patterns. r=matklad a=ecstatic-morse This fully resolves the pattern part of #1412 by enabling the parsing of complex `box` patterns such as: ```rust let box Struct { box i, j: box Inner(box &x) } = todo!(); ``` This introduces a new `ast::BoxPat` (in the mold of `ast::RefPat`) that gets translated to `hir::Pat::Missing`. Co-authored-by: Dylan MacKenzie <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs39
-rw-r--r--crates/ra_syntax/src/grammar.ron3
2 files changed, 40 insertions, 2 deletions
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 {
307 } 307 }
308} 308}
309#[derive(Debug, Clone, PartialEq, Eq, Hash)] 309#[derive(Debug, Clone, PartialEq, Eq, Hash)]
310pub struct BoxPat {
311 pub(crate) syntax: SyntaxNode,
312}
313impl AstNode for BoxPat {
314 fn can_cast(kind: SyntaxKind) -> bool {
315 match kind {
316 BOX_PAT => true,
317 _ => false,
318 }
319 }
320 fn cast(syntax: SyntaxNode) -> Option<Self> {
321 if Self::can_cast(syntax.kind()) {
322 Some(Self { syntax })
323 } else {
324 None
325 }
326 }
327 fn syntax(&self) -> &SyntaxNode {
328 &self.syntax
329 }
330}
331impl BoxPat {
332 pub fn pat(&self) -> Option<Pat> {
333 AstChildren::new(&self.syntax).next()
334 }
335}
336#[derive(Debug, Clone, PartialEq, Eq, Hash)]
310pub struct BreakExpr { 337pub struct BreakExpr {
311 pub(crate) syntax: SyntaxNode, 338 pub(crate) syntax: SyntaxNode,
312} 339}
@@ -2063,6 +2090,7 @@ impl ParenType {
2063#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2090#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2064pub enum Pat { 2091pub enum Pat {
2065 RefPat(RefPat), 2092 RefPat(RefPat),
2093 BoxPat(BoxPat),
2066 BindPat(BindPat), 2094 BindPat(BindPat),
2067 PlaceholderPat(PlaceholderPat), 2095 PlaceholderPat(PlaceholderPat),
2068 PathPat(PathPat), 2096 PathPat(PathPat),
@@ -2078,6 +2106,11 @@ impl From<RefPat> for Pat {
2078 Pat::RefPat(node) 2106 Pat::RefPat(node)
2079 } 2107 }
2080} 2108}
2109impl From<BoxPat> for Pat {
2110 fn from(node: BoxPat) -> Pat {
2111 Pat::BoxPat(node)
2112 }
2113}
2081impl From<BindPat> for Pat { 2114impl From<BindPat> for Pat {
2082 fn from(node: BindPat) -> Pat { 2115 fn from(node: BindPat) -> Pat {
2083 Pat::BindPat(node) 2116 Pat::BindPat(node)
@@ -2126,14 +2159,15 @@ impl From<LiteralPat> for Pat {
2126impl AstNode for Pat { 2159impl AstNode for Pat {
2127 fn can_cast(kind: SyntaxKind) -> bool { 2160 fn can_cast(kind: SyntaxKind) -> bool {
2128 match kind { 2161 match kind {
2129 REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT 2162 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT
2130 | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, 2163 | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2131 _ => false, 2164 _ => false,
2132 } 2165 }
2133 } 2166 }
2134 fn cast(syntax: SyntaxNode) -> Option<Self> { 2167 fn cast(syntax: SyntaxNode) -> Option<Self> {
2135 let res = match syntax.kind() { 2168 let res = match syntax.kind() {
2136 REF_PAT => Pat::RefPat(RefPat { syntax }), 2169 REF_PAT => Pat::RefPat(RefPat { syntax }),
2170 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2137 BIND_PAT => Pat::BindPat(BindPat { syntax }), 2171 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2138 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), 2172 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2139 PATH_PAT => Pat::PathPat(PathPat { syntax }), 2173 PATH_PAT => Pat::PathPat(PathPat { syntax }),
@@ -2150,6 +2184,7 @@ impl AstNode for Pat {
2150 fn syntax(&self) -> &SyntaxNode { 2184 fn syntax(&self) -> &SyntaxNode {
2151 match self { 2185 match self {
2152 Pat::RefPat(it) => &it.syntax, 2186 Pat::RefPat(it) => &it.syntax,
2187 Pat::BoxPat(it) => &it.syntax,
2153 Pat::BindPat(it) => &it.syntax, 2188 Pat::BindPat(it) => &it.syntax,
2154 Pat::PlaceholderPat(it) => &it.syntax, 2189 Pat::PlaceholderPat(it) => &it.syntax,
2155 Pat::PathPat(it) => &it.syntax, 2190 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(
158 "DYN_TRAIT_TYPE", 158 "DYN_TRAIT_TYPE",
159 159
160 "REF_PAT", 160 "REF_PAT",
161 "BOX_PAT",
161 "BIND_PAT", 162 "BIND_PAT",
162 "PLACEHOLDER_PAT", 163 "PLACEHOLDER_PAT",
163 "PATH_PAT", 164 "PATH_PAT",
@@ -523,6 +524,7 @@ Grammar(
523 ), 524 ),
524 525
525 "RefPat": ( options: [ "Pat" ]), 526 "RefPat": ( options: [ "Pat" ]),
527 "BoxPat": ( options: [ "Pat" ]),
526 "BindPat": ( 528 "BindPat": (
527 options: [ "Pat" ], 529 options: [ "Pat" ],
528 traits: ["NameOwner"] 530 traits: ["NameOwner"]
@@ -552,6 +554,7 @@ Grammar(
552 "Pat": ( 554 "Pat": (
553 enum: [ 555 enum: [
554 "RefPat", 556 "RefPat",
557 "BoxPat",
555 "BindPat", 558 "BindPat",
556 "PlaceholderPat", 559 "PlaceholderPat",
557 "PathPat", 560 "PathPat",