diff options
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 119 |
1 files changed, 59 insertions, 60 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 70c71a8e1..ccbc905ab 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -43,67 +43,60 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { | |||
43 | attributes::inner_attributes(p); | 43 | attributes::inner_attributes(p); |
44 | 44 | ||
45 | while !p.at(EOF) && !p.at(R_CURLY) { | 45 | while !p.at(EOF) && !p.at(R_CURLY) { |
46 | match p.current() { | 46 | // test nocontentexpr |
47 | // test nocontentexpr | 47 | // fn foo(){ |
48 | // fn foo(){ | 48 | // ;;;some_expr();;;;{;;;};;;;Ok(()) |
49 | // ;;;some_expr();;;;{;;;};;;;Ok(()) | 49 | // } |
50 | // } | 50 | if p.current() == SEMI { |
51 | SEMI => p.bump(), | 51 | p.bump(); |
52 | _ => { | 52 | continue; |
53 | // test block_items | 53 | } |
54 | // fn a() { fn b() {} } | 54 | |
55 | let m = p.start(); | 55 | // test block_items |
56 | let has_attrs = p.at(POUND); | 56 | // fn a() { fn b() {} } |
57 | attributes::outer_attributes(p); | 57 | let m = p.start(); |
58 | if p.at(LET_KW) { | 58 | let has_attrs = p.at(POUND); |
59 | let_stmt(p, m); | 59 | attributes::outer_attributes(p); |
60 | if p.at(LET_KW) { | ||
61 | let_stmt(p, m); | ||
62 | continue; | ||
63 | } | ||
64 | |||
65 | let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { | ||
66 | Ok(()) => continue, | ||
67 | Err(m) => m, | ||
68 | }; | ||
69 | |||
70 | // test pub_expr | ||
71 | // fn foo() { pub 92; } //FIXME | ||
72 | if has_attrs { | ||
73 | m.abandon(p); | ||
74 | p.error("expected a let statement or an item after attributes in block"); | ||
75 | } else { | ||
76 | let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; | ||
77 | if p.at(R_CURLY) { | ||
78 | m.abandon(p); | ||
79 | } else { | ||
80 | // test no_semi_after_block | ||
81 | // fn foo() { | ||
82 | // if true {} | ||
83 | // loop {} | ||
84 | // match () {} | ||
85 | // while true {} | ||
86 | // for _ in () {} | ||
87 | // {} | ||
88 | // {} | ||
89 | // macro_rules! test { | ||
90 | // () => {} | ||
91 | // } | ||
92 | // test!{} | ||
93 | // } | ||
94 | if is_blocklike { | ||
95 | p.eat(SEMI); | ||
60 | } else { | 96 | } else { |
61 | match items::maybe_item(p, items::ItemFlavor::Mod) { | 97 | p.expect(SEMI); |
62 | items::MaybeItem::Item(kind) => { | ||
63 | m.complete(p, kind); | ||
64 | } | ||
65 | items::MaybeItem::Modifiers => { | ||
66 | m.abandon(p); | ||
67 | p.error("expected an item"); | ||
68 | } | ||
69 | // test pub_expr | ||
70 | // fn foo() { pub 92; } //FIXME | ||
71 | items::MaybeItem::None => { | ||
72 | if has_attrs { | ||
73 | m.abandon(p); | ||
74 | p.error( | ||
75 | "expected a let statement or an item after attributes in block", | ||
76 | ); | ||
77 | } else { | ||
78 | let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; | ||
79 | if p.at(R_CURLY) { | ||
80 | m.abandon(p); | ||
81 | } else { | ||
82 | // test no_semi_after_block | ||
83 | // fn foo() { | ||
84 | // if true {} | ||
85 | // loop {} | ||
86 | // match () {} | ||
87 | // while true {} | ||
88 | // for _ in () {} | ||
89 | // {} | ||
90 | // {} | ||
91 | // macro_rules! test { | ||
92 | // () => {} | ||
93 | // } | ||
94 | // test!{} | ||
95 | // } | ||
96 | if is_blocklike { | ||
97 | p.eat(SEMI); | ||
98 | } else { | ||
99 | p.expect(SEMI); | ||
100 | } | ||
101 | m.complete(p, EXPR_STMT); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | } | 98 | } |
99 | m.complete(p, EXPR_STMT); | ||
107 | } | 100 | } |
108 | } | 101 | } |
109 | } | 102 | } |
@@ -155,6 +148,7 @@ fn current_op(p: &Parser) -> (u8, Op) { | |||
155 | (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), | 148 | (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), |
156 | (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), | 149 | (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), |
157 | (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)), | 150 | (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)), |
151 | (PERCENT, EQ) => return (1, Op::Composite(PERCENTEQ, 2)), | ||
158 | (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)), | 152 | (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)), |
159 | (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)), | 153 | (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)), |
160 | (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)), | 154 | (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)), |
@@ -453,8 +447,13 @@ pub(crate) fn named_field_list(p: &mut Parser) { | |||
453 | p.bump(); | 447 | p.bump(); |
454 | while !p.at(EOF) && !p.at(R_CURLY) { | 448 | while !p.at(EOF) && !p.at(R_CURLY) { |
455 | match p.current() { | 449 | match p.current() { |
456 | IDENT => { | 450 | // test struct_literal_field_with_attr |
451 | // fn main() { | ||
452 | // S { #[cfg(test)] field: 1 } | ||
453 | // } | ||
454 | IDENT | POUND => { | ||
457 | let m = p.start(); | 455 | let m = p.start(); |
456 | attributes::outer_attributes(p); | ||
458 | name_ref(p); | 457 | name_ref(p); |
459 | if p.eat(COLON) { | 458 | if p.eat(COLON) { |
460 | expr(p); | 459 | expr(p); |