Simplify creating a parser from a token tree

Closes #15306
This commit is contained in:
Piotr Jawniak
2014-07-03 11:42:24 +02:00
committed by Alex Crichton
parent 4a6fcc51a0
commit 2f355b79dd
8 changed files with 14 additions and 46 deletions

View File

@@ -15,6 +15,7 @@ use codemap::{CodeMap, Span, ExpnInfo};
use ext;
use ext::expand;
use parse;
use parse::parser;
use parse::token;
use parse::token::{InternedString, intern, str_to_ident};
use util::small_vector::SmallVector;
@@ -433,6 +434,11 @@ impl<'a> ExtCtxt<'a> {
}
}
pub fn new_parser_from_tts(&self, tts: &[ast::TokenTree])
-> parser::Parser<'a> {
parse::tts_to_parser(self.parse_sess, Vec::from_slice(tts), self.cfg())
}
pub fn codemap(&self) -> &'a CodeMap { &self.parse_sess.span_diagnostic.cm }
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
@@ -586,11 +592,7 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt,
pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree]) -> Option<Vec<Gc<ast::Expr>>> {
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
tts.iter()
.map(|x| (*x).clone())
.collect());
let mut p = cx.new_parser_from_tts(tts);
let mut es = Vec::new();
while p.token != token::EOF {
es.push(cx.expand_expr(p.parse_expr()));