aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r--crates/ra_syntax/src/grammar/expressions.rs81
-rw-r--r--crates/ra_syntax/src/grammar/items.rs2
2 files changed, 47 insertions, 36 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs
index 1604d9b5a..d27eb8b7e 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/grammar/expressions.rs
@@ -45,7 +45,6 @@ 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),
49 // test nocontentexpr 48 // test nocontentexpr
50 // fn foo(){ 49 // fn foo(){
51 // ;;;some_expr();;;;{;;;};;;;Ok(()) 50 // ;;;some_expr();;;;{;;;};;;;Ok(())
@@ -55,41 +54,54 @@ pub(crate) fn block(p: &mut Parser) {
55 // test block_items 54 // test block_items
56 // fn a() { fn b() {} } 55 // fn a() { fn b() {} }
57 let m = p.start(); 56 let m = p.start();
58 match items::maybe_item(p, items::ItemFlavor::Mod) { 57 let has_attrs = p.at(POUND);
59 items::MaybeItem::Item(kind) => { 58 attributes::outer_attributes(p);
60 m.complete(p, kind); 59 if p.at(LET_KW) {
61 } 60 let_stmt(p, m);
62 items::MaybeItem::Modifiers => { 61 } else {
63 m.abandon(p); 62 match items::maybe_item(p, items::ItemFlavor::Mod) {
64 p.error("expected an item"); 63 items::MaybeItem::Item(kind) => {
65 } 64 m.complete(p, kind);
66 // test pub_expr 65 }
67 // fn foo() { pub 92; } //FIXME 66 items::MaybeItem::Modifiers => {
68 items::MaybeItem::None => {
69 let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
70 if p.at(R_CURLY) {
71 m.abandon(p); 67 m.abandon(p);
72 } else { 68 p.error("expected an item");
73 // test no_semi_after_block 69 }
74 // fn foo() { 70 // test pub_expr
75 // if true {} 71 // fn foo() { pub 92; } //FIXME
76 // loop {} 72 items::MaybeItem::None => {
77 // match () {} 73 if has_attrs {
78 // while true {} 74 m.abandon(p);
79 // for _ in () {} 75 p.error(
80 // {} 76 "expected a let statement or an item after attributes in block",
81 // {} 77 );
82 // macro_rules! test {
83 // () => {}
84 // }
85 // test!{}
86 // }
87 if is_blocklike {
88 p.eat(SEMI);
89 } else { 78 } else {
90 p.expect(SEMI); 79 let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
80 if p.at(R_CURLY) {
81 m.abandon(p);
82 } else {
83 // test no_semi_after_block
84 // fn foo() {
85 // if true {}
86 // loop {}
87 // match () {}
88 // while true {}
89 // for _ in () {}
90 // {}
91 // {}
92 // macro_rules! test {
93 // () => {}
94 // }
95 // test!{}
96 // }
97 if is_blocklike {
98 p.eat(SEMI);
99 } else {
100 p.expect(SEMI);
101 }
102 m.complete(p, EXPR_STMT);
103 }
91 } 104 }
92 m.complete(p, EXPR_STMT);
93 } 105 }
94 } 106 }
95 } 107 }
@@ -106,9 +118,8 @@ pub(crate) fn block(p: &mut Parser) {
106 // let c = 92; 118 // let c = 92;
107 // let d: i32 = 92; 119 // let d: i32 = 92;
108 // } 120 // }
109 fn let_stmt(p: &mut Parser) { 121 fn let_stmt(p: &mut Parser, m: Marker) {
110 assert!(p.at(LET_KW)); 122 assert!(p.at(LET_KW));
111 let m = p.start();
112 p.bump(); 123 p.bump();
113 patterns::pattern(p); 124 patterns::pattern(p);
114 if p.at(COLON) { 125 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);