Skip to content

Commit

Permalink
Remove parse_str_lit_or_env_ident.
Browse files Browse the repository at this point in the history
We decided to use metadata for the more complex cases, and a simple
string is enough for rustc right now.
  • Loading branch information
cixtor committed Jun 23, 2011
1 parent 14c31c2 commit 3c534b2
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,6 @@ fn parse_value_ident(&parser p) -> ast::ident {
ret parse_ident(p);
}


/* FIXME: gross hack copied from rustboot to make certain configuration-based
* decisions work at build-time. We should probably change it to use a
* lexical sytnax-extension or something similar. For now we just imitate
* rustboot.
*/
fn parse_str_lit_or_env_ident(&parser p) -> ast::ident {
alt (p.peek()) {
case (token::LIT_STR(?s)) { p.bump(); ret p.get_str(s); }
case (token::IDENT(?i, _)) {
auto v =
eval::lookup(p.get_session(), p.get_env(), p.get_span(),
p.get_str(i));
if (!eval::val_is_str(v)) {
p.fatal("expecting string-valued variable");
}
p.bump();
ret eval::val_as_str(v);
}
case (_) { p.fatal("expecting string literal"); fail; }
}
}

fn is_word(&parser p, &str word) -> bool {
ret alt (p.peek()) {
case (token::IDENT(?sid, false)) { str::eq(word, p.get_str(sid)) }
Expand Down Expand Up @@ -1849,7 +1826,7 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item {
auto link_name = none;
if (p.peek() == token::EQ) {
p.bump();
link_name = some(parse_str_lit_or_env_ident(p));
link_name = some(parse_str(p));
}
auto hi = p.get_hi_pos();
expect(p, token::SEMI);
Expand Down Expand Up @@ -1897,7 +1874,7 @@ fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto lo = p.get_last_lo_pos();
auto abi = ast::native_abi_cdecl;
if (!is_word(p, "mod")) {
auto t = parse_str_lit_or_env_ident(p);
auto t = parse_str(p);
if (str::eq(t, "cdecl")) {
} else if (str::eq(t, "rust")) {
abi = ast::native_abi_rust;
Expand All @@ -1912,7 +1889,7 @@ fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto native_name;
if (p.peek() == token::EQ) {
expect(p, token::EQ);
native_name = parse_str_lit_or_env_ident(p);
native_name = parse_str(p);
} else { native_name = default_native_name(p.get_session(), id); }
expect(p, token::LBRACE);
auto m = parse_native_mod_items(p, native_name, abi);
Expand Down Expand Up @@ -2297,6 +2274,15 @@ fn parse_crate_from_source_file(&parser p) -> @ast::crate {
attrs=crate_attrs._0));
}

fn parse_str(&parser p) -> ast::ident {
alt (p.peek()) {
case (token::LIT_STR(?s)) {
p.bump();
ret p.get_str(s);
}
case (_) { fail; }
}
}

// Logic for parsing crate files (.rc)
//
Expand All @@ -2318,9 +2304,7 @@ fn parse_crate_directive(&parser p) -> ast::crate_directive {
alt (p.peek()) {
case (token::EQ) {
p.bump();

// FIXME: turn this into parse+eval expr
some(parse_str_lit_or_env_ident(p))
some(parse_str(p))
}
case (_) { none }
};
Expand Down

0 comments on commit 3c534b2

Please sign in to comment.