Marijn Haverbeke 6fd6fdea93 Move everything syntax-related to syntax/, break deps on rest of compiler
src/comp/syntax is currently just a sub-module of rustc, but it will,
in the near future, be its own crate. This includes:

 - The AST data structure
 - The parser
 - The pretty-printer
 - Visit, walk, and fold
 - The syntax extension system
 - Some utility stuff that should be in the stdlib*

*) Stdlib extensions currently require a snapshot before they can be
   used, and the win build is very broken right now. This is temporary
   and will be cleaned up when one of those problems goes away.

A lot of code was moved by this patch, mostly towards a more organized
layout. Some package paths did get longer, and I guess the new layout
will take some getting used to. Sorry about that!

Please try not to re-introduce any dependencies in syntax/ on any of
the other src/comp/ subdirs.
2011-07-05 15:57:21 +02:00

48 lines
1.4 KiB
Rust

/*
* The compiler code necessary to support the #env extension. Eventually this
* should all get sucked into either the compiler syntax extension plugin
* interface.
*/
import std::str;
import std::vec;
import std::option;
import std::generic_os;
import base::*;
export expand_syntax_ext;
fn expand_syntax_ext(&ext_ctxt cx, codemap::span sp, &vec[@ast::expr] args,
option::t[str] body) -> @ast::expr {
if (vec::len[@ast::expr](args) != 1u) {
cx.span_fatal(sp, "malformed #env call");
}
// FIXME: if this was more thorough it would manufacture an
// option::t[str] rather than just an maybe-empty string.
auto var = expr_to_str(cx, args.(0), "#env requires a string");
alt (generic_os::getenv(var)) {
case (option::none) { ret make_new_str(cx, sp, ""); }
case (option::some(?s)) { ret make_new_str(cx, sp, s); }
}
}
fn make_new_lit(&ext_ctxt cx, codemap::span sp, ast::lit_ lit) -> @ast::expr {
auto sp_lit = @rec(node=lit, span=sp);
ret @rec(id=cx.next_id(), node=ast::expr_lit(sp_lit), span=sp);
}
fn make_new_str(&ext_ctxt cx, codemap::span sp, str s) -> @ast::expr {
ret make_new_lit(cx, sp, ast::lit_str(s, ast::sk_rc));
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//