5
5
//! The grammar is as follows:
6
6
//!
7
7
//! ```text
8
- //! Command: `@bot modify labels:? to? <label-list>.` or `@bot label:? <label-list>.`
8
+ //! Command: `@bot modify? <label-w> to? :? <label-list>.`
9
+ //!
10
+ //! <label-w>:
11
+ //! - label
12
+ //! - labels
9
13
//!
10
14
//! <label-list>:
11
15
//! - <label-delta>
@@ -46,7 +50,6 @@ pub enum ParseError {
46
50
EmptyLabel ,
47
51
ExpectedLabelDelta ,
48
52
MisleadingTo ,
49
- NoSeparator ,
50
53
}
51
54
52
55
impl std:: error:: Error for ParseError { }
@@ -57,7 +60,6 @@ impl fmt::Display for ParseError {
57
60
ParseError :: EmptyLabel => write ! ( f, "empty label" ) ,
58
61
ParseError :: ExpectedLabelDelta => write ! ( f, "a label delta" ) ,
59
62
ParseError :: MisleadingTo => write ! ( f, "forbidden `to`, use `+to`" ) ,
60
- ParseError :: NoSeparator => write ! ( f, "must have `:` or `to` as label starter" ) ,
61
63
}
62
64
}
63
65
}
@@ -128,28 +130,13 @@ impl RelabelCommand {
128
130
pub fn parse < ' a > ( input : & mut Tokenizer < ' a > ) -> Result < Option < Self > , Error < ' a > > {
129
131
let mut toks = input. clone ( ) ;
130
132
131
- if toks. eat_token ( Token :: Word ( "modify" ) ) ? {
132
- if toks. eat_token ( Token :: Word ( "labels" ) ) ? {
133
- if toks. eat_token ( Token :: Colon ) ? {
134
- // ate the colon
135
- } else if toks. eat_token ( Token :: Word ( "to" ) ) ? {
136
- // optionally eat the colon after to, e.g.:
137
- // @rustbot modify labels to: -S-waiting-on-author, +S-waiting-on-review
138
- toks. eat_token ( Token :: Colon ) ?;
139
- } else {
140
- // It's okay if there's no to or colon, we can just eat labels
141
- // afterwards.
142
- }
143
- // continue
144
- { } // FIXME(rustfmt#4506): this is needed to get rustfmt to indent the comment correctly
145
- } else {
146
- return Ok ( None ) ;
147
- }
148
- } else if toks. eat_token ( Token :: Word ( "label" ) ) ? {
149
- // optionally eat a colon
133
+ toks. eat_token ( Token :: Word ( "modify" ) ) ?;
134
+
135
+ if toks. eat_token ( Token :: Word ( "labels" ) ) ? || toks. eat_token ( Token :: Word ( "label" ) ) ? {
136
+ toks. eat_token ( Token :: Word ( "to" ) ) ?;
150
137
toks. eat_token ( Token :: Colon ) ?;
138
+
151
139
// continue
152
- { } // FIXME(rustfmt#4506): this is needed to get rustfmt to indent the comment correctly
153
140
} else {
154
141
return Ok ( None ) ;
155
142
}
@@ -163,12 +150,8 @@ impl RelabelCommand {
163
150
deltas. push ( LabelDelta :: parse ( & mut toks) ?) ;
164
151
165
152
// optional `, and` separator
166
- if let Some ( Token :: Comma ) = toks. peek_token ( ) ? {
167
- toks. next_token ( ) ?;
168
- }
169
- if let Some ( Token :: Word ( "and" ) ) = toks. peek_token ( ) ? {
170
- toks. next_token ( ) ?;
171
- }
153
+ toks. eat_token ( Token :: Comma ) ?;
154
+ toks. eat_token ( Token :: Word ( "and" ) ) ?;
172
155
173
156
if let Some ( Token :: Semi ) | Some ( Token :: Dot ) | Some ( Token :: EndOfLine ) =
174
157
toks. peek_token ( ) ?
@@ -258,7 +241,7 @@ fn parse_shorter_command() {
258
241
#[ test]
259
242
fn parse_shorter_command_with_colon ( ) {
260
243
assert_eq ! (
261
- parse( "label : +T-compiler -T-lang bug" ) ,
244
+ parse( "labels : +T-compiler -T-lang bug" ) ,
262
245
Ok ( Some ( vec![
263
246
LabelDelta :: Add ( Label ( "T-compiler" . into( ) ) ) ,
264
247
LabelDelta :: Remove ( Label ( "T-lang" . into( ) ) ) ,
@@ -270,23 +253,23 @@ fn parse_shorter_command_with_colon() {
270
253
#[ test]
271
254
fn parse_shorter_command_with_to ( ) {
272
255
assert_eq ! (
273
- parse( "label to +T-compiler -T-lang bug" )
274
- . unwrap_err ( )
275
- . source ( )
276
- . unwrap ( )
277
- . downcast_ref ( ) ,
278
- Some ( & ParseError :: MisleadingTo )
256
+ parse( "label to +T-compiler -T-lang bug" ) ,
257
+ Ok ( Some ( vec! [
258
+ LabelDelta :: Add ( Label ( "T-compiler" . into ( ) ) ) ,
259
+ LabelDelta :: Remove ( Label ( "T-lang" . into ( ) ) ) ,
260
+ LabelDelta :: Add ( Label ( "bug" . into ( ) ) ) ,
261
+ ] ) )
279
262
) ;
280
263
}
281
264
282
265
#[ test]
283
266
fn parse_shorter_command_with_to_colon ( ) {
284
267
assert_eq ! (
285
- parse( "label to: +T-compiler -T-lang bug" )
286
- . unwrap_err ( )
287
- . source ( )
288
- . unwrap ( )
289
- . downcast_ref ( ) ,
290
- Some ( & ParseError :: MisleadingTo )
268
+ parse( "label to: +T-compiler -T-lang bug" ) ,
269
+ Ok ( Some ( vec! [
270
+ LabelDelta :: Add ( Label ( "T-compiler" . into ( ) ) ) ,
271
+ LabelDelta :: Remove ( Label ( "T-lang" . into ( ) ) ) ,
272
+ LabelDelta :: Add ( Label ( "bug" . into ( ) ) ) ,
273
+ ] ) )
291
274
) ;
292
275
}
0 commit comments