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]
This commit is contained in:
parent
16f15ce391
commit
190d8bdbc6
8 changed files with 73 additions and 68 deletions
|
@ -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
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -159,6 +159,7 @@ impl fmt::Show for Abi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case_functions)]
|
||||||
#[test]
|
#[test]
|
||||||
fn lookup_Rust() {
|
fn lookup_Rust() {
|
||||||
let abi = lookup("Rust");
|
let abi = lookup("Rust");
|
||||||
|
|
|
@ -26,6 +26,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||||
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
|
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
|
||||||
pub type P<T> = @T;
|
pub type P<T> = @T;
|
||||||
|
|
||||||
|
#[allow(non_snake_case_functions)]
|
||||||
/// Construct a P<T> from a T value.
|
/// Construct a P<T> from a T value.
|
||||||
pub fn P<T: 'static>(value: T) -> P<T> {
|
pub fn P<T: 'static>(value: T) -> P<T> {
|
||||||
@value
|
@value
|
||||||
|
|
|
@ -223,7 +223,7 @@ fn marksof_internal(ctxt: SyntaxContext,
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
Mark(mark, tl) => {
|
Mark(mark, tl) => {
|
||||||
xorPush(&mut result, mark);
|
xor_push(&mut result, mark);
|
||||||
loopvar = tl;
|
loopvar = tl;
|
||||||
},
|
},
|
||||||
Rename(_,name,tl) => {
|
Rename(_,name,tl) => {
|
||||||
|
@ -253,7 +253,7 @@ pub fn outer_mark(ctxt: SyntaxContext) -> Mrk {
|
||||||
|
|
||||||
// Push a name... unless it matches the one on top, in which
|
// Push a name... unless it matches the one on top, in which
|
||||||
// case pop and discard (so two of the same marks cancel)
|
// 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) {
|
if (marks.len() > 0) && (*marks.last().unwrap() == mark) {
|
||||||
marks.pop().unwrap();
|
marks.pop().unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,26 +264,27 @@ fn xorPush(marks: &mut Vec<Mrk>, mark: Mrk) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ast::*;
|
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::{new_rename_internal, marksof_internal, resolve_internal};
|
||||||
use super::{SCTable, EmptyCtxt, Mark, Rename, IllegalCtxt};
|
use super::{SCTable, EmptyCtxt, Mark, Rename, IllegalCtxt};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
|
||||||
#[test] fn xorpush_test () {
|
#[test]
|
||||||
|
fn xorpush_test () {
|
||||||
let mut s = Vec::new();
|
let mut s = Vec::new();
|
||||||
xorPush(&mut s, 14);
|
xor_push(&mut s, 14);
|
||||||
assert_eq!(s.clone(), vec!(14));
|
assert_eq!(s.clone(), vec!(14));
|
||||||
xorPush(&mut s, 14);
|
xor_push(&mut s, 14);
|
||||||
assert_eq!(s.clone(), Vec::new());
|
assert_eq!(s.clone(), Vec::new());
|
||||||
xorPush(&mut s, 14);
|
xor_push(&mut s, 14);
|
||||||
assert_eq!(s.clone(), vec!(14));
|
assert_eq!(s.clone(), vec!(14));
|
||||||
xorPush(&mut s, 15);
|
xor_push(&mut s, 15);
|
||||||
assert_eq!(s.clone(), vec!(14, 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));
|
assert_eq!(s.clone(), vec!(14, 15, 16));
|
||||||
xorPush(&mut s, 16);
|
xor_push(&mut s, 16);
|
||||||
assert_eq!(s.clone(), vec!(14, 15));
|
assert_eq!(s.clone(), vec!(14, 15));
|
||||||
xorPush(&mut s, 15);
|
xor_push(&mut s, 15);
|
||||||
assert_eq!(s.clone(), vec!(14));
|
assert_eq!(s.clone(), vec!(14));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +332,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn test_unfold_refold(){
|
#[test]
|
||||||
|
fn test_unfold_refold(){
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
|
|
||||||
let test_sc = vec!(M(3),R(id(101,0),14),M(9));
|
let test_sc = vec!(M(3),R(id(101,0),14),M(9));
|
||||||
|
@ -364,7 +366,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn test_marksof () {
|
#[test]
|
||||||
|
fn test_marksof () {
|
||||||
let stopname = 242;
|
let stopname = 242;
|
||||||
let name1 = 243;
|
let name1 = 243;
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
|
@ -397,7 +400,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test] fn resolve_tests () {
|
#[test]
|
||||||
|
fn resolve_tests () {
|
||||||
let a = 40;
|
let a = 40;
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
let mut rt = HashMap::new();
|
let mut rt = HashMap::new();
|
||||||
|
@ -447,13 +451,15 @@ mod tests {
|
||||||
assert_eq!(resolve_internal(id(a,a50_to_a51_b),&mut t, &mut rt),50);}
|
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;
|
let a = 40;
|
||||||
assert_eq!(resolve(id(a,EMPTY_CTXT)),a);
|
assert_eq!(resolve(id(a,EMPTY_CTXT)),a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test] fn hashing_tests () {
|
#[test]
|
||||||
|
fn hashing_tests () {
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
assert_eq!(new_mark_internal(12,EMPTY_CTXT,&mut t),2);
|
assert_eq!(new_mark_internal(12,EMPTY_CTXT,&mut t),2);
|
||||||
assert_eq!(new_mark_internal(13,EMPTY_CTXT,&mut t),3);
|
assert_eq!(new_mark_internal(13,EMPTY_CTXT,&mut t),3);
|
||||||
|
@ -462,7 +468,8 @@ mod tests {
|
||||||
// I'm assuming that the rename table will behave the same....
|
// 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 t = new_sctable_internal();
|
||||||
let mut rt = HashMap::new();
|
let mut rt = HashMap::new();
|
||||||
assert_eq!(rt.len(),0);
|
assert_eq!(rt.len(),0);
|
||||||
|
|
|
@ -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
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -402,7 +402,7 @@ pub fn parse(sess: &ParseSess,
|
||||||
}
|
}
|
||||||
rdr.next_token();
|
rdr.next_token();
|
||||||
} else /* bb_eis.len() == 1 */ {
|
} 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();
|
let mut ei = bb_eis.pop().unwrap();
|
||||||
match ei.elts.get(ei.idx).node {
|
match ei.elts.get(ei.idx).node {
|
||||||
|
|
|
@ -171,7 +171,7 @@ fn generic_extension(cx: &ExtCtxt,
|
||||||
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
|
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
|
||||||
Some(named_matches),
|
Some(named_matches),
|
||||||
rhs);
|
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.
|
// Let the context choose how to interpret the result.
|
||||||
// Weird, but useful for X-macros.
|
// Weird, but useful for X-macros.
|
||||||
return box ParserAnyMacro {
|
return box ParserAnyMacro {
|
||||||
|
|
|
@ -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
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -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.
|
// parsing tt's probably shouldn't require a parser at all.
|
||||||
let cfg = Vec::new();
|
let cfg = Vec::new();
|
||||||
let srdr = lexer::new_string_reader(&sess.span_diagnostic, filemap);
|
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()
|
p1.parse_all_token_trees()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ pub fn tts_to_parser<'a>(sess: &'a ParseSess,
|
||||||
tts: Vec<ast::TokenTree>,
|
tts: Vec<ast::TokenTree>,
|
||||||
cfg: ast::CrateConfig) -> Parser<'a> {
|
cfg: ast::CrateConfig) -> Parser<'a> {
|
||||||
let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, tts);
|
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
|
// abort if necessary
|
||||||
|
|
|
@ -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
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -19,7 +19,7 @@ removed.
|
||||||
|
|
||||||
use ast::{Expr, ExprLit, LitNil};
|
use ast::{Expr, ExprLit, LitNil};
|
||||||
use codemap::{Span, respan};
|
use codemap::{Span, respan};
|
||||||
use parse::parser::Parser;
|
use parse::parser;
|
||||||
use parse::token;
|
use parse::token;
|
||||||
|
|
||||||
/// The specific types of unsupported syntax
|
/// The specific types of unsupported syntax
|
||||||
|
@ -45,7 +45,7 @@ pub trait ParserObsoleteMethods {
|
||||||
fn eat_obsolete_ident(&mut self, ident: &str) -> bool;
|
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.
|
/// Reports an obsolete syntax non-fatal error.
|
||||||
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
|
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
|
||||||
let (kind_str, desc) = match kind {
|
let (kind_str, desc) = match kind {
|
||||||
|
|
|
@ -278,50 +278,11 @@ struct ParsedItemsAndViewItems {
|
||||||
attrs_remaining: Vec<Attribute> ,
|
attrs_remaining: Vec<Attribute> ,
|
||||||
view_items: Vec<ViewItem> ,
|
view_items: Vec<ViewItem> ,
|
||||||
items: Vec<@Item> ,
|
items: Vec<@Item> ,
|
||||||
foreign_items: Vec<@ForeignItem> }
|
foreign_items: Vec<@ForeignItem>
|
||||||
|
}
|
||||||
|
|
||||||
/* ident is handled by common.rs */
|
/* 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 struct Parser<'a> {
|
||||||
pub sess: &'a ParseSess,
|
pub sess: &'a ParseSess,
|
||||||
// the current token:
|
// the current token:
|
||||||
|
@ -362,6 +323,41 @@ fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
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
|
// convert a token to a string using self's reader
|
||||||
pub fn token_to_str(token: &token::Token) -> String {
|
pub fn token_to_str(token: &token::Token) -> String {
|
||||||
token::to_str(token)
|
token::to_str(token)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue