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::string::String;
19 pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
21 tts: &[ast::TokenTree])
22 -> Box<base::MacResult+'static> {
23 let es = match base::get_exprs_from_tts(cx, sp, tts) {
25 None => return base::DummyResult::expr(sp)
27 let mut accumulator = String::new();
30 ast::ExprLit(ref lit) => {
32 ast::LitStr(ref s, _) |
33 ast::LitFloat(ref s, _) |
34 ast::LitFloatUnsuffixed(ref s) => {
35 accumulator.push_str(&s);
40 ast::LitInt(i, ast::UnsignedIntLit(_)) |
41 ast::LitInt(i, ast::SignedIntLit(_, ast::Plus)) |
42 ast::LitInt(i, ast::UnsuffixedIntLit(ast::Plus)) => {
43 accumulator.push_str(&format!("{}", i)[]);
45 ast::LitInt(i, ast::SignedIntLit(_, ast::Minus)) |
46 ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => {
47 accumulator.push_str(&format!("-{}", i)[]);
50 accumulator.push_str(&format!("{}", b)[]);
53 ast::LitBinary(..) => {
54 cx.span_err(e.span, "cannot concatenate a binary literal");
59 cx.span_err(e.span, "expected a literal");
63 base::MacExpr::new(cx.expr_str(
65 token::intern_and_get_ident(&accumulator[..])))