Skip to content

Commit

Permalink
Convert some token functions into methods
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Oct 28, 2014
1 parent d8b1fa0 commit fcb78d6
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 311 deletions.
20 changes: 10 additions & 10 deletions src/librustc/middle/save/span_utils.rs
Expand Up @@ -19,7 +19,7 @@ use syntax::codemap::*;
use syntax::parse::lexer;
use syntax::parse::lexer::{Reader,StringReader};
use syntax::parse::token;
use syntax::parse::token::{is_keyword,keywords,is_ident,Token};
use syntax::parse::token::{keywords, Token};

pub struct SpanUtils<'a> {
pub sess: &'a Session,
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'a> SpanUtils<'a> {
return self.make_sub_span(span, result)
}
if bracket_count == 0 &&
(is_ident(&ts.tok) || is_keyword(keywords::Self, &ts.tok)) {
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::Self)) {
result = Some(ts.sp);
}

Expand All @@ -120,7 +120,7 @@ impl<'a> SpanUtils<'a> {
return None;
}
if bracket_count == 0 &&
(is_ident(&ts.tok) || is_keyword(keywords::Self, &ts.tok)) {
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::Self)) {
return self.make_sub_span(span, Some(ts.sp));
}

Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'a> SpanUtils<'a> {
if (next.tok == token::LParen ||
next.tok == token::Lt) &&
bracket_count == 0 &&
is_ident(&prev.tok) {
prev.tok.is_ident() {
result = Some(prev.sp);
}

Expand All @@ -158,7 +158,7 @@ impl<'a> SpanUtils<'a> {
prev = next;
next = toks.next_token();
if next.tok == token::Lt &&
is_ident(&old.tok) {
old.tok.is_ident() {
result = Some(old.sp);
}
}
Expand All @@ -170,7 +170,7 @@ impl<'a> SpanUtils<'a> {
_ => 0
};

if is_ident(&prev.tok) && bracket_count == 0 {
if prev.tok.is_ident() && bracket_count == 0 {
last_span = Some(prev.sp);
}
prev = next;
Expand All @@ -194,7 +194,7 @@ impl<'a> SpanUtils<'a> {
if (next.tok == token::Lt ||
next.tok == token::Colon) &&
bracket_count == 0 &&
is_ident(&prev.tok) {
prev.tok.is_ident() {
result = Some(prev.sp);
}

Expand All @@ -216,7 +216,7 @@ impl<'a> SpanUtils<'a> {
format!("Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
self.snippet(span), loc.file.name, loc.line).as_slice());
}
if result.is_none() && is_ident(&prev.tok) && bracket_count == 0 {
if result.is_none() && prev.tok.is_ident() && bracket_count == 0 {
return self.make_sub_span(span, Some(prev.sp));
}
self.make_sub_span(span, result)
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<'a> SpanUtils<'a> {
token::BinOp(token::Shr) => -2,
_ => 0
};
if is_ident(&ts.tok) &&
if ts.tok.is_ident() &&
bracket_count == nesting {
result.push(self.make_sub_span(span, Some(ts.sp)).unwrap());
}
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'a> SpanUtils<'a> {
if ts.tok == token::Eof {
return None;
}
if is_keyword(keyword, &ts.tok) {
if ts.tok.is_keyword(keyword) {
let ts = toks.next_token();
if ts.tok == token::Eof {
return None
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/highlight.rs
Expand Up @@ -101,7 +101,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
token::RParen | token::LBracket | token::LBrace | token::RBrace |
token::Question => "",
token::Dollar => {
if token::is_ident(&lexer.peek().tok) {
if lexer.peek().tok.is_ident() {
is_macro_nonterminal = true;
"macro-nonterminal"
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
"Option" | "Result" => "prelude-ty",
"Some" | "None" | "Ok" | "Err" => "prelude-val",

_ if token::is_any_keyword(&next.tok) => "kw",
_ if next.tok.is_any_keyword() => "kw",
_ => {
if is_macro_nonterminal {
is_macro_nonterminal = false;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -82,7 +82,7 @@ impl PartialEq for Ident {
//
// On the other hand, if the comparison does need to be hygienic,
// one example and its non-hygienic counterpart would be:
// syntax::parse::token::mtwt_token_eq
// syntax::parse::token::Token::mtwt_eq
// syntax::ext::tt::macro_parser::token_name_eq
fail!("not allowed to compare these idents: {}, {}. \
Probably related to issue \\#6993", self, other);
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/ext/format.rs
Expand Up @@ -116,8 +116,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool,
return (invocation, None);
}
if p.token == token::Eof { break } // accept trailing commas
if named || (token::is_ident(&p.token) &&
p.look_ahead(1, |t| *t == token::Eq)) {
if named || (p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq)) {
named = true;
let ident = match p.token {
token::Ident(i, _) => {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/trace_macros.rs
Expand Up @@ -12,18 +12,18 @@ use ast;
use codemap::Span;
use ext::base::ExtCtxt;
use ext::base;
use parse::token::{keywords, is_keyword};
use parse::token::keywords;


pub fn expand_trace_macros(cx: &mut ExtCtxt,
sp: Span,
tt: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
match tt {
[ast::TtToken(_, ref tok)] if is_keyword(keywords::True, tok) => {
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => {
cx.set_trace_macros(true);
}
[ast::TtToken(_, ref tok)] if is_keyword(keywords::False, tok) => {
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::False) => {
cx.set_trace_macros(false);
}
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/comments.rs
Expand Up @@ -367,7 +367,7 @@ pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler,
rdr.next_token();
//discard, and look ahead; we're working with internal state
let TokenAndSpan { tok, sp } = rdr.peek();
if token::is_lit(&tok) {
if tok.is_lit() {
rdr.with_str_from(bstart, |s| {
debug!("tok lit: {}", s);
literals.push(Literal {lit: s.to_string(), pos: sp.lo});
Expand Down
9 changes: 4 additions & 5 deletions src/libsyntax/parse/lexer/mod.rs
Expand Up @@ -1058,15 +1058,14 @@ impl<'a> StringReader<'a> {
let keyword_checking_token =
&token::Ident(keyword_checking_ident, false);
let last_bpos = self.last_pos;
if token::is_keyword(token::keywords::Self,
keyword_checking_token) {
if keyword_checking_token.is_keyword(token::keywords::Self) {
self.err_span_(start,
last_bpos,
"invalid lifetime name: 'self \
is no longer a special lifetime");
} else if token::is_any_keyword(keyword_checking_token) &&
!token::is_keyword(token::keywords::Static,
keyword_checking_token) {
} else if keyword_checking_token.is_any_keyword() &&
!keyword_checking_token.is_keyword(token::keywords::Static)
{
self.err_span_(start,
last_bpos,
"invalid lifetime name");
Expand Down

0 comments on commit fcb78d6

Please sign in to comment.