@@ -321,8 +321,8 @@ struct MatchState<'t> {
321
321
/// The KleeneOp of this sequence if we are in a repetition.
322
322
sep_kind : Option < RepeatKind > ,
323
323
324
- /// Number of tokens of separator parsed
325
- sep_parsed : Option < usize > ,
324
+ /// Whether we already matched separator token.
325
+ sep_matched : bool ,
326
326
327
327
/// Matched meta variables bindings
328
328
bindings : BindingsIdx ,
@@ -387,7 +387,7 @@ fn match_loop_inner<'t>(
387
387
None => {
388
388
// We are at or past the end of the matcher of `item`.
389
389
if let Some ( up) = & item. up {
390
- if item. sep_parsed . is_none ( ) {
390
+ if ! item. sep_matched {
391
391
// Get the `up` matcher
392
392
let mut new_pos = ( * * up) . clone ( ) ;
393
393
new_pos. bindings = bindings_builder. copy ( & new_pos. bindings ) ;
@@ -401,22 +401,25 @@ fn match_loop_inner<'t>(
401
401
}
402
402
403
403
// Check if we need a separator.
404
- // We check the separator one by one
405
- let sep_idx = item. sep_parsed . unwrap_or ( 0 ) ;
406
- let sep_len = item. sep . as_ref ( ) . map_or ( 0 , Separator :: tt_count) ;
407
- if item. sep . is_some ( ) && sep_idx != sep_len {
404
+ if item. sep . is_some ( ) && !item. sep_matched {
408
405
let sep = item. sep . as_ref ( ) . unwrap ( ) ;
409
- if src. clone ( ) . expect_separator ( sep, sep_idx) {
406
+ let mut fork = src. clone ( ) ;
407
+ if fork. expect_separator ( sep) {
408
+ // HACK: here we use `meta_result` to pass `TtIter` back to caller because
409
+ // it might have been advanced multiple times. `ValueResult` is
410
+ // insignificant.
411
+ item. meta_result = Some ( ( fork, ValueResult :: ok ( None ) ) ) ;
410
412
item. dot . next ( ) ;
411
- item. sep_parsed = Some ( sep_idx + 1 ) ;
413
+ // item.sep_parsed = Some(sep_len);
414
+ item. sep_matched = true ;
412
415
try_push ! ( next_items, item) ;
413
416
}
414
417
}
415
418
// We don't need a separator. Move the "dot" back to the beginning of the matcher
416
419
// and try to match again UNLESS we are only allowed to have _one_ repetition.
417
420
else if item. sep_kind != Some ( RepeatKind :: ZeroOrOne ) {
418
421
item. dot = item. dot . reset ( ) ;
419
- item. sep_parsed = None ;
422
+ item. sep_matched = false ;
420
423
bindings_builder. push_default ( & mut item. bindings ) ;
421
424
cur_items. push ( item) ;
422
425
}
@@ -451,7 +454,7 @@ fn match_loop_inner<'t>(
451
454
up : Some ( Box :: new ( item) ) ,
452
455
sep : separator. clone ( ) ,
453
456
sep_kind : Some ( * kind) ,
454
- sep_parsed : None ,
457
+ sep_matched : false ,
455
458
bindings : bindings_builder. alloc ( ) ,
456
459
meta_result : None ,
457
460
is_error : false ,
@@ -592,7 +595,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
592
595
up: None ,
593
596
sep: None ,
594
597
sep_kind: None ,
595
- sep_parsed : None ,
598
+ sep_matched : false ,
596
599
bindings: bindings_builder. alloc( ) ,
597
600
is_error: false ,
598
601
meta_result: None ,
@@ -864,26 +867,29 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
864
867
}
865
868
866
869
impl < ' a > TtIter < ' a > {
867
- fn expect_separator ( & mut self , separator : & Separator , idx : usize ) -> bool {
870
+ fn expect_separator ( & mut self , separator : & Separator ) -> bool {
868
871
let mut fork = self . clone ( ) ;
869
872
let ok = match separator {
870
- Separator :: Ident ( lhs) if idx == 0 => match fork. expect_ident_or_underscore ( ) {
873
+ Separator :: Ident ( lhs) => match fork. expect_ident_or_underscore ( ) {
871
874
Ok ( rhs) => rhs. text == lhs. text ,
872
875
Err ( _) => false ,
873
876
} ,
874
- Separator :: Literal ( lhs) if idx == 0 => match fork. expect_literal ( ) {
877
+ Separator :: Literal ( lhs) => match fork. expect_literal ( ) {
875
878
Ok ( rhs) => match rhs {
876
879
tt:: Leaf :: Literal ( rhs) => rhs. text == lhs. text ,
877
880
tt:: Leaf :: Ident ( rhs) => rhs. text == lhs. text ,
878
881
tt:: Leaf :: Punct ( _) => false ,
879
882
} ,
880
883
Err ( _) => false ,
881
884
} ,
882
- Separator :: Puncts ( lhss) if idx < lhss. len ( ) => match fork. expect_single_punct ( ) {
883
- Ok ( rhs) => rhs. char == lhss[ idx] . char ,
885
+ Separator :: Puncts ( lhs) => match fork. expect_glued_punct ( ) {
886
+ Ok ( rhs) => {
887
+ let lhs = lhs. iter ( ) . map ( |it| it. char ) ;
888
+ let rhs = rhs. iter ( ) . map ( |it| it. char ) ;
889
+ lhs. eq ( rhs)
890
+ }
884
891
Err ( _) => false ,
885
892
} ,
886
- _ => false ,
887
893
} ;
888
894
if ok {
889
895
* self = fork;
0 commit comments