aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-28 19:59:18 +0000
committerAleksey Kladov <[email protected]>2018-01-28 19:59:18 +0000
commitb7c141e0b5c66c51db7171b1de30d4c60d1048c0 (patch)
treef73695cfca44f775f913391084c9079add4a041e /src
parentab81e4c7b4383a153145752059be59e17571fad3 (diff)
Parse enums
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/expressions.rs6
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs6
-rw-r--r--src/parser/event_parser/grammar/items/structs.rs34
-rw-r--r--src/syntax_kinds.rs4
4 files changed, 49 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
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..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();
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index b6c281cd5..519326f48 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -76,6 +76,8 @@ pub enum SyntaxKind {
76 SHEBANG, 76 SHEBANG,
77 FILE, 77 FILE,
78 STRUCT_ITEM, 78 STRUCT_ITEM,
79 ENUM_ITEM,
80 ENUM_VARIANT,
79 NAMED_FIELD, 81 NAMED_FIELD,
80 POS_FIELD, 82 POS_FIELD,
81 FN_ITEM, 83 FN_ITEM,
@@ -176,6 +178,8 @@ impl SyntaxKind {
176 SHEBANG => &SyntaxInfo { name: "SHEBANG" }, 178 SHEBANG => &SyntaxInfo { name: "SHEBANG" },
177 FILE => &SyntaxInfo { name: "FILE" }, 179 FILE => &SyntaxInfo { name: "FILE" },
178 STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" }, 180 STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" },
181 ENUM_ITEM => &SyntaxInfo { name: "ENUM_ITEM" },
182 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
179 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 183 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
180 POS_FIELD => &SyntaxInfo { name: "POS_FIELD" }, 184 POS_FIELD => &SyntaxInfo { name: "POS_FIELD" },
181 FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, 185 FN_ITEM => &SyntaxInfo { name: "FN_ITEM" },