@@ -486,8 +486,8 @@ fn inner_parse_loop(
486
486
match item. top_elts . get_tt ( idx) {
487
487
// Need to descend into a sequence
488
488
TokenTree :: Sequence ( sp, seq) => {
489
- if seq . op == quoted :: KleeneOp :: ZeroOrMore {
490
- // Examine the case where there are 0 matches of this sequence
489
+ // Examine the case where there are 0 matches of this sequence
490
+ if seq . op == quoted :: KleeneOp :: ZeroOrMore || seq . op == quoted :: KleeneOp :: ZeroOrOne {
491
491
let mut new_item = item. clone ( ) ;
492
492
new_item. match_cur += seq. num_captures ;
493
493
new_item. idx += 1 ;
@@ -497,20 +497,26 @@ fn inner_parse_loop(
497
497
cur_items. push ( new_item) ;
498
498
}
499
499
500
- // Examine the case where there is at least one match of this sequence
501
- let matches = create_matches ( item. matches . len ( ) ) ;
502
- cur_items. push ( Box :: new ( MatcherPos {
503
- stack : vec ! [ ] ,
504
- sep : seq. separator . clone ( ) ,
505
- idx : 0 ,
506
- matches,
507
- match_lo : item. match_cur ,
508
- match_cur : item. match_cur ,
509
- match_hi : item. match_cur + seq. num_captures ,
510
- up : Some ( item) ,
511
- sp_lo : sp. lo ( ) ,
512
- top_elts : Tt ( TokenTree :: Sequence ( sp, seq) ) ,
513
- } ) ) ;
500
+ // For ZeroOrMore and OneOrMore, we want to examine the case were there is at
501
+ // least one match. For ZeroOrOne, we only want the case where there is exactly
502
+ // one match.
503
+ if ( seq. op == quoted:: KleeneOp :: ZeroOrOne && seq. num_captures == 1 ) ||
504
+ seq. op != quoted:: KleeneOp :: ZeroOrOne {
505
+
506
+ let matches = create_matches ( item. matches . len ( ) ) ;
507
+ cur_items. push ( Box :: new ( MatcherPos {
508
+ stack : vec ! [ ] ,
509
+ sep : seq. separator . clone ( ) ,
510
+ idx : 0 ,
511
+ matches,
512
+ match_lo : item. match_cur ,
513
+ match_cur : item. match_cur ,
514
+ match_hi : item. match_cur + seq. num_captures ,
515
+ up : Some ( item) ,
516
+ sp_lo : sp. lo ( ) ,
517
+ top_elts : Tt ( TokenTree :: Sequence ( sp, seq) ) ,
518
+ } ) ) ;
519
+ }
514
520
}
515
521
516
522
// We need to match a metavar (but the identifier is invalid)... this is an error
0 commit comments