diff options
author | Aleksey Kladov <[email protected]> | 2018-01-28 19:59:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-28 19:59:18 +0000 |
commit | b7c141e0b5c66c51db7171b1de30d4c60d1048c0 (patch) | |
tree | f73695cfca44f775f913391084c9079add4a041e /src/parser | |
parent | ab81e4c7b4383a153145752059be59e17571fad3 (diff) |
Parse enums
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/event_parser/grammar/expressions.rs | 6 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 6 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/structs.rs | 34 |
3 files changed, 45 insertions, 1 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 | |||
16 | pub(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..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 | ||
12 | pub(super) const ITEM_FIRST: TokenSet = | 12 | pub(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 | ||
15 | fn item(p: &mut Parser) { | 15 | fn 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 | ||
43 | pub(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 | |||
43 | fn named_fields(p: &mut Parser) { | 77 | fn named_fields(p: &mut Parser) { |
44 | assert!(p.at(L_CURLY)); | 78 | assert!(p.at(L_CURLY)); |
45 | p.bump(); | 79 | p.bump(); |