aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/grammar/expressions.rs15
-rw-r--r--crates/ra_syntax/src/grammar/items.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt32
3 files changed, 26 insertions, 23 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs
index 0b2f7b116..8dd9587d0 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/grammar/expressions.rs
@@ -45,7 +45,10 @@ pub(crate) fn block(p: &mut Parser) {
45 45
46 while !p.at(EOF) && !p.at(R_CURLY) { 46 while !p.at(EOF) && !p.at(R_CURLY) {
47 match p.current() { 47 match p.current() {
48 LET_KW => let_stmt(p), 48 LET_KW => {
49 let m = p.start();
50 let_stmt(p, m)
51 }
49 // test nocontentexpr 52 // test nocontentexpr
50 // fn foo(){ 53 // fn foo(){
51 // ;;;some_expr();;;;{;;;};;;;Ok(()) 54 // ;;;some_expr();;;;{;;;};;;;Ok(())
@@ -54,8 +57,9 @@ pub(crate) fn block(p: &mut Parser) {
54 _ => { 57 _ => {
55 // test block_items 58 // test block_items
56 // fn a() { fn b() {} } 59 // fn a() { fn b() {} }
57 let has_attrs = p.at(POUND);
58 let m = p.start(); 60 let m = p.start();
61 let has_attrs = p.at(POUND);
62 attributes::outer_attributes(p);
59 match items::maybe_item(p, items::ItemFlavor::Mod) { 63 match items::maybe_item(p, items::ItemFlavor::Mod) {
60 items::MaybeItem::Item(kind) => { 64 items::MaybeItem::Item(kind) => {
61 m.complete(p, kind); 65 m.complete(p, kind);
@@ -68,10 +72,10 @@ pub(crate) fn block(p: &mut Parser) {
68 // fn foo() { pub 92; } //FIXME 72 // fn foo() { pub 92; } //FIXME
69 items::MaybeItem::None => { 73 items::MaybeItem::None => {
70 if has_attrs { 74 if has_attrs {
71 m.abandon(p);
72 if p.at(LET_KW) { 75 if p.at(LET_KW) {
73 let_stmt(p); 76 let_stmt(p, m);
74 } else { 77 } else {
78 m.abandon(p);
75 p.error("expected a let statement"); 79 p.error("expected a let statement");
76 } 80 }
77 } else { 81 } else {
@@ -116,9 +120,8 @@ pub(crate) fn block(p: &mut Parser) {
116 // let c = 92; 120 // let c = 92;
117 // let d: i32 = 92; 121 // let d: i32 = 92;
118 // } 122 // }
119 fn let_stmt(p: &mut Parser) { 123 fn let_stmt(p: &mut Parser, m: Marker) {
120 assert!(p.at(LET_KW)); 124 assert!(p.at(LET_KW));
121 let m = p.start();
122 p.bump(); 125 p.bump();
123 patterns::pattern(p); 126 patterns::pattern(p);
124 if p.at(COLON) { 127 if p.at(COLON) {
diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs
index 265e84570..18039cd3f 100644
--- a/crates/ra_syntax/src/grammar/items.rs
+++ b/crates/ra_syntax/src/grammar/items.rs
@@ -36,6 +36,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
36 36
37pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { 37pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
38 let m = p.start(); 38 let m = p.start();
39 attributes::outer_attributes(p);
39 match maybe_item(p, flavor) { 40 match maybe_item(p, flavor) {
40 MaybeItem::Item(kind) => { 41 MaybeItem::Item(kind) => {
41 m.complete(p, kind); 42 m.complete(p, kind);
@@ -79,7 +80,6 @@ pub(super) enum MaybeItem {
79} 80}
80 81
81pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem { 82pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
82 attributes::outer_attributes(p);
83 opt_visibility(p); 83 opt_visibility(p);
84 if let Some(kind) = items_without_modifiers(p) { 84 if let Some(kind) = items_without_modifiers(p) {
85 return MaybeItem::Item(kind); 85 return MaybeItem::Item(kind);
diff --git a/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt b/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt
index b3f37dd96..1f52f699b 100644
--- a/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt
+++ b/crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt
@@ -13,22 +13,22 @@ SOURCE_FILE@[0; 166)
13 BLOCK@[71; 165) 13 BLOCK@[71; 165)
14 L_CURLY@[71; 72) 14 L_CURLY@[71; 72)
15 WHITESPACE@[72; 77) 15 WHITESPACE@[72; 77)
16 ATTR@[77; 106) 16 LET_STMT@[77; 163)
17 POUND@[77; 78) 17 ATTR@[77; 106)
18 TOKEN_TREE@[78; 106) 18 POUND@[77; 78)
19 L_BRACK@[78; 79) 19 TOKEN_TREE@[78; 106)
20 IDENT@[79; 82) "cfg" 20 L_BRACK@[78; 79)
21 TOKEN_TREE@[82; 105) 21 IDENT@[79; 82) "cfg"
22 L_PAREN@[82; 83) 22 TOKEN_TREE@[82; 105)
23 IDENT@[83; 90) "feature" 23 L_PAREN@[82; 83)
24 WHITESPACE@[90; 91) 24 IDENT@[83; 90) "feature"
25 EQ@[91; 92) 25 WHITESPACE@[90; 91)
26 WHITESPACE@[92; 93) 26 EQ@[91; 92)
27 STRING@[93; 104) 27 WHITESPACE@[92; 93)
28 R_PAREN@[104; 105) 28 STRING@[93; 104)
29 R_BRACK@[105; 106) 29 R_PAREN@[104; 105)
30 WHITESPACE@[106; 111) 30 R_BRACK@[105; 106)
31 LET_STMT@[111; 163) 31 WHITESPACE@[106; 111)
32 LET_KW@[111; 114) 32 LET_KW@[111; 114)
33 WHITESPACE@[114; 115) 33 WHITESPACE@[114; 115)
34 BIND_PAT@[115; 124) 34 BIND_PAT@[115; 124)