aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/validation
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-17 17:08:34 +0000
committerVille Penttinen <[email protected]>2019-02-17 17:26:57 +0000
commit1c97c1ac11459d45f7bfc57dc72428d2b294520c (patch)
tree70638cabf61f96a7511f974cc66dae40175bfb22 /crates/ra_syntax/src/validation
parent982f72c022b45629e6adbaef22884359d3495ecf (diff)
Enable parsing of attributes inside a match block
We allow invalid inner attributes to be parsed, e.g. inner attributes that are not directly after the opening brace of the match block. Instead we run validation on `MatchArmList` to allow better reporting of errors.
Diffstat (limited to 'crates/ra_syntax/src/validation')
-rw-r--r--crates/ra_syntax/src/validation/match_armlist.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/validation/match_armlist.rs b/crates/ra_syntax/src/validation/match_armlist.rs
new file mode 100644
index 000000000..c43ed7092
--- /dev/null
+++ b/crates/ra_syntax/src/validation/match_armlist.rs
@@ -0,0 +1,28 @@
1use crate::{
2 ast::{self, AttrsOwner, AstNode},
3 syntax_node::{
4 SyntaxError,
5 SyntaxErrorKind::*,
6 Direction,
7 },
8};
9
10pub(crate) fn validate_match_armlist(node: &ast::MatchArmList, errors: &mut Vec<SyntaxError>) {
11 // Report errors for any inner attribute
12 // which has a preceding matcharm or an outer attribute
13 for inner_attr in node.attrs().filter(|s| s.is_inner()) {
14 let any_errors = inner_attr.syntax().siblings(Direction::Prev).any(|s| {
15 match (ast::MatchArm::cast(s), ast::Attr::cast(s)) {
16 (Some(_), _) => true,
17 // Outer attributes which preceed an inner attribute are not allowed
18 (_, Some(a)) if !a.is_inner() => true,
19 (_, Some(_)) => false,
20 (None, None) => false,
21 }
22 });
23
24 if any_errors {
25 errors.push(SyntaxError::new(InvalidMatchInnerAttr, inner_attr.syntax().range()));
26 }
27 }
28}