Avoid interpolated token trees.
This commit is contained in:
parent
6a9248fc15
commit
57c0ed097c
@ -480,23 +480,8 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
||||
match name {
|
||||
"tt" => {
|
||||
p.quote_depth += 1; //but in theory, non-quoted tts might be useful
|
||||
let mut tt = panictry!(p.parse_token_tree());
|
||||
let tt = panictry!(p.parse_token_tree());
|
||||
p.quote_depth -= 1;
|
||||
while let TokenTree::Token(sp, token::Interpolated(nt)) = tt {
|
||||
if let token::NtTT(..) = *nt {
|
||||
match Rc::try_unwrap(nt) {
|
||||
Ok(token::NtTT(sub_tt)) => tt = sub_tt,
|
||||
Ok(_) => unreachable!(),
|
||||
Err(nt_rc) => match *nt_rc {
|
||||
token::NtTT(ref sub_tt) => tt = sub_tt.clone(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
tt = TokenTree::Token(sp, token::Interpolated(nt.clone()));
|
||||
break
|
||||
}
|
||||
}
|
||||
return token::NtTT(tt);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -12,7 +12,7 @@ use self::LockstepIterSize::*;
|
||||
use ast::Ident;
|
||||
use errors::Handler;
|
||||
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
||||
use parse::token::{self, MatchNt, SubstNt, Token, NtIdent};
|
||||
use parse::token::{self, MatchNt, SubstNt, Token, NtIdent, NtTT};
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use tokenstream::{self, TokenTree};
|
||||
use util::small_vector::SmallVector;
|
||||
@ -241,6 +241,7 @@ fn tt_next_token(r: &mut TtReader, prev_span: Span) -> Option<TokenTree> {
|
||||
NtIdent(ref sn) => {
|
||||
return Some(TokenTree::Token(sn.span, token::Ident(sn.node)));
|
||||
}
|
||||
NtTT(ref tt) => return Some(tt.clone()),
|
||||
_ => {
|
||||
// FIXME(pcwalton): Bad copy
|
||||
return Some(TokenTree::Token(sp, token::Interpolated(nt.clone())));
|
||||
|
@ -306,8 +306,8 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn next_tok(&mut self) -> TokenAndSpan {
|
||||
'outer: loop {
|
||||
let mut tok = if let Some((tts, i)) = self.tts.pop() {
|
||||
loop {
|
||||
let tok = if let Some((tts, i)) = self.tts.pop() {
|
||||
let tt = tts.get_tt(i);
|
||||
if i + 1 < tts.len() {
|
||||
self.tts.push((tts, i + 1));
|
||||
@ -322,25 +322,11 @@ impl<'a> Parser<'a> {
|
||||
TokenAndSpan { tok: token::Eof, sp: self.span }
|
||||
};
|
||||
|
||||
loop {
|
||||
let nt = match tok.tok {
|
||||
token::Interpolated(ref nt) => nt.clone(),
|
||||
token::DocComment(name) if self.desugar_doc_comments => {
|
||||
self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0));
|
||||
continue 'outer
|
||||
}
|
||||
_ => return tok,
|
||||
};
|
||||
match *nt {
|
||||
token::NtTT(TokenTree::Token(sp, ref t)) => {
|
||||
tok = TokenAndSpan { tok: t.clone(), sp: sp };
|
||||
}
|
||||
token::NtTT(ref tt) => {
|
||||
self.tts.push((tt.clone(), 0));
|
||||
continue 'outer
|
||||
}
|
||||
_ => return tok,
|
||||
match tok.tok {
|
||||
token::DocComment(name) if self.desugar_doc_comments => {
|
||||
self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0));
|
||||
}
|
||||
_ => return tok,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user