aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-28 15:53:53 +0000
committerAleksey Kladov <[email protected]>2018-01-28 18:18:24 +0000
commit8ca02acb5a574c312dcb3842904b99b282d45883 (patch)
treed1707c94eda435c95408f73ec530aa5ac2386920 /src/parser/event_parser/grammar
parent7e55b2693f17afdae91c492c6f79c9ba4020d893 (diff)
Generic params in structs
Diffstat (limited to 'src/parser/event_parser/grammar')
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs44
-rw-r--r--src/parser/event_parser/grammar/items/structs.rs2
2 files changed, 44 insertions, 2 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs
index 867776415..f10fb230b 100644
--- a/src/parser/event_parser/grammar/items/mod.rs
+++ b/src/parser/event_parser/grammar/items/mod.rs
@@ -59,7 +59,49 @@ fn item(p: &mut Parser) {
59 item.complete(p, item_kind); 59 item.complete(p, item_kind);
60} 60}
61 61
62fn generic_parameters(_: &mut Parser) {} 62fn type_param_list(p: &mut Parser) {
63 if !p.at(L_ANGLE) {
64 return;
65 }
66 let m = p.start();
67 p.bump();
68
69 while !p.at(EOF) && !p.at(R_ANGLE) {
70 match p.current() {
71 LIFETIME => lifetime_param(p),
72 IDENT => type_param(p),
73 _ => p.err_and_bump("expected type parameter"),
74 }
75 if !p.at(R_ANGLE) && !p.expect(COMMA) {
76 break;
77 }
78 }
79 p.expect(R_ANGLE);
80 m.complete(p, TYPE_PARAM_LIST);
81
82 fn lifetime_param(p: &mut Parser) {
83 assert!(p.at(LIFETIME));
84 let m = p.start();
85 p.bump();
86 if p.eat(COLON) {
87 while p.at(LIFETIME) {
88 p.bump();
89 if !p.eat(PLUS) {
90 break;
91 }
92 }
93 }
94 m.complete(p, LIFETIME_PARAM);
95 }
96
97 fn type_param(p: &mut Parser) {
98 assert!(p.at(IDENT));
99 let m = p.start();
100 p.bump();
101 m.complete(p, TYPE_PARAM);
102 //TODO: bounds
103 }
104}
63 105
64fn where_clause(_: &mut Parser) {} 106fn where_clause(_: &mut Parser) {}
65 107
diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs
index b31cf18df..0934f3d28 100644
--- a/src/parser/event_parser/grammar/items/structs.rs
+++ b/src/parser/event_parser/grammar/items/structs.rs
@@ -7,7 +7,7 @@ pub(super) fn struct_item(p: &mut Parser) {
7 if !p.expect(IDENT) { 7 if !p.expect(IDENT) {
8 return; 8 return;
9 } 9 }
10 generic_parameters(p); 10 type_param_list(p);
11 match p.current() { 11 match p.current() {
12 WHERE_KW => { 12 WHERE_KW => {
13 where_clause(p); 13 where_clause(p);