fix one remaining token comparison, refactor token comparison to avoid == check

This commit is contained in:
John Clements 2013-07-10 11:52:39 -07:00
parent e29d25338d
commit bc2a44daf1

View File

@ -234,16 +234,12 @@ pub fn parse_or_else(
}
}
// temporary for testing
// perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
if (*t1 == *t2) {
true
} else {
match (t1,t2) {
(&token::IDENT(id1,_),&token::IDENT(id2,_)) =>
id1.name == id2.name,
_ => false
}
match (t1,t2) {
(&token::IDENT(id1,_),&token::IDENT(id2,_)) =>
id1.name == id2.name,
_ => *t1 == *t2
}
}
@ -310,7 +306,10 @@ pub fn parse(
// the *_t vars are workarounds for the lack of unary move
match ei.sep {
Some(ref t) if idx == len => { // we need a separator
if tok == (*t) { //pass the separator
// i'm conflicted about whether this should be hygienic....
// though in this case, if the separators are never legal
// idents, it shouldn't matter.
if token_name_eq(&tok, t) { //pass the separator
let mut ei_t = ei.clone();
ei_t.idx += 1;
next_eis.push(ei_t);
@ -367,7 +366,7 @@ pub fn parse(
}
/* error messages here could be improved with links to orig. rules */
if tok == EOF {
if token_name_eq(&tok, &EOF) {
if eof_eis.len() == 1u {
let mut v = ~[];
for dv in eof_eis[0u].matches.mut_iter() {