1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 use ext::build::AstBuilder;
17 use std::strbuf::StrBuf;
19 pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
21 tts: &[ast::TokenTree])
22 -> Box<base::MacResult> {
23 let es = match base::get_exprs_from_tts(cx, sp, tts) {
25 None => return base::DummyResult::expr(sp)
27 let mut accumulator = StrBuf::new();
28 for e in es.move_iter() {
30 ast::ExprLit(lit) => {
32 ast::LitStr(ref s, _) |
33 ast::LitFloat(ref s, _) |
34 ast::LitFloatUnsuffixed(ref s) => {
35 accumulator.push_str(s.get());
38 accumulator.push_char(c);
40 ast::LitInt(i, _) | ast::LitIntUnsuffixed(i) => {
41 accumulator.push_str(format!("{}", i));
43 ast::LitUint(u, _) => {
44 accumulator.push_str(format!("{}", u));
48 accumulator.push_str(format!("{}", b));
50 ast::LitBinary(..) => {
51 cx.span_err(e.span, "cannot concatenate a binary literal");
56 cx.span_err(e.span, "expected a literal");
60 base::MacExpr::new(cx.expr_str(
62 token::intern_and_get_ident(accumulator.into_owned())))