Update the macro parser to allow at most once repetitions for ?
Kleene
This commit is contained in:
parent
760879bc88
commit
bb8110c1fc
1 changed files with 22 additions and 16 deletions
|
@ -486,8 +486,8 @@ fn inner_parse_loop(
|
|||
match item.top_elts.get_tt(idx) {
|
||||
// Need to descend into a sequence
|
||||
TokenTree::Sequence(sp, seq) => {
|
||||
if seq.op == quoted::KleeneOp::ZeroOrMore {
|
||||
// Examine the case where there are 0 matches of this sequence
|
||||
if seq.op == quoted::KleeneOp::ZeroOrMore || seq.op == quoted::KleeneOp::ZeroOrOne {
|
||||
let mut new_item = item.clone();
|
||||
new_item.match_cur += seq.num_captures;
|
||||
new_item.idx += 1;
|
||||
|
@ -497,7 +497,12 @@ fn inner_parse_loop(
|
|||
cur_items.push(new_item);
|
||||
}
|
||||
|
||||
// Examine the case where there is at least one match of this sequence
|
||||
// For ZeroOrMore and OneOrMore, we want to examine the case were there is at
|
||||
// least one match. For ZeroOrOne, we only want the case where there is exactly
|
||||
// one match.
|
||||
if (seq.op == quoted::KleeneOp::ZeroOrOne && seq.num_captures == 1) ||
|
||||
seq.op != quoted::KleeneOp::ZeroOrOne {
|
||||
|
||||
let matches = create_matches(item.matches.len());
|
||||
cur_items.push(Box::new(MatcherPos {
|
||||
stack: vec![],
|
||||
|
@ -512,6 +517,7 @@ fn inner_parse_loop(
|
|||
top_elts: Tt(TokenTree::Sequence(sp, seq)),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// We need to match a metavar (but the identifier is invalid)... this is an error
|
||||
TokenTree::MetaVarDecl(span, _, id) if id.name == keywords::Invalid.name() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue