Remove FlattenNtFolder
The tests pass without it, so 🤷
This commit is contained in:
parent
dde603757d
commit
0ec0950c5f
1 changed files with 3 additions and 22 deletions
|
@ -2,9 +2,8 @@ use std::mem;
|
||||||
use syntax::ast::LitKind;
|
use syntax::ast::LitKind;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::fold::Folder;
|
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
use syntax::parse::token::{BinOpToken, DelimToken, Nonterminal, Token};
|
use syntax::parse::token::{BinOpToken, DelimToken, Token};
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::keywords;
|
||||||
use syntax::tokenstream::{Delimited, TokenStream, TokenTree};
|
use syntax::tokenstream::{Delimited, TokenStream, TokenTree};
|
||||||
|
@ -63,37 +62,19 @@ macro_rules! keyword {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(cx: &ExtCtxt, sp: Span, input: &[TokenTree]) -> ParseResult<Vec<TokenTree>> {
|
pub fn parse(cx: &ExtCtxt, sp: Span, input: &[TokenTree]) -> ParseResult<Vec<TokenTree>> {
|
||||||
let input: Vec<TokenTree> = FlattenNtFolder.fold_tts(input.iter().cloned().collect())
|
|
||||||
.into_trees().collect();
|
|
||||||
let mut render = Renderer::new(cx);
|
let mut render = Renderer::new(cx);
|
||||||
Parser {
|
Parser {
|
||||||
cx,
|
cx,
|
||||||
in_attr: false,
|
in_attr: false,
|
||||||
input: &input,
|
input: input,
|
||||||
span: sp,
|
span: sp,
|
||||||
}.markups(&mut render)?;
|
}.markups(&mut render)?;
|
||||||
// Heuristic: the size of the resulting markup tends to correlate with the
|
// Heuristic: the size of the resulting markup tends to correlate with the
|
||||||
// code size of the template itself
|
// code size of the template itself
|
||||||
let size_hint = pprust::tts_to_string(&input).len();
|
let size_hint = pprust::tts_to_string(input).len();
|
||||||
Ok(render.into_expr(size_hint).into_trees().collect())
|
Ok(render.into_expr(size_hint).into_trees().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FlattenNtFolder;
|
|
||||||
|
|
||||||
impl Folder for FlattenNtFolder {
|
|
||||||
fn fold_tt(&mut self, tt: TokenTree) -> TokenTree {
|
|
||||||
let mut tt = &tt;
|
|
||||||
while let TokenTree::Token(_, Token::Interpolated(ref nt)) = *tt {
|
|
||||||
if let Nonterminal::NtTT(ref sub_tt) = **nt {
|
|
||||||
tt = sub_tt;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tt.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Parser<'cx, 'a: 'cx, 'i> {
|
struct Parser<'cx, 'a: 'cx, 'i> {
|
||||||
cx: &'cx ExtCtxt<'a>,
|
cx: &'cx ExtCtxt<'a>,
|
||||||
in_attr: bool,
|
in_attr: bool,
|
||||||
|
|
Loading…
Add table
Reference in a new issue