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.
12 use syntax::ext::base;
13 use syntax::ext::build::AstBuilder;
14 use syntax::symbol::Symbol;
16 use syntax::tokenstream;
18 use std::string::String;
20 pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
22 tts: &[tokenstream::TokenTree])
23 -> Box<base::MacResult + 'static> {
24 let es = match base::get_exprs_from_tts(cx, sp, tts) {
26 None => return base::DummyResult::expr(sp),
28 let mut accumulator = String::new();
31 ast::ExprKind::Lit(ref lit) => {
33 ast::LitKind::Str(ref s, _) |
34 ast::LitKind::Float(ref s, _) |
35 ast::LitKind::FloatUnsuffixed(ref s) => {
36 accumulator.push_str(&s.as_str());
38 ast::LitKind::Char(c) => {
41 ast::LitKind::Int(i, ast::LitIntType::Unsigned(_)) |
42 ast::LitKind::Int(i, ast::LitIntType::Signed(_)) |
43 ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
44 accumulator.push_str(&format!("{}", i));
46 ast::LitKind::Bool(b) => {
47 accumulator.push_str(&format!("{}", b));
49 ast::LitKind::Byte(..) |
50 ast::LitKind::ByteStr(..) => {
51 cx.span_err(e.span, "cannot concatenate a byte string literal");
56 cx.span_err(e.span, "expected a literal");
60 base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))