aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar/type_params.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/grammar/type_params.rs')
-rw-r--r--src/parser/grammar/type_params.rs96
1 files changed, 0 insertions, 96 deletions
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs
deleted file mode 100644
index b31bf52b6..000000000
--- a/src/parser/grammar/type_params.rs
+++ /dev/null
@@ -1,96 +0,0 @@
1use super::*;
2
3pub(super) fn type_param_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 name(p);
42 if p.at(COLON) {
43 bounds(p);
44 }
45 // test type_param_default
46 // struct S<T = i32>;
47 if p.at(EQ) {
48 p.bump();
49 types::type_(p)
50 }
51 m.complete(p, TYPE_PARAM);
52 }
53}
54
55// test type_param_bounds
56// struct S<T: 'a + ?Sized + (Copy)>;
57pub(super) fn bounds(p: &mut Parser) {
58 assert!(p.at(COLON));
59 p.bump();
60 bounds_without_colon(p);
61}
62
63pub(super) fn bounds_without_colon(p: &mut Parser) {
64 loop {
65 let has_paren = p.eat(L_PAREN);
66 p.eat(QUESTION);
67 if p.at(FOR_KW) {
68 //TODO
69 }
70 if p.at(LIFETIME) {
71 p.bump();
72 } else if paths::is_path_start(p) {
73 paths::type_path(p);
74 } else {
75 break;
76 }
77 if has_paren {
78 p.expect(R_PAREN);
79 }
80 if !p.eat(PLUS) {
81 break;
82 }
83 }
84}
85
86
87pub(super) fn where_clause(p: &mut Parser) {
88 if p.at(WHERE_KW) {
89 let m = p.start();
90 p.bump();
91 p.expect(IDENT);
92 p.expect(COLON);
93 p.expect(IDENT);
94 m.complete(p, WHERE_CLAUSE);
95 }
96}