Files
rust/src/comp/syntax/ext/ident_to_str.rs
2011-08-09 15:53:26 -07:00

22 lines
696 B
Rust

import std::ivec;
import std::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 ivec::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"),
ast::sk_rc));
}