1 // Copyright 2012 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::base;
14 use syntax::feature_gate;
15 use syntax::parse::token;
18 use syntax_pos::symbol::Symbol;
19 use syntax_pos::hygiene::SyntaxContext;
20 use syntax::tokenstream::TokenTree;
22 pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
25 -> Box<base::MacResult + 'cx> {
26 if !cx.ecfg.enable_concat_idents() {
27 feature_gate::emit_feature_err(&cx.parse_sess,
30 feature_gate::GateIssue::Language,
31 feature_gate::EXPLAIN_CONCAT_IDENTS);
32 return base::DummyResult::expr(sp);
35 let mut res_str = String::new();
36 for (i, e) in tts.iter().enumerate() {
39 TokenTree::Token(_, token::Comma) => {}
41 cx.span_err(sp, "concat_idents! expecting comma.");
42 return DummyResult::expr(sp);
47 TokenTree::Token(_, token::Ident(ident)) => res_str.push_str(&ident.name.as_str()),
49 cx.span_err(sp, "concat_idents! requires ident args.");
50 return DummyResult::expr(sp);
55 let res = ast::Ident {
56 name: Symbol::intern(&res_str),
57 ctxt: SyntaxContext::empty().apply_mark(cx.current_expansion.mark),
66 fn path(&self) -> ast::Path {
69 segments: vec![ast::PathSegment::from_ident(self.ident, self.span)],
74 impl base::MacResult for Result {
75 fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
77 id: ast::DUMMY_NODE_ID,
78 node: ast::ExprKind::Path(None, self.path()),
80 attrs: ast::ThinVec::new(),
84 fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
86 id: ast::DUMMY_NODE_ID,
87 node: ast::TyKind::Path(None, self.path()),