Implement ignore and index metavar expression

This commit is contained in:
Jonas Schievink 2022-07-11 18:31:42 +02:00
parent f7bb9327ad
commit df66eb74ab
7 changed files with 108 additions and 5 deletions

View file

@ -103,6 +103,23 @@ fn expand_subtree(
err = err.or(e);
push_fragment(arena, fragment)
}
Op::Ignore { name, id } => {
// Expand the variable, but ignore the result. This registers the repetition count.
expand_var(ctx, name, *id);
}
Op::Index { depth } => {
let index = ctx
.nesting
.get(ctx.nesting.len() - 1 - (*depth as usize))
.map_or(0, |nest| nest.idx);
arena.push(
tt::Leaf::Literal(tt::Literal {
text: index.to_string().into(),
id: tt::TokenId::unspecified(),
})
.into(),
);
}
}
}
// drain the elements added in this instance of expand_subtree