aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar/type_params.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser/grammar/type_params.rs')
-rw-r--r--src/parser/event_parser/grammar/type_params.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/parser/event_parser/grammar/type_params.rs b/src/parser/event_parser/grammar/type_params.rs
new file mode 100644
index 000000000..12c9a5362
--- /dev/null
+++ b/src/parser/event_parser/grammar/type_params.rs
@@ -0,0 +1,75 @@
1use super::*;
2
3pub(super) fn list(p: &mut Parser) {
4 if !p.at(L_ANGLE) {
5 return;
6 }
7 let m = p.start();
8 p.bump();
9
10 while !p.at(EOF) && !p.at(R_ANGLE) {
11 match p.current() {
12 LIFETIME => lifetime_param(p),
13 IDENT => type_param(p),
14 _ => p.err_and_bump("expected type parameter"),
15 }
16 if !p.at(R_ANGLE) && !p.expect(COMMA) {
17 break;
18 }
19 }
20 p.expect(R_ANGLE);
21 m.complete(p, TYPE_PARAM_LIST);
22
23 fn lifetime_param(p: &mut Parser) {
24 assert!(p.at(LIFETIME));
25 let m = p.start();
26 p.bump();
27 if p.eat(COLON) {
28 while p.at(LIFETIME) {
29 p.bump();
30 if !p.eat(PLUS) {
31 break;
32 }
33 }
34 }
35 m.complete(p, LIFETIME_PARAM);
36 }
37
38 fn type_param(p: &mut Parser) {
39 assert!(p.at(IDENT));
40 let m = p.start();
41 p.bump();
42 if p.eat(COLON) {
43 loop {
44 let has_paren = p.eat(L_PAREN);
45 p.eat(QUESTION);
46 if p.at(FOR_KW) {
47 //TODO
48 }
49 if p.at(LIFETIME) {
50 p.bump();
51 } else if paths::is_path_start(p) {
52 paths::type_path(p);
53 } else {
54 break;
55 }
56 if has_paren {
57 p.expect(R_PAREN);
58 }
59 if !p.eat(PLUS) {
60 break;
61 }
62 }
63 }
64 if p.at(EQ) {
65 types::type_ref(p)
66 }
67 m.complete(p, TYPE_PARAM);
68 }
69}
70
71pub(super) fn where_clause(p: &mut Parser) {
72 if p.at(WHERE_KW) {
73 p.bump();
74 }
75}