Skip to content

Commit f59b821

Browse files
committed
Attempted fix for ? kleene op
1 parent 5ac48ec commit f59b821

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ struct MatcherPos {
181181
match_hi: usize,
182182

183183
// Specifically used if we are matching a repetition. If we aren't both should be `None`.
184+
/// The KleeneOp of this sequence if we are in a repetition.
185+
seq_op: Option<quoted::KleeneOp>,
184186
/// The separator if we are in a repetition
185187
sep: Option<Token>,
186188
/// The "parent" matcher position if we are in a repetition. That is, the matcher position just
@@ -263,6 +265,7 @@ fn initial_matcher_pos(ms: Vec<TokenTree>, lo: BytePos) -> Box<MatcherPos> {
263265
stack: vec![],
264266

265267
// Haven't descended into any sequences, so both of these are `None`.
268+
seq_op: None,
266269
sep: None,
267270
up: None,
268271
})
@@ -464,10 +467,11 @@ fn inner_parse_loop(
464467
item.idx += 1;
465468
next_items.push(item);
466469
}
467-
}
470+
}
468471
// We don't need a separator. Move the "dot" back to the beginning of the matcher
469-
// and try to match again.
470-
else {
472+
// and try to match again UNLESS we are only allowed to have _one_ repetition.
473+
else if item.seq_op != Some(quoted::KleeneOp::ZeroOrOne) {
474+
// we don't need a separator
471475
item.match_cur = item.match_lo;
472476
item.idx = 0;
473477
cur_items.push(item);
@@ -499,26 +503,20 @@ fn inner_parse_loop(
499503
cur_items.push(new_item);
500504
}
501505

502-
// For ZeroOrMore and OneOrMore, we want to examine the case were there is at
503-
// least one match. For ZeroOrOne, we only want the case where there is exactly
504-
// one match.
505-
if (seq.op == quoted::KleeneOp::ZeroOrOne && seq.num_captures == 1)
506-
|| seq.op != quoted::KleeneOp::ZeroOrOne
507-
{
508-
let matches = create_matches(item.matches.len());
509-
cur_items.push(Box::new(MatcherPos {
510-
stack: vec![],
511-
sep: seq.separator.clone(),
512-
idx: 0,
513-
matches,
514-
match_lo: item.match_cur,
515-
match_cur: item.match_cur,
516-
match_hi: item.match_cur + seq.num_captures,
517-
up: Some(item),
518-
sp_lo: sp.lo(),
519-
top_elts: Tt(TokenTree::Sequence(sp, seq)),
520-
}));
521-
}
506+
let matches = create_matches(item.matches.len());
507+
cur_items.push(Box::new(MatcherPos {
508+
stack: vec![],
509+
sep: seq.separator.clone(),
510+
seq_op: Some(seq.op),
511+
idx: 0,
512+
matches,
513+
match_lo: item.match_cur,
514+
match_cur: item.match_cur,
515+
match_hi: item.match_cur + seq.num_captures,
516+
up: Some(item),
517+
sp_lo: sp.lo(),
518+
top_elts: Tt(TokenTree::Sequence(sp, seq)),
519+
}));
522520
}
523521

524522
// We need to match a metavar (but the identifier is invalid)... this is an error

0 commit comments

Comments
 (0)