]>
git.proxmox.com Git - rustc.git/blob - src/libsyntax_ext/concat_idents.rs
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
, _
)) =>
48 res_str
.push_str(&ident
.name
.as_str()),
50 cx
.span_err(sp
, "concat_idents! requires ident args.");
51 return DummyResult
::expr(sp
);
56 let res
= ast
::Ident
{
57 name
: Symbol
::intern(&res_str
),
58 ctxt
: SyntaxContext
::empty().apply_mark(cx
.current_expansion
.mark
),
67 fn path(&self) -> ast
::Path
{
70 segments
: vec
![ast
::PathSegment
::from_ident(self.ident
, self.span
)],
75 impl base
::MacResult
for Result
{
76 fn make_expr(self: Box
<Self>) -> Option
<P
<ast
::Expr
>> {
78 id
: ast
::DUMMY_NODE_ID
,
79 node
: ast
::ExprKind
::Path(None
, self.path()),
81 attrs
: ast
::ThinVec
::new(),
85 fn make_ty(self: Box
<Self>) -> Option
<P
<ast
::Ty
>> {
87 id
: ast
::DUMMY_NODE_ID
,
88 node
: ast
::TyKind
::Path(None
, self.path()),
96 span
: sp
.with_ctxt(sp
.ctxt().apply_mark(cx
.current_expansion
.mark
)),