diff options
author | Aleksey Kladov <[email protected]> | 2018-02-02 20:23:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-02-02 20:23:39 +0000 |
commit | be20b014d9fd4df64a8b6b88aaf6950d44ca6f39 (patch) | |
tree | c15234d193badb99117c3f4a4b53a4d76c243f90 /src/parser/event_parser/grammar/items | |
parent | 7cdf990c40e932a466e8799ca3fa582467d32c91 (diff) |
Move type parameter parsing to a separate file
Diffstat (limited to 'src/parser/event_parser/grammar/items')
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 70 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/structs.rs | 8 |
2 files changed, 4 insertions, 74 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 1c092779b..35825e7c4 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs | |||
@@ -83,76 +83,6 @@ fn item(p: &mut Parser) { | |||
83 | item.complete(p, item_kind); | 83 | item.complete(p, item_kind); |
84 | } | 84 | } |
85 | 85 | ||
86 | fn type_param_list(p: &mut Parser) { | ||
87 | if !p.at(L_ANGLE) { | ||
88 | return; | ||
89 | } | ||
90 | let m = p.start(); | ||
91 | p.bump(); | ||
92 | |||
93 | while !p.at(EOF) && !p.at(R_ANGLE) { | ||
94 | match p.current() { | ||
95 | LIFETIME => lifetime_param(p), | ||
96 | IDENT => type_param(p), | ||
97 | _ => p.err_and_bump("expected type parameter"), | ||
98 | } | ||
99 | if !p.at(R_ANGLE) && !p.expect(COMMA) { | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | p.expect(R_ANGLE); | ||
104 | m.complete(p, TYPE_PARAM_LIST); | ||
105 | |||
106 | fn lifetime_param(p: &mut Parser) { | ||
107 | assert!(p.at(LIFETIME)); | ||
108 | let m = p.start(); | ||
109 | p.bump(); | ||
110 | if p.eat(COLON) { | ||
111 | while p.at(LIFETIME) { | ||
112 | p.bump(); | ||
113 | if !p.eat(PLUS) { | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | m.complete(p, LIFETIME_PARAM); | ||
119 | } | ||
120 | |||
121 | fn type_param(p: &mut Parser) { | ||
122 | assert!(p.at(IDENT)); | ||
123 | let m = p.start(); | ||
124 | p.bump(); | ||
125 | if p.eat(COLON) { | ||
126 | loop { | ||
127 | let has_paren = p.eat(L_PAREN); | ||
128 | p.eat(QUESTION); | ||
129 | if p.at(FOR_KW) { | ||
130 | //TODO | ||
131 | } | ||
132 | if p.at(LIFETIME) { | ||
133 | p.bump(); | ||
134 | } else if paths::is_path_start(p) { | ||
135 | paths::type_path(p); | ||
136 | } else { | ||
137 | break; | ||
138 | } | ||
139 | if has_paren { | ||
140 | p.expect(R_PAREN); | ||
141 | } | ||
142 | if !p.eat(PLUS) { | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | if p.at(EQ) { | ||
148 | types::type_ref(p) | ||
149 | } | ||
150 | m.complete(p, TYPE_PARAM); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | fn where_clause(_: &mut Parser) {} | ||
155 | |||
156 | fn extern_crate_item(p: &mut Parser) { | 86 | fn extern_crate_item(p: &mut Parser) { |
157 | assert!(p.at(EXTERN_KW)); | 87 | assert!(p.at(EXTERN_KW)); |
158 | p.bump(); | 88 | p.bump(); |
diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs index 6e438413b..69d95c698 100644 --- a/src/parser/event_parser/grammar/items/structs.rs +++ b/src/parser/event_parser/grammar/items/structs.rs | |||
@@ -7,10 +7,10 @@ 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 | type_param_list(p); | 10 | type_params::list(p); |
11 | match p.current() { | 11 | match p.current() { |
12 | WHERE_KW => { | 12 | WHERE_KW => { |
13 | where_clause(p); | 13 | type_params::where_clause(p); |
14 | match p.current() { | 14 | match p.current() { |
15 | SEMI => { | 15 | SEMI => { |
16 | p.bump(); | 16 | p.bump(); |
@@ -44,8 +44,8 @@ pub(super) fn enum_item(p: &mut Parser) { | |||
44 | assert!(p.at(ENUM_KW)); | 44 | assert!(p.at(ENUM_KW)); |
45 | p.bump(); | 45 | p.bump(); |
46 | p.expect(IDENT); | 46 | p.expect(IDENT); |
47 | type_param_list(p); | 47 | type_params::list(p); |
48 | where_clause(p); | 48 | type_params::where_clause(p); |
49 | if p.expect(L_CURLY) { | 49 | if p.expect(L_CURLY) { |
50 | while !p.at(EOF) && !p.at(R_CURLY) { | 50 | while !p.at(EOF) && !p.at(R_CURLY) { |
51 | let var = p.start(); | 51 | let var = p.start(); |