@@ -147,9 +147,23 @@ impure fn parse_ident(parser p) -> ast.ident {
147
147
}
148
148
149
149
150
- impure fn parse_str_lit ( parser p) -> ast . ident {
150
+ /* FIXME: gross hack copied from rustboot to make certain configuration-based
151
+ * decisions work at build-time. We should probably change it to use a
152
+ * lexical sytnax-extension or something similar. For now we just imitate
153
+ * rustboot.
154
+ */
155
+ impure fn parse_str_lit_or_env_ident ( parser p) -> ast . ident {
151
156
alt ( p. peek ( ) ) {
152
157
case ( token. LIT_STR ( ?s) ) { p. bump ( ) ; ret s; }
158
+ case ( token. IDENT ( ?i) ) {
159
+ auto v = eval. lookup ( p. get_session ( ) , p. get_env ( ) ,
160
+ p. get_span ( ) , i) ;
161
+ if ( !eval. val_is_str ( v) ) {
162
+ p. err ( "expecting string-valued variable" ) ;
163
+ }
164
+ p. bump ( ) ;
165
+ ret eval. val_as_str ( v) ;
166
+ }
153
167
case ( _) {
154
168
p. err ( "expecting string literal" ) ;
155
169
fail;
@@ -1824,7 +1838,7 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
1824
1838
expect ( p, token. NATIVE ) ;
1825
1839
auto abi = ast. native_abi_cdecl ;
1826
1840
if ( p. peek ( ) != token. MOD ) {
1827
- auto t = parse_str_lit ( p) ;
1841
+ auto t = parse_str_lit_or_env_ident ( p) ;
1828
1842
if ( _str. eq ( t, "cdecl" ) ) {
1829
1843
} else if ( _str. eq ( t, "rust" ) ) {
1830
1844
abi = ast. native_abi_rust ;
@@ -1838,7 +1852,7 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
1838
1852
auto native_name;
1839
1853
if ( p. peek ( ) == token. EQ ) {
1840
1854
expect ( p, token. EQ ) ;
1841
- native_name = parse_str_lit ( p) ;
1855
+ native_name = parse_str_lit_or_env_ident ( p) ;
1842
1856
} else {
1843
1857
native_name = default_native_name ( p. get_session ( ) , id) ;
1844
1858
}
@@ -2202,7 +2216,7 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
2202
2216
case ( token. EQ ) {
2203
2217
p. bump ( ) ;
2204
2218
// FIXME: turn this into parse+eval expr
2205
- file_opt = some[ filename] ( parse_str_lit ( p) ) ;
2219
+ file_opt = some[ filename] ( parse_str_lit_or_env_ident ( p) ) ;
2206
2220
}
2207
2221
case ( _) { }
2208
2222
}
0 commit comments