2012-12-04 00:48:01 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-05-05 02:05:16 +00:00
|
|
|
/*
|
2012-10-12 19:32:36 +00:00
|
|
|
* The compiler code necessary to support the env! extension. Eventually this
|
2011-05-05 02:05:16 +00:00
|
|
|
* should all get sucked into either the compiler syntax extension plugin
|
|
|
|
* interface.
|
|
|
|
*/
|
2012-12-23 22:41:37 +00:00
|
|
|
|
2013-05-17 22:28:44 +00:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2013-02-25 19:11:21 +00:00
|
|
|
use ast;
|
|
|
|
use codemap::span;
|
2012-12-13 21:05:22 +00:00
|
|
|
use ext::base::*;
|
2012-12-23 22:41:37 +00:00
|
|
|
use ext::base;
|
2013-05-17 14:19:28 +00:00
|
|
|
use ext::build::AstBuilder;
|
2012-12-23 22:41:37 +00:00
|
|
|
|
2013-05-25 02:35:29 +00:00
|
|
|
use core::os;
|
|
|
|
|
2013-05-17 11:27:17 +00:00
|
|
|
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
2013-01-23 00:45:27 +00:00
|
|
|
-> base::MacResult {
|
2012-12-13 01:08:09 +00:00
|
|
|
|
|
|
|
let var = get_single_str_from_tts(cx, sp, tts, "env!");
|
2012-05-14 22:32:32 +00:00
|
|
|
|
2012-06-21 23:44:10 +00:00
|
|
|
// FIXME (#2248): if this was more thorough it would manufacture an
|
2012-08-20 19:23:37 +00:00
|
|
|
// Option<str> rather than just an maybe-empty string.
|
2011-05-06 23:30:39 +00:00
|
|
|
|
2012-12-13 01:08:09 +00:00
|
|
|
let e = match os::getenv(var) {
|
2013-06-12 17:02:55 +00:00
|
|
|
None => cx.expr_str(sp, @""),
|
|
|
|
Some(s) => cx.expr_str(sp, s.to_managed())
|
2012-12-13 01:08:09 +00:00
|
|
|
};
|
2013-01-23 00:45:27 +00:00
|
|
|
MRExpr(e)
|
2011-05-05 02:05:16 +00:00
|
|
|
}
|