aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs14
-rw-r--r--crates/ra_syntax/src/ast/generated.rs2
-rw-r--r--crates/ra_syntax/src/grammar.ron4
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs28
-rw-r--r--crates/ra_syntax/src/syntax_node/syntax_error.rs4
5 files changed, 51 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 22105d6c9..350f01f33 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -153,6 +153,20 @@ impl FnDef {
153} 153}
154 154
155impl Attr { 155impl Attr {
156 pub fn is_inner(&self) -> bool {
157 let tt = match self.value() {
158 None => return false,
159 Some(tt) => tt,
160 };
161
162 let prev = match tt.syntax().prev_sibling() {
163 None => return false,
164 Some(prev) => prev,
165 };
166
167 prev.kind() == EXCL
168 }
169
156 pub fn as_atom(&self) -> Option<SmolStr> { 170 pub fn as_atom(&self) -> Option<SmolStr> {
157 let tt = self.value()?; 171 let tt = self.value()?;
158 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; 172 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index dd91b5063..c7aaccc95 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1946,6 +1946,7 @@ impl ToOwned for MatchArm {
1946} 1946}
1947 1947
1948 1948
1949impl ast::AttrsOwner for MatchArm {}
1949impl MatchArm { 1950impl MatchArm {
1950 pub fn pats(&self) -> impl Iterator<Item = &Pat> { 1951 pub fn pats(&self) -> impl Iterator<Item = &Pat> {
1951 super::children(self) 1952 super::children(self)
@@ -1986,6 +1987,7 @@ impl ToOwned for MatchArmList {
1986} 1987}
1987 1988
1988 1989
1990impl ast::AttrsOwner for MatchArmList {}
1989impl MatchArmList { 1991impl MatchArmList {
1990 pub fn arms(&self) -> impl Iterator<Item = &MatchArm> { 1992 pub fn arms(&self) -> impl Iterator<Item = &MatchArm> {
1991 super::children(self) 1993 super::children(self)
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 27a123681..193b563aa 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -413,13 +413,15 @@ Grammar(
413 ), 413 ),
414 "MatchArmList": ( 414 "MatchArmList": (
415 collections: [ ["arms", "MatchArm"] ], 415 collections: [ ["arms", "MatchArm"] ],
416 traits: [ "AttrsOwner" ]
416 ), 417 ),
417 "MatchArm": ( 418 "MatchArm": (
418 options: [ 419 options: [
419 [ "guard", "MatchGuard" ], 420 [ "guard", "MatchGuard" ],
420 "Expr", 421 "Expr",
421 ], 422 ],
422 collections: [ [ "pats", "Pat" ] ] 423 collections: [ [ "pats", "Pat" ] ],
424 traits: [ "AttrsOwner" ]
423 ), 425 ),
424 "MatchGuard": (options: ["Expr"]), 426 "MatchGuard": (options: ["Expr"]),
425 "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]), 427 "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index 27ba87657..e74305b6a 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -313,11 +313,39 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
313 assert!(p.at(L_CURLY)); 313 assert!(p.at(L_CURLY));
314 let m = p.start(); 314 let m = p.start();
315 p.eat(L_CURLY); 315 p.eat(L_CURLY);
316
317 // test match_arms_inner_attribute
318 // fn foo() {
319 // match () {
320 // #![doc("Inner attribute")]
321 // #![doc("Can be")]
322 // #![doc("Stacked")]
323 // _ => (),
324 // }
325 // }
326 attributes::inner_attributes(p);
327
316 while !p.at(EOF) && !p.at(R_CURLY) { 328 while !p.at(EOF) && !p.at(R_CURLY) {
317 if p.at(L_CURLY) { 329 if p.at(L_CURLY) {
318 error_block(p, "expected match arm"); 330 error_block(p, "expected match arm");
319 continue; 331 continue;
320 } 332 }
333
334 // test match_arms_outer_attributes
335 // fn foo() {
336 // match () {
337 // #[cfg(feature = "some")]
338 // _ => (),
339 // #[cfg(feature = "other")]
340 // _ => (),
341 // #[cfg(feature = "many")]
342 // #[cfg(feature = "attributes")]
343 // #[cfg(feature = "before")]
344 // _ => (),
345 // }
346 // }
347 attributes::outer_attributes(p);
348
321 // test match_arms_commas 349 // test match_arms_commas
322 // fn foo() { 350 // fn foo() {
323 // match () { 351 // match () {
diff --git a/crates/ra_syntax/src/syntax_node/syntax_error.rs b/crates/ra_syntax/src/syntax_node/syntax_error.rs
index 412cf82cc..4ff998090 100644
--- a/crates/ra_syntax/src/syntax_node/syntax_error.rs
+++ b/crates/ra_syntax/src/syntax_node/syntax_error.rs
@@ -92,6 +92,7 @@ pub enum SyntaxErrorKind {
92 UnclosedString, 92 UnclosedString,
93 InvalidSuffix, 93 InvalidSuffix,
94 InvalidBlockAttr, 94 InvalidBlockAttr,
95 InvalidMatchInnerAttr,
95} 96}
96 97
97#[derive(Debug, Clone, PartialEq, Eq, Hash)] 98#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -136,6 +137,9 @@ impl fmt::Display for SyntaxErrorKind {
136 InvalidBlockAttr => { 137 InvalidBlockAttr => {
137 write!(f, "A block in this position cannot accept inner attributes") 138 write!(f, "A block in this position cannot accept inner attributes")
138 } 139 }
140 InvalidMatchInnerAttr => {
141 write!(f, "Inner attributes are only allowed directly after the opening brace of the match expression")
142 }
139 ParseError(msg) => write!(f, "{}", msg.0), 143 ParseError(msg) => write!(f, "{}", msg.0),
140 } 144 }
141 } 145 }