1
1
use crate :: parser:: { ParseArg , Parser } ;
2
- use proc_macro2:: { token_stream, Delimiter , Ident , Literal , Span , TokenStream , TokenTree } ;
3
2
use proc_macro_error2:: abort;
3
+ use proc_macro2:: { Delimiter , Ident , Literal , Span , TokenStream , TokenTree , token_stream} ;
4
4
use quote:: quote;
5
5
use std:: iter:: Peekable ;
6
6
use std:: str:: Chars ;
@@ -65,7 +65,7 @@ pub fn scan_str_lit(lit: &Literal) -> TokenStream {
65
65
// If it's braced, we might have a format specifier or it might just be empty braces.
66
66
if chars. peek ( ) == Some ( & ':' ) {
67
67
chars. next ( ) ; // Consume ':'
68
- // Read the format specifier until '}'
68
+ // Read the format specifier until '}'
69
69
while let Some ( & c) = chars. peek ( ) {
70
70
if c == '}' {
71
71
break ;
@@ -290,14 +290,13 @@ impl Lexer {
290
290
self . extend_last_arg ( quote ! ( #ss. into_os_string( ) ) ) ;
291
291
} else {
292
292
let mut is_redirect = false ;
293
- if s == "1" || s == "2" {
294
- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
295
- if p. as_char ( ) == '>' {
296
- self . iter . next ( ) ;
297
- self . scan_redirect_out ( if s == "1" { 1 } else { 2 } ) ;
298
- is_redirect = true ;
299
- }
300
- }
293
+ if ( s == "1" || s == "2" )
294
+ && let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
295
+ && p. as_char ( ) == '>'
296
+ {
297
+ self . iter . next ( ) ;
298
+ self . scan_redirect_out ( if s == "1" { 1 } else { 2 } ) ;
299
+ is_redirect = true ;
301
300
}
302
301
if !is_redirect {
303
302
self . extend_last_arg ( quote ! ( #s) ) ;
@@ -306,15 +305,15 @@ impl Lexer {
306
305
}
307
306
308
307
fn scan_pipe ( & mut self ) {
309
- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
310
- if p. as_char ( ) == '&' {
311
- if let Some ( ref redirect) = self . last_redirect {
312
- abort ! ( redirect. 1 , "invalid '&': found previous redirect" ) ;
313
- }
314
- Self :: check_set_redirect ( & mut self . seen_redirect . 2 , "stderr" , p. span ( ) ) ;
315
- self . args . push ( ParseArg :: RedirectFd ( 2 , 1 ) ) ;
316
- self . iter . next ( ) ;
308
+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
309
+ && p. as_char ( ) == '&'
310
+ {
311
+ if let Some ( ref redirect) = self . last_redirect {
312
+ abort ! ( redirect. 1 , "invalid '&': found previous redirect" ) ;
317
313
}
314
+ Self :: check_set_redirect ( & mut self . seen_redirect . 2 , "stderr" , p. span ( ) ) ;
315
+ self . args . push ( ParseArg :: RedirectFd ( 2 , 1 ) ) ;
316
+ self . iter . next ( ) ;
318
317
}
319
318
320
319
// expect new command
@@ -342,29 +341,29 @@ impl Lexer {
342
341
RedirectFd :: Stderr { append }
343
342
} ,
344
343
) ;
345
- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
346
- if p. as_char ( ) == '&' {
347
- if append {
348
- abort ! ( p. span( ) , "raw fd not allowed for append redirection" ) ;
344
+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
345
+ && p. as_char ( ) == '&'
346
+ {
347
+ if append {
348
+ abort ! ( p. span( ) , "raw fd not allowed for append redirection" ) ;
349
+ }
350
+ self . iter . next ( ) ;
351
+ if let Some ( TokenTree :: Literal ( lit) ) = self . iter . peek_no_gap ( ) {
352
+ let s = lit. to_string ( ) ;
353
+ if s. starts_with ( '\"' ) || s. starts_with ( 'r' ) {
354
+ abort ! ( lit. span( ) , "invalid literal string after &" ) ;
349
355
}
350
- self . iter . next ( ) ;
351
- if let Some ( TokenTree :: Literal ( lit) ) = self . iter . peek_no_gap ( ) {
352
- let s = lit. to_string ( ) ;
353
- if s. starts_with ( '\"' ) || s. starts_with ( 'r' ) {
354
- abort ! ( lit. span( ) , "invalid literal string after &" ) ;
355
- }
356
- if & s == "1" {
357
- self . args . push ( ParseArg :: RedirectFd ( fd, 1 ) ) ;
358
- } else if & s == "2" {
359
- self . args . push ( ParseArg :: RedirectFd ( fd, 2 ) ) ;
360
- } else {
361
- abort ! ( lit. span( ) , "Only &1 or &2 is supported" ) ;
362
- }
363
- self . last_redirect = None ;
364
- self . iter . next ( ) ;
356
+ if & s == "1" {
357
+ self . args . push ( ParseArg :: RedirectFd ( fd, 1 ) ) ;
358
+ } else if & s == "2" {
359
+ self . args . push ( ParseArg :: RedirectFd ( fd, 2 ) ) ;
365
360
} else {
366
- abort ! ( self . iter . span( ) , "expect &1 or &2" ) ;
361
+ abort ! ( lit . span( ) , "Only &1 or &2 is supported " ) ;
367
362
}
363
+ self . last_redirect = None ;
364
+ self . iter . next ( ) ;
365
+ } else {
366
+ abort ! ( self . iter. span( ) , "expect &1 or &2" ) ;
368
367
}
369
368
}
370
369
}
@@ -436,11 +435,11 @@ impl Lexer {
436
435
437
436
fn check_append ( & mut self ) -> bool {
438
437
let mut append = false ;
439
- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
440
- if p. as_char ( ) == '>' {
441
- append = true ;
442
- self . iter . next ( ) ;
443
- }
438
+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
439
+ && p. as_char ( ) == '>'
440
+ {
441
+ append = true ;
442
+ self . iter . next ( ) ;
444
443
}
445
444
append
446
445
}
0 commit comments