diff options
Diffstat (limited to 'crates/ra_parser/src/grammar/items')
-rw-r--r-- | crates/ra_parser/src/grammar/items/consts.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items/nominal.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items/use_item.rs | 3 |
3 files changed, 12 insertions, 13 deletions
diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs index 5a5852f83..e6e6011c6 100644 --- a/crates/ra_parser/src/grammar/items/consts.rs +++ b/crates/ra_parser/src/grammar/items/consts.rs | |||
@@ -1,14 +1,14 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn static_def(p: &mut Parser) { | 3 | pub(super) fn static_def(p: &mut Parser, m: Marker) { |
4 | const_or_static(p, STATIC_KW) | 4 | const_or_static(p, m, STATIC_KW, STATIC_DEF) |
5 | } | 5 | } |
6 | 6 | ||
7 | pub(super) fn const_def(p: &mut Parser) { | 7 | pub(super) fn const_def(p: &mut Parser, m: Marker) { |
8 | const_or_static(p, CONST_KW) | 8 | const_or_static(p, m, CONST_KW, CONST_DEF) |
9 | } | 9 | } |
10 | 10 | ||
11 | fn const_or_static(p: &mut Parser, kw: SyntaxKind) { | 11 | fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { |
12 | assert!(p.at(kw)); | 12 | assert!(p.at(kw)); |
13 | p.bump(); | 13 | p.bump(); |
14 | p.eat(MUT_KW); // TODO: validator to forbid const mut | 14 | p.eat(MUT_KW); // TODO: validator to forbid const mut |
@@ -18,4 +18,5 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { | |||
18 | expressions::expr(p); | 18 | expressions::expr(p); |
19 | } | 19 | } |
20 | p.expect(SEMI); | 20 | p.expect(SEMI); |
21 | m.complete(p, def); | ||
21 | } | 22 | } |
diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs index ff9b38f9c..a3579eebd 100644 --- a/crates/ra_parser/src/grammar/items/nominal.rs +++ b/crates/ra_parser/src/grammar/items/nominal.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { | 3 | pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { |
4 | assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union")); | 4 | assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union")); |
5 | p.bump_remap(kind); | 5 | p.bump_remap(kind); |
6 | 6 | ||
@@ -12,19 +12,16 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { | |||
12 | match p.current() { | 12 | match p.current() { |
13 | SEMI => { | 13 | SEMI => { |
14 | p.bump(); | 14 | p.bump(); |
15 | return; | ||
16 | } | 15 | } |
17 | L_CURLY => named_field_def_list(p), | 16 | L_CURLY => named_field_def_list(p), |
18 | _ => { | 17 | _ => { |
19 | //TODO: special case `(` error message | 18 | //TODO: special case `(` error message |
20 | p.error("expected `;` or `{`"); | 19 | p.error("expected `;` or `{`"); |
21 | return; | ||
22 | } | 20 | } |
23 | } | 21 | } |
24 | } | 22 | } |
25 | SEMI if kind == STRUCT_KW => { | 23 | SEMI if kind == STRUCT_KW => { |
26 | p.bump(); | 24 | p.bump(); |
27 | return; | ||
28 | } | 25 | } |
29 | L_CURLY => named_field_def_list(p), | 26 | L_CURLY => named_field_def_list(p), |
30 | L_PAREN if kind == STRUCT_KW => { | 27 | L_PAREN if kind == STRUCT_KW => { |
@@ -37,16 +34,15 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { | |||
37 | } | 34 | } |
38 | _ if kind == STRUCT_KW => { | 35 | _ if kind == STRUCT_KW => { |
39 | p.error("expected `;`, `{`, or `(`"); | 36 | p.error("expected `;`, `{`, or `(`"); |
40 | return; | ||
41 | } | 37 | } |
42 | _ => { | 38 | _ => { |
43 | p.error("expected `{`"); | 39 | p.error("expected `{`"); |
44 | return; | ||
45 | } | 40 | } |
46 | } | 41 | } |
42 | m.complete(p, STRUCT_DEF); | ||
47 | } | 43 | } |
48 | 44 | ||
49 | pub(super) fn enum_def(p: &mut Parser) { | 45 | pub(super) fn enum_def(p: &mut Parser, m: Marker) { |
50 | assert!(p.at(ENUM_KW)); | 46 | assert!(p.at(ENUM_KW)); |
51 | p.bump(); | 47 | p.bump(); |
52 | name_r(p, ITEM_RECOVERY_SET); | 48 | name_r(p, ITEM_RECOVERY_SET); |
@@ -57,6 +53,7 @@ pub(super) fn enum_def(p: &mut Parser) { | |||
57 | } else { | 53 | } else { |
58 | p.error("expected `{`") | 54 | p.error("expected `{`") |
59 | } | 55 | } |
56 | m.complete(p, ENUM_DEF); | ||
60 | } | 57 | } |
61 | 58 | ||
62 | pub(crate) fn enum_variant_list(p: &mut Parser) { | 59 | pub(crate) fn enum_variant_list(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index b36612726..ea2f94604 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn use_item(p: &mut Parser) { | 3 | pub(super) fn use_item(p: &mut Parser, m: Marker) { |
4 | assert!(p.at(USE_KW)); | 4 | assert!(p.at(USE_KW)); |
5 | p.bump(); | 5 | p.bump(); |
6 | use_tree(p); | 6 | use_tree(p); |
7 | p.expect(SEMI); | 7 | p.expect(SEMI); |
8 | m.complete(p, USE_ITEM); | ||
8 | } | 9 | } |
9 | 10 | ||
10 | /// Parse a use 'tree', such as `some::path` in `use some::path;` | 11 | /// Parse a use 'tree', such as `some::path` in `use some::path;` |