aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser')
-rw-r--r--src/parser/event_parser/grammar/expressions.rs6
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs9
-rw-r--r--src/parser/event_parser/grammar/items/structs.rs34
3 files changed, 47 insertions, 2 deletions
diff --git a/src/parser/event_parser/grammar/expressions.rs b/src/parser/event_parser/grammar/expressions.rs
index c81dc6c35..8caaf3553 100644
--- a/src/parser/event_parser/grammar/expressions.rs
+++ b/src/parser/event_parser/grammar/expressions.rs
@@ -12,3 +12,9 @@ pub(super) fn literal(p: &mut Parser) -> bool {
12 _ => false, 12 _ => false,
13 } 13 }
14} 14}
15
16pub(super) fn expr(p: &mut Parser) {
17 if !literal(p) {
18 p.error().message("expected expression").emit();
19 }
20}
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs
index f10fb230b..0a50fffc1 100644
--- a/src/parser/event_parser/grammar/items/mod.rs
+++ b/src/parser/event_parser/grammar/items/mod.rs
@@ -9,8 +9,9 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
9 } 9 }
10} 10}
11 11
12pub(super) const ITEM_FIRST: TokenSet = 12pub(super) const ITEM_FIRST: TokenSet = token_set![
13 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; 13 EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND
14];
14 15
15fn item(p: &mut Parser) { 16fn item(p: &mut Parser) {
16 let item = p.start(); 17 let item = p.start();
@@ -34,6 +35,10 @@ fn item(p: &mut Parser) {
34 structs::struct_item(p); 35 structs::struct_item(p);
35 STRUCT_ITEM 36 STRUCT_ITEM
36 } 37 }
38 ENUM_KW => {
39 structs::enum_item(p);
40 ENUM_ITEM
41 }
37 FN_KW => { 42 FN_KW => {
38 fn_item(p); 43 fn_item(p);
39 FN_ITEM 44 FN_ITEM
diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs
index 0934f3d28..6e438413b 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();