diff options
author | Aleksey Kladov <[email protected]> | 2018-08-24 17:27:30 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-24 17:27:30 +0100 |
commit | 7edab6ae6b4c5d0c411e88f10e923b91dca31de3 (patch) | |
tree | 4c17856285f568c56adb7c02024ef80e821dd367 /crates/libsyntax2/src/grammar/items/structs.rs | |
parent | 4d293003964c8f9fabadb1ceb77eab29c0438de3 (diff) |
nodes for blocks
Diffstat (limited to 'crates/libsyntax2/src/grammar/items/structs.rs')
-rw-r--r-- | crates/libsyntax2/src/grammar/items/structs.rs | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/crates/libsyntax2/src/grammar/items/structs.rs b/crates/libsyntax2/src/grammar/items/structs.rs index cde9d0ae6..ca027d718 100644 --- a/crates/libsyntax2/src/grammar/items/structs.rs +++ b/crates/libsyntax2/src/grammar/items/structs.rs | |||
@@ -14,7 +14,7 @@ pub(super) fn struct_def(p: &mut Parser) { | |||
14 | p.bump(); | 14 | p.bump(); |
15 | return; | 15 | return; |
16 | } | 16 | } |
17 | L_CURLY => named_fields(p), | 17 | L_CURLY => named_field_def_list(p), |
18 | _ => { | 18 | _ => { |
19 | //TODO: special case `(` error message | 19 | //TODO: special case `(` error message |
20 | p.error("expected `;` or `{`"); | 20 | p.error("expected `;` or `{`"); |
@@ -26,9 +26,9 @@ pub(super) fn struct_def(p: &mut Parser) { | |||
26 | p.bump(); | 26 | p.bump(); |
27 | return; | 27 | return; |
28 | } | 28 | } |
29 | L_CURLY => named_fields(p), | 29 | L_CURLY => named_field_def_list(p), |
30 | L_PAREN => { | 30 | L_PAREN => { |
31 | pos_fields(p); | 31 | pos_field_list(p); |
32 | p.expect(SEMI); | 32 | p.expect(SEMI); |
33 | } | 33 | } |
34 | _ => { | 34 | _ => { |
@@ -44,46 +44,58 @@ pub(super) fn enum_def(p: &mut Parser) { | |||
44 | name(p); | 44 | name(p); |
45 | type_params::opt_type_param_list(p); | 45 | type_params::opt_type_param_list(p); |
46 | type_params::opt_where_clause(p); | 46 | type_params::opt_where_clause(p); |
47 | if p.expect(L_CURLY) { | 47 | if p.at(L_CURLY) { |
48 | while !p.at(EOF) && !p.at(R_CURLY) { | 48 | enum_variant_list(p); |
49 | let var = p.start(); | 49 | } else { |
50 | attributes::outer_attributes(p); | 50 | p.error("expected `{`") |
51 | if p.at(IDENT) { | 51 | } |
52 | name(p); | 52 | } |
53 | match p.current() { | 53 | |
54 | L_CURLY => named_fields(p), | 54 | fn enum_variant_list(p: &mut Parser) { |
55 | L_PAREN => pos_fields(p), | 55 | assert!(p.at(L_CURLY)); |
56 | EQ => { | 56 | let m = p.start(); |
57 | p.bump(); | 57 | p.bump(); |
58 | expressions::expr(p); | 58 | while !p.at(EOF) && !p.at(R_CURLY) { |
59 | } | 59 | let var = p.start(); |
60 | _ => (), | 60 | attributes::outer_attributes(p); |
61 | if p.at(IDENT) { | ||
62 | name(p); | ||
63 | match p.current() { | ||
64 | L_CURLY => named_field_def_list(p), | ||
65 | L_PAREN => pos_field_list(p), | ||
66 | EQ => { | ||
67 | p.bump(); | ||
68 | expressions::expr(p); | ||
61 | } | 69 | } |
62 | var.complete(p, ENUM_VARIANT); | 70 | _ => (), |
63 | } else { | ||
64 | var.abandon(p); | ||
65 | p.err_and_bump("expected enum variant"); | ||
66 | } | ||
67 | if !p.at(R_CURLY) { | ||
68 | p.expect(COMMA); | ||
69 | } | 71 | } |
72 | var.complete(p, ENUM_VARIANT); | ||
73 | } else { | ||
74 | var.abandon(p); | ||
75 | p.err_and_bump("expected enum variant"); | ||
76 | } | ||
77 | if !p.at(R_CURLY) { | ||
78 | p.expect(COMMA); | ||
70 | } | 79 | } |
71 | p.expect(R_CURLY); | ||
72 | } | 80 | } |
81 | p.expect(R_CURLY); | ||
82 | m.complete(p, ENUM_VARIANT_LIST); | ||
73 | } | 83 | } |
74 | 84 | ||
75 | fn named_fields(p: &mut Parser) { | 85 | fn named_field_def_list(p: &mut Parser) { |
76 | assert!(p.at(L_CURLY)); | 86 | assert!(p.at(L_CURLY)); |
87 | let m = p.start(); | ||
77 | p.bump(); | 88 | p.bump(); |
78 | while !p.at(R_CURLY) && !p.at(EOF) { | 89 | while !p.at(R_CURLY) && !p.at(EOF) { |
79 | named_field(p); | 90 | named_field_def(p); |
80 | if !p.at(R_CURLY) { | 91 | if !p.at(R_CURLY) { |
81 | p.expect(COMMA); | 92 | p.expect(COMMA); |
82 | } | 93 | } |
83 | } | 94 | } |
84 | p.expect(R_CURLY); | 95 | p.expect(R_CURLY); |
96 | m.complete(p, NAMED_FIELD_DEF_LIST); | ||
85 | 97 | ||
86 | fn named_field(p: &mut Parser) { | 98 | fn named_field_def(p: &mut Parser) { |
87 | let m = p.start(); | 99 | let m = p.start(); |
88 | // test field_attrs | 100 | // test field_attrs |
89 | // struct S { | 101 | // struct S { |
@@ -96,7 +108,7 @@ fn named_fields(p: &mut Parser) { | |||
96 | name(p); | 108 | name(p); |
97 | p.expect(COLON); | 109 | p.expect(COLON); |
98 | types::type_(p); | 110 | types::type_(p); |
99 | m.complete(p, NAMED_FIELD); | 111 | m.complete(p, NAMED_FIELD_DEF); |
100 | } else { | 112 | } else { |
101 | m.abandon(p); | 113 | m.abandon(p); |
102 | p.err_and_bump("expected field declaration"); | 114 | p.err_and_bump("expected field declaration"); |
@@ -104,7 +116,9 @@ fn named_fields(p: &mut Parser) { | |||
104 | } | 116 | } |
105 | } | 117 | } |
106 | 118 | ||
107 | fn pos_fields(p: &mut Parser) { | 119 | fn pos_field_list(p: &mut Parser) { |
120 | assert!(p.at(L_PAREN)); | ||
121 | let m = p.start(); | ||
108 | if !p.expect(L_PAREN) { | 122 | if !p.expect(L_PAREN) { |
109 | return; | 123 | return; |
110 | } | 124 | } |
@@ -119,4 +133,5 @@ fn pos_fields(p: &mut Parser) { | |||
119 | } | 133 | } |
120 | } | 134 | } |
121 | p.expect(R_PAREN); | 135 | p.expect(R_PAREN); |
136 | m.complete(p, POS_FIELD_LIST); | ||
122 | } | 137 | } |