diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-09-27 21:01:58 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-09-30 23:21:19 -0700 |
| commit | af3b132285bc9314d545cae2e4eaef079a26252a (patch) | |
| tree | 1c7116cb4d82388a6eb3da6e4088448ea24016ba /src/libsyntax/parse | |
| parent | 7e709bfd0dac1d5bbe5c97494980731b4d477e8f (diff) | |
| download | rust-af3b132285bc9314d545cae2e4eaef079a26252a.tar.gz rust-af3b132285bc9314d545cae2e4eaef079a26252a.zip | |
syntax: Remove usage of fmt!
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 32 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 117 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 12 |
7 files changed, 92 insertions, 94 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 1bc334f1140..dba2f0b9417 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -32,7 +32,7 @@ impl parser_attr for Parser { fn parse_outer_attributes(&self) -> ~[ast::Attribute] { let mut attrs: ~[ast::Attribute] = ~[]; loop { - debug!("parse_outer_attributes: self.token=%?", + debug2!("parse_outer_attributes: self.token={:?}", self.token); match *self.token { token::INTERPOLATED(token::nt_attr(*)) => { @@ -67,7 +67,7 @@ impl parser_attr for Parser { // if permit_inner is true, then a trailing `;` indicates an inner // attribute fn parse_attribute(&self, permit_inner: bool) -> ast::Attribute { - debug!("parse_attributes: permit_inner=%? self.token=%?", + debug2!("parse_attributes: permit_inner={:?} self.token={:?}", permit_inner, self.token); let (span, value) = match *self.token { INTERPOLATED(token::nt_attr(attr)) => { @@ -85,8 +85,8 @@ impl parser_attr for Parser { (mk_sp(lo, hi), meta_item) } _ => { - self.fatal(fmt!("expected `#` but found `%s`", - self.this_token_to_str())); + self.fatal(format!("expected `\\#` but found `{}`", + self.this_token_to_str())); } }; let style = if permit_inner && *self.token == token::SEMI { diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 88c9fc3e0f7..f163bec7d4e 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -134,7 +134,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { return lines.connect("\n"); } - fail!("not a doc-comment: %s", comment); + fail2!("not a doc-comment: {}", comment); } fn read_to_eol(rdr: @mut StringReader) -> ~str { @@ -161,7 +161,7 @@ fn consume_non_eol_whitespace(rdr: @mut StringReader) { } fn push_blank_line_comment(rdr: @mut StringReader, comments: &mut ~[cmnt]) { - debug!(">>> blank-line comment"); + debug2!(">>> blank-line comment"); let v: ~[~str] = ~[]; comments.push(cmnt {style: blank_line, lines: v, pos: rdr.last_pos}); } @@ -179,9 +179,9 @@ fn consume_whitespace_counting_blank_lines(rdr: @mut StringReader, fn read_shebang_comment(rdr: @mut StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { - debug!(">>> shebang comment"); + debug2!(">>> shebang comment"); let p = rdr.last_pos; - debug!("<<< shebang comment"); + debug2!("<<< shebang comment"); comments.push(cmnt { style: if code_to_the_left { trailing } else { isolated }, lines: ~[read_one_line_comment(rdr)], @@ -191,19 +191,19 @@ fn read_shebang_comment(rdr: @mut StringReader, code_to_the_left: bool, fn read_line_comments(rdr: @mut StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { - debug!(">>> line comments"); + debug2!(">>> line comments"); let p = rdr.last_pos; let mut lines: ~[~str] = ~[]; while rdr.curr == '/' && nextch(rdr) == '/' { let line = read_one_line_comment(rdr); - debug!("%s", line); + debug2!("{}", line); if is_doc_comment(line) { // doc-comments are not put in comments break; } lines.push(line); consume_non_eol_whitespace(rdr); } - debug!("<<< line comments"); + debug2!("<<< line comments"); if !lines.is_empty() { comments.push(cmnt { style: if code_to_the_left { trailing } else { isolated }, @@ -242,14 +242,14 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str], } None => s, }; - debug!("pushing line: %s", s1); + debug2!("pushing line: {}", s1); lines.push(s1); } fn read_block_comment(rdr: @mut StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { - debug!(">>> block comment"); + debug2!(">>> block comment"); let p = rdr.last_pos; let mut lines: ~[~str] = ~[]; let col: CharPos = rdr.col; @@ -275,7 +275,7 @@ fn read_block_comment(rdr: @mut StringReader, } else { let mut level: int = 1; while level > 0 { - debug!("=== block comment level %d", level); + debug2!("=== block comment level {}", level); if is_eof(rdr) { (rdr as @mut reader).fatal(~"unterminated block comment"); } @@ -311,7 +311,7 @@ fn read_block_comment(rdr: @mut StringReader, if !is_eof(rdr) && rdr.curr != '\n' && lines.len() == 1u { style = mixed; } - debug!("<<< block comment"); + debug2!("<<< block comment"); comments.push(cmnt {style: style, lines: lines, pos: p}); } @@ -324,15 +324,15 @@ fn peeking_at_comment(rdr: @mut StringReader) -> bool { fn consume_comment(rdr: @mut StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { - debug!(">>> consume comment"); + debug2!(">>> consume comment"); if rdr.curr == '/' && nextch(rdr) == '/' { read_line_comments(rdr, code_to_the_left, comments); } else if rdr.curr == '/' && nextch(rdr) == '*' { read_block_comment(rdr, code_to_the_left, comments); } else if rdr.curr == '#' && nextch(rdr) == '!' { read_shebang_comment(rdr, code_to_the_left, comments); - } else { fail!(); } - debug!("<<< consume comment"); + } else { fail2!(); } + debug2!("<<< consume comment"); } #[deriving(Clone)] @@ -378,11 +378,11 @@ pub fn gather_comments_and_literals(span_diagnostic: let TokenAndSpan {tok: tok, sp: sp} = rdr.peek(); if token::is_lit(&tok) { do with_str_from(rdr, bstart) |s| { - debug!("tok lit: %s", s); + debug2!("tok lit: {}", s); literals.push(lit {lit: s.to_owned(), pos: sp.lo}); } } else { - debug!("tok: %s", token::to_str(get_ident_interner(), &tok)); + debug2!("tok: {}", token::to_str(get_ident_interner(), &tok)); } first_read = false; } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 09adcc66ea5..640c7c220e5 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -133,7 +133,7 @@ impl reader for TtReader { fn is_eof(@mut self) -> bool { self.cur_tok == token::EOF } fn next_token(@mut self) -> TokenAndSpan { let r = tt_next_token(self); - debug!("TtReader: r=%?", r); + debug2!("TtReader: r={:?}", r); return r; } fn fatal(@mut self, m: ~str) -> ! { @@ -261,7 +261,7 @@ fn hex_digit_val(c: char) -> int { if in_range(c, '0', '9') { return (c as int) - ('0' as int); } if in_range(c, 'a', 'f') { return (c as int) - ('a' as int) + 10; } if in_range(c, 'A', 'F') { return (c as int) - ('A' as int) + 10; } - fail!(); + fail2!(); } fn bin_digit_value(c: char) -> int { if c == '0' { return 0; } return 1; } @@ -569,8 +569,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { ~"int literal is too large") }; - debug!("lexing %s as an unsuffixed integer literal", - num_str); + debug2!("lexing {} as an unsuffixed integer literal", num_str); return token::LIT_INT_UNSUFFIXED(parsed as i64); } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a492a2283e3..67bcab31956 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -416,18 +416,18 @@ mod test { _ => assert_eq!("wrong 4","correct") }, _ => { - error!("failing value 3: %?",first_set); + error2!("failing value 3: {:?}",first_set); assert_eq!("wrong 3","correct") } }, _ => { - error!("failing value 2: %?",delim_elts); + error2!("failing value 2: {:?}",delim_elts); assert_eq!("wrong","correct"); } }, _ => { - error!("failing value: %?",tts); + error2!("failing value: {:?}",tts); assert_eq!("wrong 1","correct"); } } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 66774cb275b..adf0c208da4 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -261,10 +261,10 @@ impl ParserObsoleteMethods for Parser { kind: ObsoleteSyntax, kind_str: &str, desc: &str) { - self.span_err(sp, fmt!("obsolete syntax: %s", kind_str)); + self.span_err(sp, format!("obsolete syntax: {}", kind_str)); if !self.obsolete_set.contains(&kind) { - self.sess.span_diagnostic.handler().note(fmt!("%s", desc)); + self.sess.span_diagnostic.handler().note(format!("{}", desc)); self.obsolete_set.insert(kind); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5a68e32a533..4dd09cbcbd2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -362,8 +362,8 @@ impl Parser { pub fn unexpected_last(&self, t: &token::Token) -> ! { self.span_fatal( *self.last_span, - fmt!( - "unexpected token: `%s`", + format!( + "unexpected token: `{}`", self.token_to_str(t) ) ); @@ -371,8 +371,8 @@ impl Parser { pub fn unexpected(&self) -> ! { self.fatal( - fmt!( - "unexpected token: `%s`", + format!( + "unexpected token: `{}`", self.this_token_to_str() ) ); @@ -385,8 +385,8 @@ impl Parser { self.bump(); } else { self.fatal( - fmt!( - "expected `%s` but found `%s`", + format!( + "expected `{}` but found `{}`", self.token_to_str(t), self.this_token_to_str() ) @@ -414,9 +414,9 @@ impl Parser { let actual = self.this_token_to_str(); self.fatal( if expected.len() != 1 { - fmt!("expected one of `%s` but found `%s`", expect, actual) + format!("expected one of `{}` but found `{}`", expect, actual) } else { - fmt!("expected `%s` but found `%s`", expect, actual) + format!("expected `{}` but found `{}`", expect, actual) } ) } @@ -444,7 +444,7 @@ impl Parser { // followed by some token from the set edible + inedible. Recover // from anticipated input errors, discarding erroneous characters. pub fn commit_expr(&self, e: @Expr, edible: &[token::Token], inedible: &[token::Token]) { - debug!("commit_expr %?", e); + debug2!("commit_expr {:?}", e); match e.node { ExprPath(*) => { // might be unit-struct construction; check for recoverableinput error. @@ -464,7 +464,7 @@ impl Parser { // followed by some token from the set edible + inedible. Check // for recoverable input errors, discarding erroneous characters. pub fn commit_stmt(&self, s: @Stmt, edible: &[token::Token], inedible: &[token::Token]) { - debug!("commit_stmt %?", s); + debug2!("commit_stmt {:?}", s); let _s = s; // unused, but future checks might want to inspect `s`. if self.last_token.map_default(false, |t|is_ident_or_path(*t)) { let expected = vec::append(edible.to_owned(), inedible); @@ -490,8 +490,8 @@ impl Parser { } _ => { self.fatal( - fmt!( - "expected ident, found `%s`", + format!( + "expected ident, found `{}`", self.this_token_to_str() ) ); @@ -536,8 +536,8 @@ impl Parser { pub fn expect_keyword(&self, kw: keywords::Keyword) { if !self.eat_keyword(kw) { self.fatal( - fmt!( - "expected `%s`, found `%s`", + format!( + "expected `{}`, found `{}`", self.id_to_str(kw.to_ident()).to_str(), self.this_token_to_str() ) @@ -549,14 +549,14 @@ impl Parser { pub fn check_strict_keywords(&self) { if token::is_strict_keyword(self.token) { self.span_err(*self.last_span, - fmt!("found `%s` in ident position", self.this_token_to_str())); + format!("found `{}` in ident position", self.this_token_to_str())); } } // signal an error if the current token is a reserved keyword pub fn check_reserved_keywords(&self) { if token::is_reserved_keyword(self.token) { - self.fatal(fmt!("`%s` is a reserved keyword", self.this_token_to_str())); + self.fatal(format!("`{}` is a reserved keyword", self.this_token_to_str())); } } @@ -571,7 +571,7 @@ impl Parser { self.span.lo + BytePos(1u), self.span.hi ), - _ => self.fatal(fmt!("expected `%s`, found `%s`", + _ => self.fatal(format!("expected `{}`, found `{}`", self.token_to_str(&token::GT), self.this_token_to_str())) } @@ -938,13 +938,13 @@ impl Parser { }; let hi = p.last_span.hi; - debug!("parse_trait_methods(): trait method signature ends in \ - `%s`", + debug2!("parse_trait_methods(): trait method signature ends in \ + `{}`", self.this_token_to_str()); match *p.token { token::SEMI => { p.bump(); - debug!("parse_trait_methods(): parsing required method"); + debug2!("parse_trait_methods(): parsing required method"); // NB: at the moment, visibility annotations on required // methods are ignored; this could change. if vis != ast::inherited { @@ -963,7 +963,7 @@ impl Parser { }) } token::LBRACE => { - debug!("parse_trait_methods(): parsing provided method"); + debug2!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = p.parse_inner_attrs_and_block(); let attrs = vec::append(attrs, inner_attrs); @@ -984,8 +984,8 @@ impl Parser { _ => { p.fatal( - fmt!( - "expected `;` or `{` but found `%s`", + format!( + "expected `;` or `\\{` but found `{}`", self.this_token_to_str() ) ); @@ -1153,8 +1153,7 @@ impl Parser { } = self.parse_path(LifetimeAndTypesAndBounds); ty_path(path, bounds, ast::DUMMY_NODE_ID) } else { - self.fatal(fmt!("expected type, found token %?", - *self.token)); + self.fatal(format!("expected type, found token {:?}", *self.token)); }; let sp = mk_sp(lo, self.last_span.hi); @@ -1245,7 +1244,7 @@ impl Parser { _ => 0 }; - debug!("parser is_named_argument offset:%u", offset); + debug2!("parser is_named_argument offset:{}", offset); if offset == 0 { is_plain_ident_or_underscore(&*self.token) @@ -1261,7 +1260,7 @@ impl Parser { pub fn parse_arg_general(&self, require_name: bool) -> arg { let is_mutbl = self.eat_keyword(keywords::Mut); let pat = if require_name || self.is_named_argument() { - debug!("parse_arg_general parse_pat (require_name:%?)", + debug2!("parse_arg_general parse_pat (require_name:{:?})", require_name); self.parse_arg_mode(); let pat = self.parse_pat(); @@ -1273,7 +1272,7 @@ impl Parser { self.expect(&token::COLON); pat } else { - debug!("parse_arg_general ident_to_pat"); + debug2!("parse_arg_general ident_to_pat"); ast_util::ident_to_pat(ast::DUMMY_NODE_ID, *self.last_span, special_idents::invalid) @@ -1581,7 +1580,7 @@ impl Parser { } _ => { - self.fatal(fmt!("Expected a lifetime name")); + self.fatal(format!("Expected a lifetime name")); } } } @@ -1614,7 +1613,7 @@ impl Parser { token::GT => { return res; } token::BINOP(token::SHR) => { return res; } _ => { - self.fatal(fmt!("expected `,` or `>` after lifetime name, got: %?", + self.fatal(format!("expected `,` or `>` after lifetime name, got: {:?}", *self.token)); } } @@ -2067,8 +2066,8 @@ impl Parser { token::RPAREN | token::RBRACE | token::RBRACKET => { p.fatal( - fmt!( - "incorrect close delimiter: `%s`", + format!( + "incorrect close delimiter: `{}`", p.this_token_to_str() ) ); @@ -2561,10 +2560,10 @@ impl Parser { // There may be other types of expressions that can // represent the callee in `for` and `do` expressions // but they aren't represented by tests - debug!("sugary call on %?", e.node); + debug2!("sugary call on {:?}", e.node); self.span_fatal( e.span, - fmt!("`%s` must be followed by a block call", keyword)); + format!("`{}` must be followed by a block call", keyword)); } } } @@ -2759,8 +2758,8 @@ impl Parser { self.bump(); if *self.token != token::RBRACE { self.fatal( - fmt!( - "expected `}`, found `%s`", + format!( + "expected `\\}`, found `{}`", self.this_token_to_str() ) ); @@ -3543,8 +3542,8 @@ impl Parser { fn expect_self_ident(&self) { if !self.is_self_ident() { self.fatal( - fmt!( - "expected `self` but found `%s`", + format!( + "expected `self` but found `{}`", self.this_token_to_str() ) ); @@ -3682,8 +3681,8 @@ impl Parser { } _ => { self.fatal( - fmt!( - "expected `,` or `)`, found `%s`", + format!( + "expected `,` or `)`, found `{}`", self.this_token_to_str() ) ); @@ -3920,7 +3919,7 @@ impl Parser { } } if fields.len() == 0 { - self.fatal(fmt!("Unit-like struct definition should be written as `struct %s;`", + self.fatal(format!("Unit-like struct definition should be written as `struct {};`", get_ident_interner().get(class_name.name))); } self.bump(); @@ -3949,9 +3948,9 @@ impl Parser { fields = ~[]; } else { self.fatal( - fmt!( - "expected `{`, `(`, or `;` after struct name \ - but found `%s`", + format!( + "expected `\\{`, `(`, or `;` after struct name \ + but found `{}`", self.this_token_to_str() ) ); @@ -3995,7 +3994,7 @@ impl Parser { token::RBRACE => {} _ => { self.span_fatal(*self.span, - fmt!("expected `,`, or '}' but found `%s`", + format!("expected `,`, or '\\}' but found `{}`", self.this_token_to_str())); } } @@ -4064,7 +4063,7 @@ impl Parser { attrs = attrs_remaining + attrs; first = false; } - debug!("parse_mod_items: parse_item_or_view_item(attrs=%?)", + debug2!("parse_mod_items: parse_item_or_view_item(attrs={:?})", attrs); match self.parse_item_or_view_item(attrs, true /* macros allowed */) { @@ -4075,7 +4074,7 @@ impl Parser { the module"); } _ => { - self.fatal(fmt!("expected item but found `%s`", + self.fatal(format!("expected item but found `{}`", self.this_token_to_str())); } } @@ -4167,11 +4166,11 @@ impl Parser { (true, false) => default_path, (false, true) => secondary_path, (false, false) => { - self.span_fatal(id_sp, fmt!("file not found for module `%s`", mod_name)); + self.span_fatal(id_sp, format!("file not found for module `{}`", mod_name)); } (true, true) => { self.span_fatal(id_sp, - fmt!("file for module `%s` found at both %s and %s", + format!("file for module `{}` found at both {} and {}", mod_name, default_path_str, secondary_path_str)); } } @@ -4323,7 +4322,7 @@ impl Parser { self.expect_keyword(keywords::Mod); } else if *self.token != token::LBRACE { self.span_fatal(*self.span, - fmt!("expected `{` or `mod` but found `%s`", + format!("expected `\\{` or `mod` but found `{}`", self.this_token_to_str())); } @@ -4340,8 +4339,8 @@ impl Parser { _ => { if must_be_named_mod { self.span_fatal(*self.span, - fmt!("expected foreign module name but \ - found `%s`", + format!("expected foreign module name but \ + found `{}`", self.this_token_to_str())); } @@ -4566,7 +4565,7 @@ impl Parser { if abis.contains(abi) { self.span_err( *self.span, - fmt!("ABI `%s` appears twice", + format!("ABI `{}` appears twice", word)); } else { abis.add(abi); @@ -4576,9 +4575,9 @@ impl Parser { None => { self.span_err( *self.span, - fmt!("illegal ABI: \ - expected one of [%s], \ - found `%s`", + format!("illegal ABI: \ + expected one of [{}], \ + found `{}`", abi::all_names().connect(", "), word)); } @@ -4853,7 +4852,7 @@ impl Parser { let first_ident = self.parse_ident(); let mut path = ~[first_ident]; - debug!("parsed view_path: %s", self.id_to_str(first_ident)); + debug2!("parsed view_path: {}", self.id_to_str(first_ident)); match *self.token { token::EQ => { // x = foo::bar @@ -5061,7 +5060,7 @@ impl Parser { break; } iovi_foreign_item(_) => { - fail!(); + fail2!(); } } attrs = self.parse_outer_attributes(); @@ -5084,7 +5083,7 @@ impl Parser { items.push(item) } iovi_foreign_item(_) => { - fail!(); + fail2!(); } } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index eec4a81b2cf..d0faf917688 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -193,11 +193,11 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { } body } - LIT_STR(ref s) => { fmt!("\"%s\"", ident_to_str(s).escape_default()) } + LIT_STR(ref s) => { format!("\"{}\"", ident_to_str(s).escape_default()) } /* Name components */ IDENT(s, _) => input.get(s.name).to_owned(), - LIFETIME(s) => fmt!("'%s", input.get(s.name)), + LIFETIME(s) => format!("'{}", input.get(s.name)), UNDERSCORE => ~"_", /* Other */ @@ -214,8 +214,8 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { nt_block(*) => ~"block", nt_stmt(*) => ~"statement", nt_pat(*) => ~"pattern", - nt_attr(*) => fail!("should have been handled"), - nt_expr(*) => fail!("should have been handled above"), + nt_attr(*) => fail2!("should have been handled"), + nt_expr(*) => fail2!("should have been handled above"), nt_ty(*) => ~"type", nt_ident(*) => ~"identifier", nt_path(*) => ~"path", @@ -269,7 +269,7 @@ pub fn flip_delimiter(t: &token::Token) -> token::Token { RPAREN => LPAREN, RBRACE => LBRACE, RBRACKET => LBRACKET, - _ => fail!() + _ => fail2!() } } @@ -553,7 +553,7 @@ pub fn fresh_name(src : &ast::Ident) -> Name { // good error messages and uses of struct names in ambiguous could-be-binding // locations. Also definitely destroys the guarantee given above about ptr_eq. /*let num = rand::rng().gen_uint_range(0,0xffff); - gensym(fmt!("%s_%u",ident_to_str(src),num))*/ + gensym(format!("{}_{}",ident_to_str(src),num))*/ } // it looks like there oughta be a str_ptr_eq fn, but no one bothered to implement it? |
