diff options
| author | Piotr Jawniak <sawyer47@gmail.com> | 2014-07-03 11:42:24 +0200 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-03 12:54:52 -0700 |
| commit | 2f355b79ddb49c45fb3396352f464458ad867234 (patch) | |
| tree | 78f9a16d24171326b08c22b354077b06a92e46ea /src/libsyntax/ext/base.rs | |
| parent | 4a6fcc51a063a49c1b7a330828c857849d1e3119 (diff) | |
| download | rust-2f355b79ddb49c45fb3396352f464458ad867234.tar.gz rust-2f355b79ddb49c45fb3396352f464458ad867234.zip | |
Simplify creating a parser from a token tree
Closes #15306
Diffstat (limited to 'src/libsyntax/ext/base.rs')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index ab5d7021746..d2e69204d33 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -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())); |
