@@ -98,14 +98,7 @@ impl Comments {
98
98
line : & str ,
99
99
) -> Result < ( ) > {
100
100
if let Some ( ( _, command) ) = line. split_once ( "//@" ) {
101
- let command = command. trim ( ) ;
102
- if let Some ( ( command, args) ) = command. split_once ( ':' ) {
103
- self . parse_command_with_args ( command, args, l)
104
- } else if let Some ( ( command, _comments) ) = command. split_once ( ' ' ) {
105
- self . parse_command ( command)
106
- } else {
107
- self . parse_command ( command)
108
- }
101
+ self . parse_command ( command. trim ( ) , l)
109
102
} else if let Some ( ( _, pattern) ) = line. split_once ( "//~" ) {
110
103
self . parse_pattern ( pattern, fallthrough_to, l)
111
104
} else if let Some ( ( _, pattern) ) = line. split_once ( "//[" ) {
@@ -189,7 +182,22 @@ impl Comments {
189
182
Ok ( this)
190
183
}
191
184
192
- fn parse_command_with_args ( & mut self , command : & str , args : & str , l : usize ) -> Result < ( ) > {
185
+ fn parse_command ( & mut self , command : & str , l : usize ) -> Result < ( ) > {
186
+ // Commands are letters or dashes, grab everything until the first character that is neither of those.
187
+ let ( command, args) = match command. chars ( ) . position ( |c : char | !c. is_alphabetic ( ) && c != '-' ) {
188
+ None => ( command, "" ) ,
189
+ Some ( i) => {
190
+ let ( command, args) = command. split_at ( i) ;
191
+ let mut args = args. chars ( ) ;
192
+ let next = args. next ( ) . expect ( "the `position` above guarantees that there is at least one char" ) ;
193
+ let args = match next {
194
+ ':' | ' ' => args. as_str ( ) ,
195
+ _ => bail ! ( "expected space or `:`, got `{next}`" ) ,
196
+ } ;
197
+ ( command, args)
198
+ }
199
+ } ;
200
+
193
201
match command {
194
202
"revisions" => {
195
203
ensure ! ( self . revisions. is_none( ) , "cannot specifiy revisions twice" ) ;
@@ -222,30 +230,25 @@ impl Comments {
222
230
) ;
223
231
self . error_pattern = Some ( ( args. trim ( ) . to_string ( ) , l) ) ;
224
232
}
225
- // Maybe the user just left a comment explaining a command without arguments
226
- _ => self . parse_command ( command) ?,
227
- }
228
- Ok ( ( ) )
229
- }
230
-
231
- fn parse_command ( & mut self , command : & str ) -> Result < ( ) > {
232
- if let Some ( s) = command. strip_prefix ( "ignore-" ) {
233
- self . ignore . push ( Condition :: parse ( s) ) ;
234
- return Ok ( ( ) ) ;
235
- }
236
-
237
- if let Some ( s) = command. strip_prefix ( "only-" ) {
238
- self . only . push ( Condition :: parse ( s) ) ;
239
- return Ok ( ( ) ) ;
240
- }
233
+ "stderr-per-bitwidth" => {
234
+ ensure ! ( !self . stderr_per_bitwidth, "cannot specifiy stderr-per-bitwidth twice" ) ;
235
+ self . stderr_per_bitwidth = true ;
236
+ }
237
+ command => {
238
+ if let Some ( s) = command. strip_prefix ( "ignore-" ) {
239
+ self . ignore . push ( Condition :: parse ( s) ) ;
240
+ return Ok ( ( ) ) ;
241
+ }
241
242
242
- if command. starts_with ( "stderr-per-bitwidth" ) {
243
- ensure ! ( !self . stderr_per_bitwidth, "cannot specifiy stderr-per-bitwidth twice" ) ;
244
- self . stderr_per_bitwidth = true ;
245
- return Ok ( ( ) ) ;
243
+ if let Some ( s) = command. strip_prefix ( "only-" ) {
244
+ self . only . push ( Condition :: parse ( s) ) ;
245
+ return Ok ( ( ) ) ;
246
+ }
247
+ bail ! ( "unknown command {command}" ) ;
248
+ }
246
249
}
247
250
248
- bail ! ( "unknown command {command}" ) ;
251
+ Ok ( ( ) )
249
252
}
250
253
251
254
fn parse_pattern (
0 commit comments