@@ -320,6 +320,8 @@ define function tokens-remaining?
320
320
~parser.parser-tokens.empty?
321
321
end ;
322
322
323
+ // TODO(cgay): This says it returns false-or, but it doesn't. I think it would be an
324
+ // improvement to make it do that and get rid of tokens-remaining?.
323
325
define function peek-token
324
326
(parser :: <command>) => (token :: false-or (<token>))
325
327
unless (tokens-remaining?(parser))
@@ -611,8 +613,8 @@ define function tokenize-args
611
613
end
612
614
end ,
613
615
// Add a token to our deque
614
- method token (class :: <class> , value :: <string> ,
615
- #rest keys, #key , #all-keys ) => ()
616
+ method add- token (class :: <class> , value :: <string> ,
617
+ #rest keys, #key , #all-keys ) => ()
616
618
apply (add-argument-token, parser, class , value, keys);
617
619
end ,
618
620
method parse-short-option (arg)
@@ -624,14 +626,13 @@ define function tokenize-args
624
626
& opt.option-might-have-parameters?
625
627
& i + 1 < arg.size )
626
628
// Take rest of argument, and use it as a parameter.
627
- token(<short-option-token>, name, tightly-bound?: #t );
628
- token(<argument-token>,
629
- copy-sequence (arg, start: i + 1 ));
629
+ add-token(<short-option-token>, name, tightly-bound?: #t );
630
+ add-token(<argument-token>, copy-sequence (arg, start: i + 1 ));
630
631
done();
631
632
else
632
- // A solitary option with no parameter.
633
- // TODO(cgay): why do we not exit the loop here??
634
- token(<short-option-token>, name);
633
+ // A solitary option with no parameter. Do not exit the loop because there
634
+ // may be multiple short options strung together as in 'ls -ltR'.
635
+ add- token(<short-option-token>, name);
635
636
end if ;
636
637
end for ;
637
638
end block ;
@@ -640,22 +641,22 @@ define function tokenize-args
640
641
let arg = pop (args);
641
642
case
642
643
(arg = "=" ) =>
643
- token(<equals-token>, "=" );
644
- token(<argument-token>, next-arg());
644
+ add- token(<equals-token>, "=" );
645
+ add- token(<argument-token>, next-arg());
645
646
646
647
starts-with?(arg, "--" ) =>
647
- token(<long-option-token>, copy-sequence (arg, start: 2 ));
648
+ add- token(<long-option-token>, copy-sequence (arg, start: 2 ));
648
649
649
650
starts-with?(arg, "-" ) =>
650
651
if (arg.size = 1 )
651
652
// Probably a fake filename representing stdin ('cat -')
652
- token(<argument-token>, "-" );
653
+ add- token(<argument-token>, "-" );
653
654
else
654
655
parse-short-option(arg);
655
656
end if ;
656
657
657
658
otherwise =>
658
- token(<argument-token>, arg);
659
+ add- token(<argument-token>, arg);
659
660
end case ;
660
661
end until ;
661
662
end function tokenize-args;
0 commit comments