1
Fork 0

Refactor parse_nt.

This commit is contained in:
Mark-Simulacrum 2016-11-10 17:30:01 -07:00
parent 68abb24e8d
commit 27c09864bd

View file

@ -479,14 +479,19 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
p.quote_depth += 1; //but in theory, non-quoted tts might be useful p.quote_depth += 1; //but in theory, non-quoted tts might be useful
let mut tt = panictry!(p.parse_token_tree()); let mut tt = panictry!(p.parse_token_tree());
p.quote_depth -= 1; p.quote_depth -= 1;
loop { while let TokenTree::Token(sp, token::Interpolated(nt)) = tt {
let nt = match tt { if let token::NtTT(..) = *nt {
TokenTree::Token(_, token::Interpolated(ref nt)) => nt.clone(), match Rc::try_unwrap(nt) {
_ => break, Ok(token::NtTT(sub_tt)) => tt = sub_tt,
}; Ok(_) => unreachable!(),
match *nt { Err(nt_rc) => match *nt_rc {
token::NtTT(ref sub_tt) => tt = sub_tt.clone(), token::NtTT(ref sub_tt) => tt = sub_tt.clone(),
_ => break, _ => unreachable!(),
},
}
} else {
tt = TokenTree::Token(sp, token::Interpolated(nt.clone()));
break
} }
} }
return token::NtTT(tt); return token::NtTT(tt);