Add a KleeneOp enum for clarity

This commit is contained in:
Brendan Zabarauskas 2014-10-23 11:24:20 +11:00
parent 34dacb80ce
commit 94d6eee335
6 changed files with 42 additions and 30 deletions

View file

@ -323,9 +323,9 @@ pub fn parse(sess: &ParseSess,
} else {
match ei.elts[idx].node.clone() {
/* need to descend into sequence */
MatchSeq(ref matchers, ref sep, zero_ok,
MatchSeq(ref matchers, ref sep, kleene_op,
match_idx_lo, match_idx_hi) => {
if zero_ok {
if kleene_op == ast::ZeroOrMore {
let mut new_ei = ei.clone();
new_ei.idx += 1u;
//we specifically matched zero repeats.

View file

@ -232,10 +232,11 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt,
ms(MatchSeq(vec!(
ms(MatchNonterminal(lhs_nm, special_idents::matchers, 0u)),
ms(MatchTok(FAT_ARROW)),
ms(MatchNonterminal(rhs_nm, special_idents::tt, 1u))), Some(SEMI), false, 0u, 2u)),
ms(MatchNonterminal(rhs_nm, special_idents::tt, 1u))), Some(SEMI),
ast::OneOrMore, 0u, 2u)),
//to phase into semicolon-termination instead of
//semicolon-separation
ms(MatchSeq(vec!(ms(MatchTok(SEMI))), None, true, 2u, 2u)));
ms(MatchSeq(vec!(ms(MatchTok(SEMI))), None, ast::ZeroOrMore, 2u, 2u)));
// Parse the macro_rules! invocation (`none` is for no interpolations):

View file

@ -227,9 +227,9 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
r.stack.last_mut().unwrap().idx += 1;
return ret_val;
}
TtSequence(sp, tts, sep, zerok) => {
TtSequence(sp, tts, sep, kleene_op) => {
// FIXME(pcwalton): Bad copy.
match lockstep_iter_size(&TtSequence(sp, tts.clone(), sep.clone(), zerok), r) {
match lockstep_iter_size(&TtSequence(sp, tts.clone(), sep.clone(), kleene_op), r) {
LisUnconstrained => {
r.sp_diag.span_fatal(
sp.clone(), /* blame macro writer */
@ -243,7 +243,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
}
LisConstraint(len, _) => {
if len == 0 {
if !zerok {
if kleene_op == ast::OneOrMore {
// FIXME #2887 blame invoker
r.sp_diag.span_fatal(sp.clone(),
"this must repeat at least once");