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) {
|
match item.top_elts.get_tt(idx) {
|
||||||
// Need to descend into a sequence
|
// Need to descend into a sequence
|
||||||
TokenTree::Sequence(sp, seq) => {
|
TokenTree::Sequence(sp, seq) => {
|
||||||
if seq.op == quoted::KleeneOp::ZeroOrMore {
|
// Examine the case where there are 0 matches of this sequence
|
||||||
// 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();
|
let mut new_item = item.clone();
|
||||||
new_item.match_cur += seq.num_captures;
|
new_item.match_cur += seq.num_captures;
|
||||||
new_item.idx += 1;
|
new_item.idx += 1;
|
||||||
|
@ -497,20 +497,26 @@ fn inner_parse_loop(
|
||||||
cur_items.push(new_item);
|
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
|
||||||
let matches = create_matches(item.matches.len());
|
// least one match. For ZeroOrOne, we only want the case where there is exactly
|
||||||
cur_items.push(Box::new(MatcherPos {
|
// one match.
|
||||||
stack: vec![],
|
if (seq.op == quoted::KleeneOp::ZeroOrOne && seq.num_captures == 1) ||
|
||||||
sep: seq.separator.clone(),
|
seq.op != quoted::KleeneOp::ZeroOrOne {
|
||||||
idx: 0,
|
|
||||||
matches,
|
let matches = create_matches(item.matches.len());
|
||||||
match_lo: item.match_cur,
|
cur_items.push(Box::new(MatcherPos {
|
||||||
match_cur: item.match_cur,
|
stack: vec![],
|
||||||
match_hi: item.match_cur + seq.num_captures,
|
sep: seq.separator.clone(),
|
||||||
up: Some(item),
|
idx: 0,
|
||||||
sp_lo: sp.lo(),
|
matches,
|
||||||
top_elts: Tt(TokenTree::Sequence(sp, seq)),
|
match_lo: item.match_cur,
|
||||||
}));
|
match_cur: item.match_cur,
|
||||||
|
match_hi: item.match_cur + seq.num_captures,
|
||||||
|
up: Some(item),
|
||||||
|
sp_lo: sp.lo(),
|
||||||
|
top_elts: Tt(TokenTree::Sequence(sp, seq)),
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to match a metavar (but the identifier is invalid)... this is an error
|
// We need to match a metavar (but the identifier is invalid)... this is an error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue