]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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. | |
4 | // | |
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. | |
10 | ||
11 | use core::prelude::*; | |
12 | ||
13 | use ast; | |
14 | use codemap::span; | |
15 | use ext::base::*; | |
16 | use ext::base; | |
17 | use parse::token; | |
18 | ||
19 | pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) | |
20 | -> base::MacResult { | |
21 | let mut res_str = ~""; | |
22 | for tts.eachi |i, e| { | |
23 | if i & 1 == 1 { | |
24 | match *e { | |
25 | ast::tt_tok(_, token::COMMA) => (), | |
26 | _ => cx.span_fatal(sp, ~"concat_idents! \ | |
27 | expecting comma.") | |
28 | } | |
29 | } else { | |
30 | match *e { | |
31 | ast::tt_tok(_, token::IDENT(ident,_)) => | |
32 | res_str += cx.str_of(ident), | |
33 | _ => cx.span_fatal(sp, ~"concat_idents! \ | |
34 | requires ident args.") | |
35 | } | |
36 | } | |
37 | } | |
38 | let res = cx.parse_sess().interner.intern(@res_str); | |
39 | ||
40 | let e = @ast::expr { | |
41 | id: cx.next_id(), | |
42 | callee_id: cx.next_id(), | |
43 | node: ast::expr_path( | |
44 | @ast::path { | |
45 | span: sp, | |
46 | global: false, | |
47 | idents: ~[res], | |
48 | rp: None, | |
49 | types: ~[], | |
50 | } | |
51 | ), | |
52 | span: sp, | |
53 | }; | |
54 | MRExpr(e) | |
55 | } |