aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar/items
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser/grammar/items')
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs6
-rw-r--r--src/parser/event_parser/grammar/items/structs.rs34
2 files changed, 39 insertions, 1 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs
index f10fb230b..886c02d37 100644
--- a/src/parser/event_parser/grammar/items/mod.rs
+++ b/src/parser/event_parser/grammar/items/mod.rs
@@ -10,7 +10,7 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
10} 10}
11 11
12pub(super) const ITEM_FIRST: TokenSet = 12pub(super) const ITEM_FIRST: TokenSet =
13 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; 13 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND];
14 14
15fn item(p: &mut Parser) { 15fn item(p: &mut Parser) {
16 let item = p.start(); 16 let item = p.start();
@@ -34,6 +34,10 @@ fn item(p: &mut Parser) {
34 structs::struct_item(p); 34 structs::struct_item(p);
35 STRUCT_ITEM 35 STRUCT_ITEM
36 } 36 }
37 ENUM_KW => {
38 structs::enum_item(p);
39 ENUM_ITEM
40 }
37 FN_KW => { 41 FN_KW => {
38 fn_item(p); 42 fn_item(p);
39 FN_ITEM 43 FN_ITEM
diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs
index 0934f3d28..670406071 100644
--- a/src/parser/event_parser/grammar/items/structs.rs
+++ b/src/parser/event_parser/grammar/items/structs.rs
@@ -40,6 +40,40 @@ pub(super) fn struct_item(p: &mut Parser) {
40 } 40 }
41} 41}
42 42
43pub(super) fn enum_item(p: &mut Parser) {
44 assert!(p.at(ENUM_KW));
45 p.bump();
46 p.expect(IDENT);
47 type_param_list(p);
48 where_clause(p);
49 if p.expect(L_CURLY) {
50 while !p.at(EOF) && !p.at(R_CURLY) {
51 let var = p.start();
52 attributes::outer_attributes(p);
53 if p.at(IDENT) {
54 p.bump();
55 match p.current() {
56 L_CURLY => named_fields(p),
57 L_PAREN => pos_fields(p),
58 EQ => {
59 p.bump();
60 expressions::expr(p);
61 }
62 _ => ()
63 }
64 var.complete(p, ENUM_VARIANT);
65 } else {
66 var.abandon(p);
67 p.err_and_bump("expected enum variant");
68 }
69 if !p.at(R_CURLY) {
70 p.expect(COMMA);
71 }
72 }
73 p.expect(R_CURLY);
74 }
75}
76
43fn named_fields(p: &mut Parser) { 77fn named_fields(p: &mut Parser) {
44 assert!(p.at(L_CURLY)); 78 assert!(p.at(L_CURLY));
45 p.bump(); 79 p.bump();