aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-02 17:33:02 +0100
committerAleksey Kladov <[email protected]>2019-09-02 18:15:51 +0100
commit3c2dea7f55830ba2391e5eb8525cdbb43ac666c2 (patch)
tree4856efbfaf1b52e441bd7bd8a5f6a26e454edb07 /crates
parenta8397deab914240aca8f015fb3736689919c0a5b (diff)
always wrap block into an expression
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_parser/src/grammar.rs2
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs5
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs4
-rw-r--r--crates/ra_syntax/src/validation.rs2
-rw-r--r--crates/ra_syntax/src/validation/block.rs20
5 files changed, 19 insertions, 14 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index d0f0dd4ac..be9419e0c 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -144,7 +144,7 @@ pub(crate) fn reparser(
144 parent: Option<SyntaxKind>, 144 parent: Option<SyntaxKind>,
145) -> Option<fn(&mut Parser)> { 145) -> Option<fn(&mut Parser)> {
146 let res = match node { 146 let res = match node {
147 BLOCK => expressions::block, 147 BLOCK => expressions::naked_block,
148 RECORD_FIELD_DEF_LIST => items::record_field_def_list, 148 RECORD_FIELD_DEF_LIST => items::record_field_def_list,
149 RECORD_FIELD_LIST => items::record_field_list, 149 RECORD_FIELD_LIST => items::record_field_list,
150 ENUM_VARIANT_LIST => items::enum_variant_list, 150 ENUM_VARIANT_LIST => items::enum_variant_list,
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 783d6a6f0..ba8386d11 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -40,6 +40,11 @@ pub(crate) fn block(p: &mut Parser) {
40 p.error("expected a block"); 40 p.error("expected a block");
41 return; 41 return;
42 } 42 }
43 atom::block_expr(p, None);
44}
45
46pub(crate) fn naked_block(p: &mut Parser) {
47 assert!(p.at(T!['{']));
43 let m = p.start(); 48 let m = p.start();
44 p.bump(); 49 p.bump();
45 expr_block_contents(p); 50 expr_block_contents(p);
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index bc942ae01..ec7f2441d 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -463,10 +463,10 @@ fn match_guard(p: &mut Parser) -> CompletedMarker {
463// unsafe {}; 463// unsafe {};
464// 'label: {}; 464// 'label: {};
465// } 465// }
466fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 466pub(super) fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
467 assert!(p.at(T!['{'])); 467 assert!(p.at(T!['{']));
468 let m = m.unwrap_or_else(|| p.start()); 468 let m = m.unwrap_or_else(|| p.start());
469 block(p); 469 naked_block(p);
470 m.complete(p, BLOCK_EXPR) 470 m.complete(p, BLOCK_EXPR)
471} 471}
472 472
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index ee8797410..16824f3c4 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -97,7 +97,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
97 for node in root.descendants() { 97 for node in root.descendants() {
98 let _ = visitor_ctx(&mut errors) 98 let _ = visitor_ctx(&mut errors)
99 .visit::<ast::Literal, _>(validate_literal) 99 .visit::<ast::Literal, _>(validate_literal)
100 .visit::<ast::Block, _>(block::validate_block_node) 100 .visit::<ast::BlockExpr, _>(block::validate_block_expr)
101 .visit::<ast::FieldExpr, _>(|it, errors| validate_numeric_name(it.name_ref(), errors)) 101 .visit::<ast::FieldExpr, _>(|it, errors| validate_numeric_name(it.name_ref(), errors))
102 .visit::<ast::RecordField, _>(|it, errors| validate_numeric_name(it.name_ref(), errors)) 102 .visit::<ast::RecordField, _>(|it, errors| validate_numeric_name(it.name_ref(), errors))
103 .accept(&node); 103 .accept(&node);
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs
index c5588658d..3c9e96eb3 100644
--- a/crates/ra_syntax/src/validation/block.rs
+++ b/crates/ra_syntax/src/validation/block.rs
@@ -5,18 +5,18 @@ use crate::{
5 SyntaxKind::*, 5 SyntaxKind::*,
6}; 6};
7 7
8pub(crate) fn validate_block_node(node: ast::Block, errors: &mut Vec<SyntaxError>) { 8pub(crate) fn validate_block_expr(expr: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
9 if let Some(parent) = node.syntax().parent() { 9 if let Some(parent) = expr.syntax().parent() {
10 match parent.kind() { 10 match parent.kind() {
11 FN_DEF => return, 11 FN_DEF | EXPR_STMT | BLOCK => return,
12 BLOCK_EXPR => match parent.parent().map(|v| v.kind()) {
13 Some(EXPR_STMT) | Some(BLOCK) => return,
14 _ => {}
15 },
16 _ => {} 12 _ => {}
17 } 13 }
18 } 14 }
19 errors.extend( 15 if let Some(block) = expr.block() {
20 node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())), 16 errors.extend(
21 ) 17 block
18 .attrs()
19 .map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())),
20 )
21 }
22} 22}