mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
libsyntax: Remove many uses of token::ident_to_str
This commit is contained in:
parent
e534b565e6
commit
875c9ce30b
@ -22,8 +22,8 @@ use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
|
||||
use ext::base::*;
|
||||
use fold::*;
|
||||
use parse;
|
||||
use parse::token::{fresh_mark, fresh_name, intern};
|
||||
use parse::token;
|
||||
use parse::token::{fresh_mark, fresh_name, ident_to_str, intern};
|
||||
use visit;
|
||||
use visit::Visitor;
|
||||
use util::small_vector::SmallVector;
|
||||
@ -310,11 +310,12 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
|
||||
|
||||
Some(&NormalTT(ref expander, span)) => {
|
||||
if it.ident.name != parse::token::special_idents::invalid.name {
|
||||
let string = token::get_ident(it.ident.name);
|
||||
fld.cx.span_err(pth.span,
|
||||
format!("macro {}! expects no ident argument, \
|
||||
given '{}'",
|
||||
extnamestr.get(),
|
||||
ident_to_str(&it.ident)));
|
||||
string.get()));
|
||||
return SmallVector::zero();
|
||||
}
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
@ -411,7 +412,10 @@ fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) {
|
||||
let MacroCrate { lib, cnum } = fld.cx.loader.load_crate(crate);
|
||||
|
||||
let crate_name = match crate.node {
|
||||
ast::ViewItemExternMod(ref name, _, _) => token::ident_to_str(name),
|
||||
ast::ViewItemExternMod(ref name, _, _) => {
|
||||
let string = token::get_ident(name.name);
|
||||
string.get().to_str()
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let name = format!("<{} macros>", crate_name);
|
||||
@ -957,7 +961,7 @@ mod test {
|
||||
use fold::*;
|
||||
use ext::base::{CrateLoader, MacroCrate};
|
||||
use parse;
|
||||
use parse::token::{fresh_mark, gensym, intern, ident_to_str};
|
||||
use parse::token::{fresh_mark, gensym, intern};
|
||||
use parse::token;
|
||||
use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
|
||||
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
|
||||
@ -1272,9 +1276,12 @@ mod test {
|
||||
println!("uh oh, matches but shouldn't:");
|
||||
println!("varref: {:?}",varref);
|
||||
// good lord, you can't make a path with 0 segments, can you?
|
||||
let string = token::get_ident(varref.segments[0]
|
||||
.identifier
|
||||
.name);
|
||||
println!("varref's first segment's uint: {}, and string: \"{}\"",
|
||||
varref.segments[0].identifier.name,
|
||||
ident_to_str(&varref.segments[0].identifier));
|
||||
string.get());
|
||||
println!("binding: {:?}", bindings[binding_idx]);
|
||||
ast_util::display_sctable(get_sctable());
|
||||
}
|
||||
@ -1296,7 +1303,10 @@ foo_module!()
|
||||
let bindings = name_finder.ident_accumulator;
|
||||
|
||||
let cxbinds : ~[&ast::Ident] =
|
||||
bindings.iter().filter(|b|{@"xx" == (ident_to_str(*b))}).collect();
|
||||
bindings.iter().filter(|b| {
|
||||
let string = token::get_ident(b);
|
||||
"xx" == string.get()
|
||||
}).collect();
|
||||
let cxbind = match cxbinds {
|
||||
[b] => b,
|
||||
_ => fail!("expected just one binding for ext_cx")
|
||||
@ -1308,9 +1318,13 @@ foo_module!()
|
||||
let varrefs = path_finder.path_accumulator;
|
||||
|
||||
// the xx binding should bind all of the xx varrefs:
|
||||
for (idx,v) in varrefs.iter().filter(|p|{ p.segments.len() == 1
|
||||
&& (@"xx" == (ident_to_str(&p.segments[0].identifier)))
|
||||
}).enumerate() {
|
||||
for (idx,v) in varrefs.iter().filter(|p|{
|
||||
p.segments.len() == 1
|
||||
&& {
|
||||
let string = token::get_ident(p.segments[0].identifier.name);
|
||||
"xx" == string.get()
|
||||
}
|
||||
}).enumerate() {
|
||||
if (mtwt_resolve(v.segments[0].identifier) != resolved_binding) {
|
||||
println!("uh oh, xx binding didn't match xx varref:");
|
||||
println!("this is xx varref \\# {:?}",idx);
|
||||
|
@ -18,7 +18,7 @@ use parse::lexer::*; //resolve bug?
|
||||
use parse::ParseSess;
|
||||
use parse::attr::ParserAttr;
|
||||
use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
|
||||
use parse::token::{Token, EOF, to_str, Nonterminal, get_ident_interner, ident_to_str};
|
||||
use parse::token::{Token, EOF, to_str, Nonterminal, get_ident_interner};
|
||||
use parse::token;
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
@ -183,8 +183,9 @@ pub fn nameize(p_s: @ParseSess, ms: &[Matcher], res: &[@NamedMatch])
|
||||
node: MatchNonterminal(ref bind_name, _, idx), span: sp
|
||||
} => {
|
||||
if ret_val.contains_key(bind_name) {
|
||||
p_s.span_diagnostic.span_fatal(sp,
|
||||
"Duplicated bind name: "+ ident_to_str(bind_name))
|
||||
let string = token::get_ident(bind_name.name);
|
||||
p_s.span_diagnostic
|
||||
.span_fatal(sp, "Duplicated bind name: " + string.get())
|
||||
}
|
||||
ret_val.insert(*bind_name, res[idx]);
|
||||
}
|
||||
@ -364,8 +365,11 @@ pub fn parse(sess: @ParseSess,
|
||||
let nts = bb_eis.map(|ei| {
|
||||
match ei.elts[ei.idx].node {
|
||||
MatchNonterminal(ref bind,ref name,_) => {
|
||||
format!("{} ('{}')", ident_to_str(name),
|
||||
ident_to_str(bind))
|
||||
let bind_string = token::get_ident(bind.name);
|
||||
let name_string = token::get_ident(name.name);
|
||||
format!("{} ('{}')",
|
||||
name_string.get(),
|
||||
bind_string.get())
|
||||
}
|
||||
_ => fail!()
|
||||
} }).connect(" or ");
|
||||
@ -388,8 +392,9 @@ pub fn parse(sess: @ParseSess,
|
||||
let mut ei = bb_eis.pop().unwrap();
|
||||
match ei.elts[ei.idx].node {
|
||||
MatchNonterminal(_, ref name, idx) => {
|
||||
let name_string = token::get_ident(name.name);
|
||||
ei.matches[idx].push(@MatchedNonterminal(
|
||||
parse_nt(&mut rust_parser, ident_to_str(name))));
|
||||
parse_nt(&mut rust_parser, name_string.get())));
|
||||
ei.idx += 1u;
|
||||
}
|
||||
_ => fail!()
|
||||
|
@ -14,7 +14,7 @@ use codemap::{Span, DUMMY_SP};
|
||||
use diagnostic::SpanHandler;
|
||||
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
||||
use parse::token::{EOF, INTERPOLATED, IDENT, Token, NtIdent};
|
||||
use parse::token::{ident_to_str};
|
||||
use parse::token;
|
||||
use parse::lexer::TokenAndSpan;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
@ -122,9 +122,10 @@ fn lookup_cur_matched(r: &TtReader, name: Ident) -> @NamedMatch {
|
||||
match matched_opt {
|
||||
Some(s) => lookup_cur_matched_by_matched(r, s),
|
||||
None => {
|
||||
let name_string = token::get_ident(name.name);
|
||||
r.sp_diag.span_fatal(r.cur_span.get(),
|
||||
format!("unknown macro variable `{}`",
|
||||
ident_to_str(&name)));
|
||||
name_string.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,11 +146,11 @@ fn lis_merge(lhs: LockstepIterSize, rhs: LockstepIterSize) -> LockstepIterSize {
|
||||
LisContradiction(_) => rhs.clone(),
|
||||
LisConstraint(r_len, _) if l_len == r_len => lhs.clone(),
|
||||
LisConstraint(r_len, ref r_id) => {
|
||||
let l_n = ident_to_str(l_id);
|
||||
let r_n = ident_to_str(r_id);
|
||||
let l_n = token::get_ident(l_id.name);
|
||||
let r_n = token::get_ident(r_id.name);
|
||||
LisContradiction(format!("Inconsistent lockstep iteration: \
|
||||
'{}' has {} items, but '{}' has {}",
|
||||
l_n, l_len, r_n, r_len))
|
||||
l_n.get(), l_len, r_n.get(), r_len))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,10 +314,11 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan {
|
||||
return ret_val;
|
||||
}
|
||||
MatchedSeq(..) => {
|
||||
let string = token::get_ident(ident.name);
|
||||
r.sp_diag.span_fatal(
|
||||
r.cur_span.get(), /* blame the macro writer */
|
||||
format!("variable '{}' is still repeating at this depth",
|
||||
ident_to_str(&ident)));
|
||||
string.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,8 @@ use parse::lexer::Reader;
|
||||
use parse::lexer::TokenAndSpan;
|
||||
use parse::obsolete::*;
|
||||
use parse::token::{INTERPOLATED, InternedString, can_begin_expr, get_ident};
|
||||
use parse::token::{get_ident_interner, ident_to_str, is_ident};
|
||||
use parse::token::{is_ident_or_path, is_plain_ident, keywords};
|
||||
use parse::token::{special_idents, token_to_binop};
|
||||
use parse::token::{get_ident_interner, is_ident, is_ident_or_path};
|
||||
use parse::token::{is_plain_ident, keywords, special_idents, token_to_binop};
|
||||
use parse::token;
|
||||
use parse::{new_sub_parser_from_file, ParseSess};
|
||||
use opt_vec;
|
||||
@ -4534,7 +4533,8 @@ impl Parser {
|
||||
token::LIT_STR(s)
|
||||
| token::LIT_STR_RAW(s, _) => {
|
||||
self.bump();
|
||||
let the_string = ident_to_str(&s);
|
||||
let identifier_string = token::get_ident(s.name);
|
||||
let the_string = identifier_string.get();
|
||||
let mut abis = AbiSet::empty();
|
||||
for word in the_string.words() {
|
||||
match abi::lookup(word) {
|
||||
|
@ -19,7 +19,7 @@ use codemap::{CodeMap, BytePos};
|
||||
use codemap;
|
||||
use diagnostic;
|
||||
use parse::classify::expr_is_simple_block;
|
||||
use parse::token::{IdentInterner, ident_to_str, interner_get};
|
||||
use parse::token::{IdentInterner, interner_get};
|
||||
use parse::{comments, token};
|
||||
use parse;
|
||||
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
|
||||
@ -1539,7 +1539,8 @@ pub fn print_decl(s: &mut State, decl: &ast::Decl) {
|
||||
}
|
||||
|
||||
pub fn print_ident(s: &mut State, ident: ast::Ident) {
|
||||
word(&mut s.s, ident_to_str(&ident));
|
||||
let string = token::get_ident(ident.name);
|
||||
word(&mut s.s, string.get());
|
||||
}
|
||||
|
||||
pub fn print_name(s: &mut State, name: ast::Name) {
|
||||
|
Loading…
Reference in New Issue
Block a user