Add empty bindings and some refactoring

This commit is contained in:
Edwin Cheng 2019-05-02 23:23:14 +08:00
parent 9901f3e45e
commit 1446d620c5
2 changed files with 41 additions and 22 deletions

View file

@ -99,13 +99,31 @@ pub(crate) struct Subtree {
pub(crate) token_trees: Vec<TokenTree>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Eq)]
pub(crate) enum Separator {
Literal(tt::Literal),
Ident(tt::Ident),
Puncts(SmallVec<[tt::Punct; 3]>),
}
// Note that when we compare a Separator, we just care about its textual value.
impl PartialEq for crate::Separator {
fn eq(&self, other: &crate::Separator) -> bool {
use crate::Separator::*;
match (self, other) {
(Ident(ref a), Ident(ref b)) => a == b,
(Literal(ref a), Literal(ref b)) => a == b,
(Puncts(ref a), Puncts(ref b)) if a.len() == b.len() => {
let a_iter = a.iter().map(|a| a.char);
let b_iter = b.iter().map(|b| b.char);
a_iter.eq(b_iter)
}
_ => false,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct Repeat {
pub(crate) subtree: Subtree,