summary refs log tree commit diff
path: root/src/comp/syntax/ext/ident_to_str.rs
blob: d6093b61dbfd584be6e25c430434559ce6a04b6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import core::{vec, option};
import base::*;
import syntax::ast;

fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr,
                     _body: option::t<str>) -> @ast::expr {
    let args: [@ast::expr] =
        alt arg.node {
          ast::expr_vec(elts, _) { elts }
          _ {
            cx.span_fatal(sp, "#ident_to_str requires a vector argument .")
          }
        };
    if vec::len::<@ast::expr>(args) != 1u {
        cx.span_fatal(sp, "malformed #ident_to_str call");
    }

    ret make_new_lit(cx, sp,
                     ast::lit_str(expr_to_ident(cx, args[0u],
                                                "expected an ident")));

}