File tree Expand file tree Collapse file tree 4 files changed +80
-74
lines changed
src/parser/event_parser/grammar Expand file tree Collapse file tree 4 files changed +80
-74
lines changed Original file line number Diff line number Diff line change @@ -83,76 +83,6 @@ fn item(p: &mut Parser) {
8383 item. complete ( p, item_kind) ;
8484}
8585
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-
15686fn extern_crate_item ( p : & mut Parser ) {
15787 assert ! ( p. at( EXTERN_KW ) ) ;
15888 p. bump ( ) ;
Original file line number Diff line number Diff line change @@ -7,10 +7,10 @@ pub(super) fn struct_item(p: &mut Parser) {
77 if !p. expect ( IDENT ) {
88 return ;
99 }
10- type_param_list ( p) ;
10+ type_params :: list ( p) ;
1111 match p. current ( ) {
1212 WHERE_KW => {
13- where_clause ( p) ;
13+ type_params :: where_clause ( p) ;
1414 match p. current ( ) {
1515 SEMI => {
1616 p. bump ( ) ;
@@ -44,8 +44,8 @@ pub(super) fn enum_item(p: &mut Parser) {
4444 assert ! ( p. at( ENUM_KW ) ) ;
4545 p. bump ( ) ;
4646 p. expect ( IDENT ) ;
47- type_param_list ( p) ;
48- where_clause ( p) ;
47+ type_params :: list ( p) ;
48+ type_params :: where_clause ( p) ;
4949 if p. expect ( L_CURLY ) {
5050 while !p. at ( EOF ) && !p. at ( R_CURLY ) {
5151 let var = p. start ( ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ mod attributes;
77mod expressions;
88mod types;
99mod paths;
10+ mod type_params;
1011
1112pub ( crate ) fn file ( p : & mut Parser ) {
1213 let file = p. start ( ) ;
Original file line number Diff line number Diff line change 1+ use super :: * ;
2+
3+ pub ( 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+
71+ pub ( super ) fn where_clause ( p : & mut Parser ) {
72+ if p. at ( WHERE_KW ) {
73+ p. bump ( ) ;
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments