1
Fork 0

libsyntax: De-@mut token in the parser

This commit is contained in:
Patrick Walton 2013-12-30 15:09:41 -08:00
parent 425a140485
commit 758d854436
10 changed files with 251 additions and 251 deletions

View file

@ -66,9 +66,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
asm_str_style = Some(style); asm_str_style = Some(style);
} }
Outputs => { Outputs => {
while *p.token != token::EOF && while p.token != token::EOF &&
*p.token != token::COLON && p.token != token::COLON &&
*p.token != token::MOD_SEP { p.token != token::MOD_SEP {
if outputs.len() != 0 { if outputs.len() != 0 {
p.eat(&token::COMMA); p.eat(&token::COMMA);
@ -91,9 +91,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
} }
} }
Inputs => { Inputs => {
while *p.token != token::EOF && while p.token != token::EOF &&
*p.token != token::COLON && p.token != token::COLON &&
*p.token != token::MOD_SEP { p.token != token::MOD_SEP {
if inputs.len() != 0 { if inputs.len() != 0 {
p.eat(&token::COMMA); p.eat(&token::COMMA);
@ -116,9 +116,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
} }
Clobbers => { Clobbers => {
let mut clobs = ~[]; let mut clobs = ~[];
while *p.token != token::EOF && while p.token != token::EOF &&
*p.token != token::COLON && p.token != token::COLON &&
*p.token != token::MOD_SEP { p.token != token::MOD_SEP {
if clobs.len() != 0 { if clobs.len() != 0 {
p.eat(&token::COMMA); p.eat(&token::COMMA);
@ -142,16 +142,16 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
dialect = ast::asm_intel; dialect = ast::asm_intel;
} }
if *p.token == token::COMMA { if p.token == token::COMMA {
p.eat(&token::COMMA); p.eat(&token::COMMA);
} }
} }
} }
while *p.token == token::COLON || while p.token == token::COLON ||
*p.token == token::MOD_SEP || p.token == token::MOD_SEP ||
*p.token == token::EOF { p.token == token::EOF {
state = if *p.token == token::COLON { state = if p.token == token::COLON {
p.bump(); p.bump();
match next_state(state) { match next_state(state) {
Some(x) => x, Some(x) => x,
@ -160,7 +160,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
break break
} }
} }
} else if *p.token == token::MOD_SEP { } else if p.token == token::MOD_SEP {
p.bump(); p.bump();
let s = match next_state(state) { let s = match next_state(state) {
Some(x) => x, Some(x) => x,
@ -176,7 +176,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
break break
} }
} }
} else if *p.token == token::EOF { } else if p.token == token::EOF {
continue_ = false; continue_ = false;
break; break;
} else { } else {

View file

@ -446,7 +446,7 @@ pub fn get_exprs_from_tts(cx: &ExtCtxt,
cx.cfg(), cx.cfg(),
tts.to_owned()); tts.to_owned());
let mut es = ~[]; let mut es = ~[];
while *p.token != token::EOF { while p.token != token::EOF {
if es.len() != 0 && !p.eat(&token::COMMA) { if es.len() != 0 && !p.eat(&token::COMMA) {
cx.span_fatal(sp, "expected token: `,`"); cx.span_fatal(sp, "expected token: `,`");
} }

View file

@ -32,7 +32,7 @@ pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::
let mut cfgs = ~[]; let mut cfgs = ~[];
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)` // parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
while *p.token != token::EOF { while p.token != token::EOF {
cfgs.push(p.parse_meta_item()); cfgs.push(p.parse_meta_item());
if p.eat(&token::EOF) { break } // trailing comma is optional,. if p.eat(&token::EOF) { break } // trailing comma is optional,.
p.expect(&token::COMMA); p.expect(&token::COMMA);

View file

@ -65,22 +65,22 @@ impl<'a> Context<'a> {
return (extra, None); return (extra, None);
} }
if *p.token == token::EOF { if p.token == token::EOF {
self.ecx.span_err(sp, "requires at least a format string argument"); self.ecx.span_err(sp, "requires at least a format string argument");
return (extra, None); return (extra, None);
} }
let fmtstr = p.parse_expr(); let fmtstr = p.parse_expr();
let mut named = false; let mut named = false;
while *p.token != token::EOF { while p.token != token::EOF {
if !p.eat(&token::COMMA) { if !p.eat(&token::COMMA) {
self.ecx.span_err(sp, "expected token: `,`"); self.ecx.span_err(sp, "expected token: `,`");
return (extra, None); return (extra, None);
} }
if *p.token == token::EOF { break } // accept trailing commas if p.token == token::EOF { break } // accept trailing commas
if named || (token::is_ident(p.token) && if named || (token::is_ident(&p.token) &&
p.look_ahead(1, |t| *t == token::EQ)) { p.look_ahead(1, |t| *t == token::EQ)) {
named = true; named = true;
let ident = match *p.token { let ident = match p.token {
token::IDENT(i, _) => { token::IDENT(i, _) => {
p.bump(); p.bump();
i i

View file

@ -438,10 +438,12 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal {
"expr" => token::nt_expr(p.parse_expr()), "expr" => token::nt_expr(p.parse_expr()),
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), "ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one // this could be handled like a token, since it is one
"ident" => match *p.token { "ident" => match p.token {
token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) } token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) }
_ => p.fatal(~"expected ident, found " _ => {
+ token::to_str(get_ident_interner(), p.token)) let token_str = token::to_str(get_ident_interner(), &p.token);
p.fatal(~"expected ident, found " + token_str)
}
}, },
"path" => { "path" => {
token::nt_path(~p.parse_path(LifetimeAndTypesWithoutColons).path) token::nt_path(~p.parse_path(LifetimeAndTypesWithoutColons).path)

View file

@ -40,10 +40,10 @@ impl ParserAnyMacro {
/// allowed to be there. /// allowed to be there.
fn ensure_complete_parse(&self, allow_semi: bool) { fn ensure_complete_parse(&self, allow_semi: bool) {
let mut parser = self.parser.borrow_mut(); let mut parser = self.parser.borrow_mut();
if allow_semi && *parser.get().token == SEMI { if allow_semi && parser.get().token == SEMI {
parser.get().bump() parser.get().bump()
} }
if *parser.get().token != EOF { if parser.get().token != EOF {
let token_str = parser.get().this_token_to_str(); let token_str = parser.get().this_token_to_str();
let msg = format!("macro expansion ignores token `{}` and any \ let msg = format!("macro expansion ignores token `{}` and any \
following", following",

View file

@ -33,7 +33,7 @@ impl parser_attr for Parser {
loop { loop {
debug!("parse_outer_attributes: self.token={:?}", debug!("parse_outer_attributes: self.token={:?}",
self.token); self.token);
match *self.token { match self.token {
token::INTERPOLATED(token::nt_attr(..)) => { token::INTERPOLATED(token::nt_attr(..)) => {
attrs.push(self.parse_attribute(false)); attrs.push(self.parse_attribute(false));
} }
@ -68,7 +68,7 @@ impl parser_attr for Parser {
fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute { fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute {
debug!("parse_attributes: permit_inner={:?} self.token={:?}", debug!("parse_attributes: permit_inner={:?} self.token={:?}",
permit_inner, self.token); permit_inner, self.token);
let (span, value) = match *self.token { let (span, value) = match self.token {
INTERPOLATED(token::nt_attr(attr)) => { INTERPOLATED(token::nt_attr(attr)) => {
assert!(attr.node.style == ast::AttrOuter); assert!(attr.node.style == ast::AttrOuter);
self.bump(); self.bump();
@ -89,7 +89,7 @@ impl parser_attr for Parser {
token_str)); token_str));
} }
}; };
let style = if permit_inner && *self.token == token::SEMI { let style = if permit_inner && self.token == token::SEMI {
self.bump(); self.bump();
ast::AttrInner ast::AttrInner
} else { } else {
@ -120,7 +120,7 @@ impl parser_attr for Parser {
let mut inner_attrs: ~[ast::Attribute] = ~[]; let mut inner_attrs: ~[ast::Attribute] = ~[];
let mut next_outer_attrs: ~[ast::Attribute] = ~[]; let mut next_outer_attrs: ~[ast::Attribute] = ~[];
loop { loop {
let attr = match *self.token { let attr = match self.token {
token::INTERPOLATED(token::nt_attr(..)) => { token::INTERPOLATED(token::nt_attr(..)) => {
self.parse_attribute(true) self.parse_attribute(true)
} }
@ -158,7 +158,7 @@ impl parser_attr for Parser {
let lo = self.span.lo; let lo = self.span.lo;
let ident = self.parse_ident(); let ident = self.parse_ident();
let name = self.id_to_str(ident); let name = self.id_to_str(ident);
match *self.token { match self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
let lit = self.parse_lit(); let lit = self.parse_lit();
@ -196,7 +196,7 @@ impl parser_attr for Parser {
} }
fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] { fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] {
match *self.token { match self.token {
token::LPAREN => self.parse_meta_seq(), token::LPAREN => self.parse_meta_seq(),
_ => ~[] _ => ~[]
} }

View file

@ -631,7 +631,7 @@ mod test {
} }
fn parser_done(p: Parser){ fn parser_done(p: Parser){
assert_eq!((*p.token).clone(), token::EOF); assert_eq!(p.token.clone(), token::EOF);
} }
#[test] fn parse_ident_pat () { #[test] fn parse_ident_pat () {

View file

@ -20,7 +20,6 @@ removed.
use ast::{Expr, ExprLit, lit_nil}; use ast::{Expr, ExprLit, lit_nil};
use codemap::{Span, respan}; use codemap::{Span, respan};
use parse::parser::Parser; use parse::parser::Parser;
use parse::token::Token;
use parse::token; use parse::token;
use std::str; use std::str;
@ -66,7 +65,6 @@ pub trait ParserObsoleteMethods {
kind: ObsoleteSyntax, kind: ObsoleteSyntax,
kind_str: &str, kind_str: &str,
desc: &str); desc: &str);
fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token) -> bool;
fn is_obsolete_ident(&mut self, ident: &str) -> bool; fn is_obsolete_ident(&mut self, ident: &str) -> bool;
fn eat_obsolete_ident(&mut self, ident: &str) -> bool; fn eat_obsolete_ident(&mut self, ident: &str) -> bool;
} }
@ -176,9 +174,8 @@ impl ParserObsoleteMethods for Parser {
} }
} }
fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token) fn is_obsolete_ident(&mut self, ident: &str) -> bool {
-> bool { match self.token {
match *token {
token::IDENT(sid, _) => { token::IDENT(sid, _) => {
str::eq_slice(self.id_to_str(sid), ident) str::eq_slice(self.id_to_str(sid), ident)
} }
@ -186,10 +183,6 @@ impl ParserObsoleteMethods for Parser {
} }
} }
fn is_obsolete_ident(&mut self, ident: &str) -> bool {
self.token_is_obsolete_ident(ident, self.token)
}
fn eat_obsolete_ident(&mut self, ident: &str) -> bool { fn eat_obsolete_ident(&mut self, ident: &str) -> bool {
if self.is_obsolete_ident(ident) { if self.is_obsolete_ident(ident) {
self.bump(); self.bump();

File diff suppressed because it is too large Load diff