Skip to content

Commit

Permalink
libsyntax: Fix snake_case errors.
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Ryman committed May 30, 2014
1 parent 16f15ce commit 190d8bd
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 68 deletions.
3 changes: 2 additions & 1 deletion src/libsyntax/abi.rs
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -159,6 +159,7 @@ impl fmt::Show for Abi {
}
}

#[allow(non_snake_case_functions)]
#[test]
fn lookup_Rust() {
let abi = lookup("Rust");
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ast.rs
Expand Up @@ -26,6 +26,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
pub type P<T> = @T;

#[allow(non_snake_case_functions)]
/// Construct a P<T> from a T value.
pub fn P<T: 'static>(value: T) -> P<T> {
@value
Expand Down
41 changes: 24 additions & 17 deletions src/libsyntax/ext/mtwt.rs
Expand Up @@ -223,7 +223,7 @@ fn marksof_internal(ctxt: SyntaxContext,
return result;
},
Mark(mark, tl) => {
xorPush(&mut result, mark);
xor_push(&mut result, mark);
loopvar = tl;
},
Rename(_,name,tl) => {
Expand Down Expand Up @@ -253,7 +253,7 @@ pub fn outer_mark(ctxt: SyntaxContext) -> Mrk {

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

#[test] fn xorpush_test () {
#[test]
fn xorpush_test () {
let mut s = Vec::new();
xorPush(&mut s, 14);
xor_push(&mut s, 14);
assert_eq!(s.clone(), vec!(14));
xorPush(&mut s, 14);
xor_push(&mut s, 14);
assert_eq!(s.clone(), Vec::new());
xorPush(&mut s, 14);
xor_push(&mut s, 14);
assert_eq!(s.clone(), vec!(14));
xorPush(&mut s, 15);
xor_push(&mut s, 15);
assert_eq!(s.clone(), vec!(14, 15));
xorPush(&mut s, 16);
xor_push(&mut s, 16);
assert_eq!(s.clone(), vec!(14, 15, 16));
xorPush(&mut s, 16);
xor_push(&mut s, 16);
assert_eq!(s.clone(), vec!(14, 15));
xorPush(&mut s, 15);
xor_push(&mut s, 15);
assert_eq!(s.clone(), vec!(14));
}

Expand Down Expand Up @@ -331,7 +332,8 @@ mod tests {
}
}

#[test] fn test_unfold_refold(){
#[test]
fn test_unfold_refold(){
let mut t = new_sctable_internal();

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

#[test] fn test_marksof () {
#[test]
fn test_marksof () {
let stopname = 242;
let name1 = 243;
let mut t = new_sctable_internal();
Expand Down Expand Up @@ -397,7 +400,8 @@ mod tests {
}


#[test] fn resolve_tests () {
#[test]
fn resolve_tests () {
let a = 40;
let mut t = new_sctable_internal();
let mut rt = HashMap::new();
Expand Down Expand Up @@ -447,13 +451,15 @@ mod tests {
assert_eq!(resolve_internal(id(a,a50_to_a51_b),&mut t, &mut rt),50);}
}

#[test] fn mtwt_resolve_test(){
#[test]
fn mtwt_resolve_test(){
let a = 40;
assert_eq!(resolve(id(a,EMPTY_CTXT)),a);
}


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

#[test] fn resolve_table_hashing_tests() {
#[test]
fn resolve_table_hashing_tests() {
let mut t = new_sctable_internal();
let mut rt = HashMap::new();
assert_eq!(rt.len(),0);
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/tt/macro_parser.rs
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -402,7 +402,7 @@ pub fn parse(sess: &ParseSess,
}
rdr.next_token();
} else /* bb_eis.len() == 1 */ {
let mut rust_parser = Parser(sess, cfg.clone(), box rdr.clone());
let mut rust_parser = Parser::new(sess, cfg.clone(), box rdr.clone());

let mut ei = bb_eis.pop().unwrap();
match ei.elts.get(ei.idx).node {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Expand Up @@ -171,7 +171,7 @@ fn generic_extension(cx: &ExtCtxt,
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
Some(named_matches),
rhs);
let p = Parser(cx.parse_sess(), cx.cfg(), box trncbr);
let p = Parser::new(cx.parse_sess(), cx.cfg(), box trncbr);
// Let the context choose how to interpret the result.
// Weird, but useful for X-macros.
return box ParserAnyMacro {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/mod.rs
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -256,7 +256,7 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
// parsing tt's probably shouldn't require a parser at all.
let cfg = Vec::new();
let srdr = lexer::new_string_reader(&sess.span_diagnostic, filemap);
let mut p1 = Parser(sess, cfg, box srdr);
let mut p1 = Parser::new(sess, cfg, box srdr);
p1.parse_all_token_trees()
}

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

// abort if necessary
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/obsolete.rs
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -19,7 +19,7 @@ removed.

use ast::{Expr, ExprLit, LitNil};
use codemap::{Span, respan};
use parse::parser::Parser;
use parse::parser;
use parse::token;

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

impl<'a> ParserObsoleteMethods for Parser<'a> {
impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
/// Reports an obsolete syntax non-fatal error.
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
let (kind_str, desc) = match kind {
Expand Down
78 changes: 37 additions & 41 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -278,50 +278,11 @@ struct ParsedItemsAndViewItems {
attrs_remaining: Vec<Attribute> ,
view_items: Vec<ViewItem> ,
items: Vec<@Item> ,
foreign_items: Vec<@ForeignItem> }
foreign_items: Vec<@ForeignItem>
}

/* ident is handled by common.rs */

pub fn Parser<'a>(
sess: &'a ParseSess,
cfg: ast::CrateConfig,
mut rdr: Box<Reader:>)
-> Parser<'a> {
let tok0 = rdr.next_token();
let span = tok0.sp;
let placeholder = TokenAndSpan {
tok: token::UNDERSCORE,
sp: span,
};

Parser {
reader: rdr,
interner: token::get_ident_interner(),
sess: sess,
cfg: cfg,
token: tok0.tok,
span: span,
last_span: span,
last_token: None,
buffer: [
placeholder.clone(),
placeholder.clone(),
placeholder.clone(),
placeholder.clone(),
],
buffer_start: 0,
buffer_end: 0,
tokens_consumed: 0,
restriction: UNRESTRICTED,
quote_depth: 0,
obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(),
open_braces: Vec::new(),
owns_directory: true,
root_module_name: None,
}
}

pub struct Parser<'a> {
pub sess: &'a ParseSess,
// the current token:
Expand Down Expand Up @@ -362,6 +323,41 @@ fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
}

impl<'a> Parser<'a> {
pub fn new(sess: &'a ParseSess, cfg: ast::CrateConfig, mut rdr: Box<Reader:>) -> Parser<'a> {
let tok0 = rdr.next_token();
let span = tok0.sp;
let placeholder = TokenAndSpan {
tok: token::UNDERSCORE,
sp: span,
};

Parser {
reader: rdr,
interner: token::get_ident_interner(),
sess: sess,
cfg: cfg,
token: tok0.tok,
span: span,
last_span: span,
last_token: None,
buffer: [
placeholder.clone(),
placeholder.clone(),
placeholder.clone(),
placeholder.clone(),
],
buffer_start: 0,
buffer_end: 0,
tokens_consumed: 0,
restriction: UNRESTRICTED,
quote_depth: 0,
obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(),
open_braces: Vec::new(),
owns_directory: true,
root_module_name: None,
}
}
// convert a token to a string using self's reader
pub fn token_to_str(token: &token::Token) -> String {
token::to_str(token)
Expand Down

0 comments on commit 190d8bd

Please sign in to comment.