Skip to content

Commit 190d8bd

Browse files
committed
libsyntax: Fix snake_case errors.
A number of functions/methods have been moved or renamed to align better with rust standard conventions. syntax::ext::mtwt::xorPush => xor_push syntax::parse::parser::Parser => Parser::new [breaking-change]
1 parent 16f15ce commit 190d8bd

File tree

8 files changed

+73
-68
lines changed

8 files changed

+73
-68
lines changed

src/libsyntax/abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -159,6 +159,7 @@ impl fmt::Show for Abi {
159159
}
160160
}
161161

162+
#[allow(non_snake_case_functions)]
162163
#[test]
163164
fn lookup_Rust() {
164165
let abi = lookup("Rust");

src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
2626
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
2727
pub type P<T> = @T;
2828

29+
#[allow(non_snake_case_functions)]
2930
/// Construct a P<T> from a T value.
3031
pub fn P<T: 'static>(value: T) -> P<T> {
3132
@value

src/libsyntax/ext/mtwt.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn marksof_internal(ctxt: SyntaxContext,
223223
return result;
224224
},
225225
Mark(mark, tl) => {
226-
xorPush(&mut result, mark);
226+
xor_push(&mut result, mark);
227227
loopvar = tl;
228228
},
229229
Rename(_,name,tl) => {
@@ -253,7 +253,7 @@ pub fn outer_mark(ctxt: SyntaxContext) -> Mrk {
253253

254254
// Push a name... unless it matches the one on top, in which
255255
// case pop and discard (so two of the same marks cancel)
256-
fn xorPush(marks: &mut Vec<Mrk>, mark: Mrk) {
256+
fn xor_push(marks: &mut Vec<Mrk>, mark: Mrk) {
257257
if (marks.len() > 0) && (*marks.last().unwrap() == mark) {
258258
marks.pop().unwrap();
259259
} else {
@@ -264,26 +264,27 @@ fn xorPush(marks: &mut Vec<Mrk>, mark: Mrk) {
264264
#[cfg(test)]
265265
mod tests {
266266
use ast::*;
267-
use super::{resolve, xorPush, new_mark_internal, new_sctable_internal};
267+
use super::{resolve, xor_push, new_mark_internal, new_sctable_internal};
268268
use super::{new_rename_internal, marksof_internal, resolve_internal};
269269
use super::{SCTable, EmptyCtxt, Mark, Rename, IllegalCtxt};
270270
use collections::HashMap;
271271

272-
#[test] fn xorpush_test () {
272+
#[test]
273+
fn xorpush_test () {
273274
let mut s = Vec::new();
274-
xorPush(&mut s, 14);
275+
xor_push(&mut s, 14);
275276
assert_eq!(s.clone(), vec!(14));
276-
xorPush(&mut s, 14);
277+
xor_push(&mut s, 14);
277278
assert_eq!(s.clone(), Vec::new());
278-
xorPush(&mut s, 14);
279+
xor_push(&mut s, 14);
279280
assert_eq!(s.clone(), vec!(14));
280-
xorPush(&mut s, 15);
281+
xor_push(&mut s, 15);
281282
assert_eq!(s.clone(), vec!(14, 15));
282-
xorPush(&mut s, 16);
283+
xor_push(&mut s, 16);
283284
assert_eq!(s.clone(), vec!(14, 15, 16));
284-
xorPush(&mut s, 16);
285+
xor_push(&mut s, 16);
285286
assert_eq!(s.clone(), vec!(14, 15));
286-
xorPush(&mut s, 15);
287+
xor_push(&mut s, 15);
287288
assert_eq!(s.clone(), vec!(14));
288289
}
289290

@@ -331,7 +332,8 @@ mod tests {
331332
}
332333
}
333334

334-
#[test] fn test_unfold_refold(){
335+
#[test]
336+
fn test_unfold_refold(){
335337
let mut t = new_sctable_internal();
336338

337339
let test_sc = vec!(M(3),R(id(101,0),14),M(9));
@@ -364,7 +366,8 @@ mod tests {
364366
}
365367
}
366368

367-
#[test] fn test_marksof () {
369+
#[test]
370+
fn test_marksof () {
368371
let stopname = 242;
369372
let name1 = 243;
370373
let mut t = new_sctable_internal();
@@ -397,7 +400,8 @@ mod tests {
397400
}
398401

399402

400-
#[test] fn resolve_tests () {
403+
#[test]
404+
fn resolve_tests () {
401405
let a = 40;
402406
let mut t = new_sctable_internal();
403407
let mut rt = HashMap::new();
@@ -447,13 +451,15 @@ mod tests {
447451
assert_eq!(resolve_internal(id(a,a50_to_a51_b),&mut t, &mut rt),50);}
448452
}
449453

450-
#[test] fn mtwt_resolve_test(){
454+
#[test]
455+
fn mtwt_resolve_test(){
451456
let a = 40;
452457
assert_eq!(resolve(id(a,EMPTY_CTXT)),a);
453458
}
454459

455460

456-
#[test] fn hashing_tests () {
461+
#[test]
462+
fn hashing_tests () {
457463
let mut t = new_sctable_internal();
458464
assert_eq!(new_mark_internal(12,EMPTY_CTXT,&mut t),2);
459465
assert_eq!(new_mark_internal(13,EMPTY_CTXT,&mut t),3);
@@ -462,7 +468,8 @@ mod tests {
462468
// I'm assuming that the rename table will behave the same....
463469
}
464470

465-
#[test] fn resolve_table_hashing_tests() {
471+
#[test]
472+
fn resolve_table_hashing_tests() {
466473
let mut t = new_sctable_internal();
467474
let mut rt = HashMap::new();
468475
assert_eq!(rt.len(),0);

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -402,7 +402,7 @@ pub fn parse(sess: &ParseSess,
402402
}
403403
rdr.next_token();
404404
} else /* bb_eis.len() == 1 */ {
405-
let mut rust_parser = Parser(sess, cfg.clone(), box rdr.clone());
405+
let mut rust_parser = Parser::new(sess, cfg.clone(), box rdr.clone());
406406

407407
let mut ei = bb_eis.pop().unwrap();
408408
match ei.elts.get(ei.idx).node {

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn generic_extension(cx: &ExtCtxt,
171171
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
172172
Some(named_matches),
173173
rhs);
174-
let p = Parser(cx.parse_sess(), cx.cfg(), box trncbr);
174+
let p = Parser::new(cx.parse_sess(), cx.cfg(), box trncbr);
175175
// Let the context choose how to interpret the result.
176176
// Weird, but useful for X-macros.
177177
return box ParserAnyMacro {

src/libsyntax/parse/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -256,7 +256,7 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
256256
// parsing tt's probably shouldn't require a parser at all.
257257
let cfg = Vec::new();
258258
let srdr = lexer::new_string_reader(&sess.span_diagnostic, filemap);
259-
let mut p1 = Parser(sess, cfg, box srdr);
259+
let mut p1 = Parser::new(sess, cfg, box srdr);
260260
p1.parse_all_token_trees()
261261
}
262262

@@ -265,7 +265,7 @@ pub fn tts_to_parser<'a>(sess: &'a ParseSess,
265265
tts: Vec<ast::TokenTree>,
266266
cfg: ast::CrateConfig) -> Parser<'a> {
267267
let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, tts);
268-
Parser(sess, cfg, box trdr)
268+
Parser::new(sess, cfg, box trdr)
269269
}
270270

271271
// abort if necessary

src/libsyntax/parse/obsolete.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -19,7 +19,7 @@ removed.
1919

2020
use ast::{Expr, ExprLit, LitNil};
2121
use codemap::{Span, respan};
22-
use parse::parser::Parser;
22+
use parse::parser;
2323
use parse::token;
2424

2525
/// The specific types of unsupported syntax
@@ -45,7 +45,7 @@ pub trait ParserObsoleteMethods {
4545
fn eat_obsolete_ident(&mut self, ident: &str) -> bool;
4646
}
4747

48-
impl<'a> ParserObsoleteMethods for Parser<'a> {
48+
impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
4949
/// Reports an obsolete syntax non-fatal error.
5050
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
5151
let (kind_str, desc) = match kind {

src/libsyntax/parse/parser.rs

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -278,50 +278,11 @@ struct ParsedItemsAndViewItems {
278278
attrs_remaining: Vec<Attribute> ,
279279
view_items: Vec<ViewItem> ,
280280
items: Vec<@Item> ,
281-
foreign_items: Vec<@ForeignItem> }
281+
foreign_items: Vec<@ForeignItem>
282+
}
282283

283284
/* ident is handled by common.rs */
284285

285-
pub fn Parser<'a>(
286-
sess: &'a ParseSess,
287-
cfg: ast::CrateConfig,
288-
mut rdr: Box<Reader:>)
289-
-> Parser<'a> {
290-
let tok0 = rdr.next_token();
291-
let span = tok0.sp;
292-
let placeholder = TokenAndSpan {
293-
tok: token::UNDERSCORE,
294-
sp: span,
295-
};
296-
297-
Parser {
298-
reader: rdr,
299-
interner: token::get_ident_interner(),
300-
sess: sess,
301-
cfg: cfg,
302-
token: tok0.tok,
303-
span: span,
304-
last_span: span,
305-
last_token: None,
306-
buffer: [
307-
placeholder.clone(),
308-
placeholder.clone(),
309-
placeholder.clone(),
310-
placeholder.clone(),
311-
],
312-
buffer_start: 0,
313-
buffer_end: 0,
314-
tokens_consumed: 0,
315-
restriction: UNRESTRICTED,
316-
quote_depth: 0,
317-
obsolete_set: HashSet::new(),
318-
mod_path_stack: Vec::new(),
319-
open_braces: Vec::new(),
320-
owns_directory: true,
321-
root_module_name: None,
322-
}
323-
}
324-
325286
pub struct Parser<'a> {
326287
pub sess: &'a ParseSess,
327288
// the current token:
@@ -362,6 +323,41 @@ fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
362323
}
363324

364325
impl<'a> Parser<'a> {
326+
pub fn new(sess: &'a ParseSess, cfg: ast::CrateConfig, mut rdr: Box<Reader:>) -> Parser<'a> {
327+
let tok0 = rdr.next_token();
328+
let span = tok0.sp;
329+
let placeholder = TokenAndSpan {
330+
tok: token::UNDERSCORE,
331+
sp: span,
332+
};
333+
334+
Parser {
335+
reader: rdr,
336+
interner: token::get_ident_interner(),
337+
sess: sess,
338+
cfg: cfg,
339+
token: tok0.tok,
340+
span: span,
341+
last_span: span,
342+
last_token: None,
343+
buffer: [
344+
placeholder.clone(),
345+
placeholder.clone(),
346+
placeholder.clone(),
347+
placeholder.clone(),
348+
],
349+
buffer_start: 0,
350+
buffer_end: 0,
351+
tokens_consumed: 0,
352+
restriction: UNRESTRICTED,
353+
quote_depth: 0,
354+
obsolete_set: HashSet::new(),
355+
mod_path_stack: Vec::new(),
356+
open_braces: Vec::new(),
357+
owns_directory: true,
358+
root_module_name: None,
359+
}
360+
}
365361
// convert a token to a string using self's reader
366362
pub fn token_to_str(token: &token::Token) -> String {
367363
token::to_str(token)

0 commit comments

Comments
 (0)