diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-05-31 15:17:22 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-06-01 09:18:27 -0700 |
| commit | 5fb254695b4db9af3d8e33577fae28ae9f7006c5 (patch) | |
| tree | 33a4db59bd936a73594ca144e809b6074d6ccef3 /src/libsyntax | |
| parent | 1e52eede31a1df3627bfa9f43b9d06c730895c01 (diff) | |
| download | rust-5fb254695b4db9af3d8e33577fae28ae9f7006c5.tar.gz rust-5fb254695b4db9af3d8e33577fae28ae9f7006c5.zip | |
Remove all uses of `pub impl`. rs=style
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/abi.rs | 42 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/codemap.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 51 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/ty.rs | 59 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 60 | ||||
| -rw-r--r-- | src/libsyntax/parse/common.rs | 96 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 27 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 219 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 43 | ||||
| -rw-r--r-- | src/libsyntax/util/interner.rs | 34 |
13 files changed, 360 insertions, 338 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 2b8d8cb3d31..75439dfaa78 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -109,18 +109,18 @@ pub fn all_names() -> ~[&'static str] { AbiDatas.map(|d| d.name) } -pub impl Abi { +impl Abi { #[inline] - fn index(&self) -> uint { + pub fn index(&self) -> uint { *self as uint } #[inline] - fn data(&self) -> &'static AbiData { + pub fn data(&self) -> &'static AbiData { &AbiDatas[self.index()] } - fn name(&self) -> &'static str { + pub fn name(&self) -> &'static str { self.data().name } } @@ -131,70 +131,70 @@ impl Architecture { } } -pub impl AbiSet { - fn from(abi: Abi) -> AbiSet { +impl AbiSet { + pub fn from(abi: Abi) -> AbiSet { AbiSet { bits: (1 << abi.index()) } } #[inline] - fn Rust() -> AbiSet { + pub fn Rust() -> AbiSet { AbiSet::from(Rust) } #[inline] - fn C() -> AbiSet { + pub fn C() -> AbiSet { AbiSet::from(C) } #[inline] - fn Intrinsic() -> AbiSet { + pub fn Intrinsic() -> AbiSet { AbiSet::from(RustIntrinsic) } - fn default() -> AbiSet { + pub fn default() -> AbiSet { AbiSet::C() } - fn empty() -> AbiSet { + pub fn empty() -> AbiSet { AbiSet { bits: 0 } } #[inline] - fn is_rust(&self) -> bool { + pub fn is_rust(&self) -> bool { self.bits == 1 << Rust.index() } #[inline] - fn is_c(&self) -> bool { + pub fn is_c(&self) -> bool { self.bits == 1 << C.index() } #[inline] - fn is_intrinsic(&self) -> bool { + pub fn is_intrinsic(&self) -> bool { self.bits == 1 << RustIntrinsic.index() } - fn contains(&self, abi: Abi) -> bool { + pub fn contains(&self, abi: Abi) -> bool { (self.bits & (1 << abi.index())) != 0 } - fn subset_of(&self, other_abi_set: AbiSet) -> bool { + pub fn subset_of(&self, other_abi_set: AbiSet) -> bool { (self.bits & other_abi_set.bits) == self.bits } - fn add(&mut self, abi: Abi) { + pub fn add(&mut self, abi: Abi) { self.bits |= (1 << abi.index()); } - fn each(&self, op: &fn(abi: Abi) -> bool) -> bool { + pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool { each_abi(|abi| !self.contains(abi) || op(abi)) } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.bits == 0 } - fn for_arch(&self, arch: Architecture) -> Option<Abi> { + pub fn for_arch(&self, arch: Architecture) -> Option<Abi> { // NB---Single platform ABIs come first for self.each |abi| { let data = abi.data(); @@ -208,7 +208,7 @@ pub impl AbiSet { None } - fn check_valid(&self) -> Option<(Abi, Abi)> { + pub fn check_valid(&self) -> Option<(Abi, Abi)> { let mut abis = ~[]; for self.each |abi| { abis.push(abi); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 676a57e38da..ac9734ebaa3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -166,14 +166,14 @@ pub struct Generics { ty_params: OptVec<TyParam> } -pub impl Generics { - fn is_parameterized(&self) -> bool { +impl Generics { + pub fn is_parameterized(&self) -> bool { self.lifetimes.len() + self.ty_params.len() > 0 } - fn is_lt_parameterized(&self) -> bool { + pub fn is_lt_parameterized(&self) -> bool { self.lifetimes.len() > 0 } - fn is_type_parameterized(&self) -> bool { + pub fn is_type_parameterized(&self) -> bool { self.ty_params.len() > 0 } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index deff6dc5ba9..4da2d500dd8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -373,17 +373,19 @@ pub struct id_range { max: node_id, } -pub impl id_range { - fn max() -> id_range { - id_range {min: int::max_value, - max: int::min_value} +impl id_range { + pub fn max() -> id_range { + id_range { + min: int::max_value, + max: int::min_value, + } } - fn empty(&self) -> bool { + pub fn empty(&self) -> bool { self.min >= self.max } - fn add(&mut self, id: node_id) { + pub fn add(&mut self, id: node_id) { self.min = int::min(self.min, id); self.max = int::max(self.max, id + 1); } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index aedf30127ad..5f8d6e73cef 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -271,13 +271,13 @@ pub struct FileMap { multibyte_chars: @mut ~[MultiByteChar], } -pub impl FileMap { +impl FileMap { // EFFECT: register a start-of-line offset in the // table of line-beginnings. // UNCHECKED INVARIANT: these offsets must be added in the right // order and must be in the right places; there is shared knowledge // about what ends a line between this file and parse.rs - fn next_line(&self, pos: BytePos) { + pub fn next_line(&self, pos: BytePos) { // the new charpos must be > the last one (or it's the first one). let lines = &mut *self.lines; assert!((lines.len() == 0) || (lines[lines.len() - 1] < pos)) @@ -309,7 +309,7 @@ pub struct CodeMap { files: @mut ~[@FileMap] } -pub impl CodeMap { +impl CodeMap { pub fn new() -> CodeMap { CodeMap { files: @mut ~[], @@ -317,16 +317,15 @@ pub impl CodeMap { } /// Add a new FileMap to the CodeMap and return it - fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap { + pub fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap { return self.new_filemap_w_substr(filename, FssNone, src); } - fn new_filemap_w_substr( - &self, - filename: FileName, - substr: FileSubstr, - src: @~str - ) -> @FileMap { + pub fn new_filemap_w_substr(&self, + filename: FileName, + substr: FileSubstr, + src: @~str) + -> @FileMap { let files = &mut *self.files; let start_pos = if files.len() == 0 { 0 @@ -359,8 +358,7 @@ pub impl CodeMap { return self.lookup_pos(pos); } - pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt - { + pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt { let loc = self.lookup_char_pos(pos); match (loc.file.substr) { FssNone => @@ -430,11 +428,9 @@ pub impl CodeMap { // (or expected function, found _|_) fail!(); // ("asking for " + filename + " which we don't know about"); } - } -priv impl CodeMap { - +impl CodeMap { fn lookup_filemap_idx(&self, pos: BytePos) -> uint { let files = &*self.files; let len = files.len(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a9b12c16b31..5fae6ff3c18 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -219,8 +219,9 @@ pub struct ExtCtxt { trace_mac: @mut bool } -pub impl ExtCtxt { - fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) -> @ExtCtxt { +impl ExtCtxt { + pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) + -> @ExtCtxt { @ExtCtxt { parse_sess: parse_sess, cfg: cfg, @@ -230,21 +231,21 @@ pub impl ExtCtxt { } } - fn codemap(&self) -> @CodeMap { self.parse_sess.cm } - fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } - fn cfg(&self) -> ast::crate_cfg { copy self.cfg } - fn call_site(&self) -> span { + pub fn codemap(&self) -> @CodeMap { self.parse_sess.cm } + pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } + pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg } + pub fn call_site(&self) -> span { match *self.backtrace { Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, None => self.bug("missing top span") } } - fn print_backtrace(&self) { } - fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } - fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } - fn mod_pop(&self) { self.mod_path.pop(); } - fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } - fn bt_push(&self, ei: codemap::ExpnInfo) { + pub fn print_backtrace(&self) { } + pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } + pub fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } + pub fn mod_pop(&self) { self.mod_path.pop(); } + pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } + pub fn bt_push(&self, ei: codemap::ExpnInfo) { match ei { ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { *self.backtrace = @@ -255,7 +256,7 @@ pub impl ExtCtxt { } } } - fn bt_pop(&self) { + pub fn bt_pop(&self) { match *self.backtrace { Some(@ExpandedFrom( CallInfo { @@ -266,43 +267,43 @@ pub impl ExtCtxt { _ => self.bug("tried to pop without a push") } } - fn span_fatal(&self, sp: span, msg: &str) -> ! { + pub fn span_fatal(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_fatal(sp, msg); } - fn span_err(&self, sp: span, msg: &str) { + pub fn span_err(&self, sp: span, msg: &str) { self.print_backtrace(); self.parse_sess.span_diagnostic.span_err(sp, msg); } - fn span_warn(&self, sp: span, msg: &str) { + pub fn span_warn(&self, sp: span, msg: &str) { self.print_backtrace(); self.parse_sess.span_diagnostic.span_warn(sp, msg); } - fn span_unimpl(&self, sp: span, msg: &str) -> ! { + pub fn span_unimpl(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_unimpl(sp, msg); } - fn span_bug(&self, sp: span, msg: &str) -> ! { + pub fn span_bug(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_bug(sp, msg); } - fn bug(&self, msg: &str) -> ! { + pub fn bug(&self, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.handler().bug(msg); } - fn next_id(&self) -> ast::node_id { + pub fn next_id(&self) -> ast::node_id { parse::next_node_id(self.parse_sess) } - fn trace_macros(&self) -> bool { + pub fn trace_macros(&self) -> bool { *self.trace_mac } - fn set_trace_macros(&self, x: bool) { + pub fn set_trace_macros(&self, x: bool) { *self.trace_mac = x } - fn str_of(&self, id: ast::ident) -> ~str { + pub fn str_of(&self, id: ast::ident) -> ~str { copy *self.parse_sess.interner.get(id) } - fn ident_of(&self, st: &str) -> ast::ident { + pub fn ident_of(&self, st: &str) -> ast::ident { self.parse_sess.interner.intern(st) } } @@ -436,7 +437,7 @@ impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{ } // traits just don't work anywhere...? -//pub impl Map<Name,SyntaxExtension> for MapChain { +//impl Map<Name,SyntaxExtension> for MapChain { fn contains_key (&self, key: &K) -> bool { match *self { diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index f8f7dc8db5f..3b39cb691a6 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -38,15 +38,18 @@ pub struct Path<'self> { global: bool } -pub impl<'self> Path<'self> { - fn new<'r>(path: ~[&'r str]) -> Path<'r> { +impl<'self> Path<'self> { + pub fn new<'r>(path: ~[&'r str]) -> Path<'r> { Path::new_(path, None, ~[], true) } - fn new_local<'r>(path: &'r str) -> Path<'r> { + pub fn new_local<'r>(path: &'r str) -> Path<'r> { Path::new_(~[ path ], None, ~[], false) } - fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], global: bool) - -> Path<'r> { + pub fn new_<'r>(path: ~[&'r str], + lifetime: Option<&'r str>, + params: ~[~Ty<'r>], + global: bool) + -> Path<'r> { Path { path: path, lifetime: lifetime, @@ -55,13 +58,21 @@ pub impl<'self> Path<'self> { } } - fn to_ty(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Ty { + pub fn to_ty(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Ty { cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } - fn to_path(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Path { + pub fn to_path(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Path { let idents = self.path.map(|s| cx.ident_of(*s) ); let lt = mk_lifetime(cx, span, &self.lifetime); let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); @@ -108,9 +119,13 @@ fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Life } } -pub impl<'self> Ty<'self> { - fn to_ty(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Ty { +impl<'self> Ty<'self> { + pub fn to_ty(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Ty { match *self { Ptr(ref ty, ref ptr) => { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); @@ -143,8 +158,12 @@ pub impl<'self> Ty<'self> { } } - fn to_path(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Path { + pub fn to_path(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Path { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { @@ -192,14 +211,18 @@ pub struct LifetimeBounds<'self> { bounds: ~[(&'self str, ~[Path<'self>])] } -pub impl<'self> LifetimeBounds<'self> { - fn empty() -> LifetimeBounds<'static> { +impl<'self> LifetimeBounds<'self> { + pub fn empty() -> LifetimeBounds<'static> { LifetimeBounds { lifetimes: ~[], bounds: ~[] } } - fn to_generics(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> Generics { + pub fn to_generics(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> Generics { let lifetimes = do self.lifetimes.map |lt| { cx.lifetime(span, cx.ident_of(*lt)) }; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 80e4520b094..0eb0f5c6159 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -28,8 +28,8 @@ impl ToStr for direction { } } -pub impl direction { - fn reverse(&self) -> direction { +impl direction { + pub fn reverse(&self) -> direction { match *self { send => recv, recv => send @@ -45,21 +45,21 @@ pub struct next_state { // name, span, data, current state, next state pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>); -pub impl message { - fn name(&mut self) -> ~str { +impl message { + pub fn name(&mut self) -> ~str { match *self { message(ref id, _, _, _, _) => copy *id } } - fn span(&mut self) -> span { + pub fn span(&mut self) -> span { match *self { message(_, span, _, _, _) => span } } /// Return the type parameters actually used by this message - fn get_generics(&self) -> ast::Generics { + pub fn get_generics(&self) -> ast::Generics { match *self { message(_, _, _, this, _) => copy this.generics } @@ -79,23 +79,26 @@ pub struct state_ { proto: protocol } -pub impl state_ { - fn add_message(@self, name: ~str, span: span, - data: ~[@ast::Ty], next: Option<next_state>) { +impl state_ { + pub fn add_message(@self, + name: ~str, + span: span, + data: ~[@ast::Ty], + next: Option<next_state>) { self.messages.push(message(name, span, data, self, next)); } - fn filename(&self) -> ~str { + pub fn filename(&self) -> ~str { self.proto.filename() } - fn data_name(&self) -> ast::ident { + pub fn data_name(&self) -> ast::ident { self.ident } /// Returns the type that is used for the messages. - fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { + pub fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { cx.ty_path (path(~[cx.ident_of(self.name)],self.span).add_tys( cx.ty_vars(&self.generics.ty_params))) @@ -103,7 +106,7 @@ pub impl state_ { /// Iterate over the states that can be reached in one message /// from this state. - fn reachable(&self, f: &fn(state) -> bool) -> bool { + pub fn reachable(&self, f: &fn(state) -> bool) -> bool { for self.messages.each |m| { match *m { message(_, _, _, _, Some(next_state { state: ref id, _ })) => { @@ -140,28 +143,28 @@ pub struct protocol_ { bounded: Option<bool>, } -pub impl protocol_ { +impl protocol_ { /// Get a state. - fn get_state(&self, name: &str) -> state { + pub fn get_state(&self, name: &str) -> state { self.states.find(|i| name == i.name).get() } - fn get_state_by_id(&self, id: uint) -> state { self.states[id] } + pub fn get_state_by_id(&self, id: uint) -> state { self.states[id] } - fn has_state(&self, name: &str) -> bool { + pub fn has_state(&self, name: &str) -> bool { self.states.find(|i| name == i.name).is_some() } - fn filename(&self) -> ~str { + pub fn filename(&self) -> ~str { ~"proto://" + self.name } - fn num_states(&self) -> uint { + pub fn num_states(&self) -> uint { let states = &mut *self.states; states.len() } - fn has_ty_params(&self) -> bool { + pub fn has_ty_params(&self) -> bool { for self.states.each |s| { if s.generics.ty_params.len() > 0 { return true; @@ -169,19 +172,20 @@ pub impl protocol_ { } false } - fn is_bounded(&self) -> bool { + + pub fn is_bounded(&self) -> bool { let bounded = self.bounded.get(); bounded } } -pub impl protocol_ { - fn add_state_poly(@mut self, - name: ~str, - ident: ast::ident, - dir: direction, - generics: ast::Generics) - -> state { +impl protocol_ { + pub fn add_state_poly(@mut self, + name: ~str, + ident: ast::ident, + dir: direction, + generics: ast::Generics) + -> state { let messages = @mut ~[]; let states = &mut *self.states; diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index bdbe91e4112..8a930cf9afd 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -52,18 +52,18 @@ pub fn token_to_str(reader: @reader, token: &token::Token) -> ~str { token::to_str(reader.interner(), token) } -pub impl Parser { +impl Parser { // convert a token to a string using self's reader - fn token_to_str(&self, token: &token::Token) -> ~str { + pub fn token_to_str(&self, token: &token::Token) -> ~str { token::to_str(self.reader.interner(), token) } // convert the current token to a string using self's reader - fn this_token_to_str(&self) -> ~str { + pub fn this_token_to_str(&self) -> ~str { self.token_to_str(self.token) } - fn unexpected_last(&self, t: &token::Token) -> ! { + pub fn unexpected_last(&self, t: &token::Token) -> ! { self.span_fatal( *self.last_span, fmt!( @@ -73,7 +73,7 @@ pub impl Parser { ); } - fn unexpected(&self) -> ! { + pub fn unexpected(&self) -> ! { self.fatal( fmt!( "unexpected token: `%s`", @@ -84,7 +84,7 @@ pub impl Parser { // expect and consume the token t. Signal an error if // the next token is not t. - fn expect(&self, t: &token::Token) { + pub fn expect(&self, t: &token::Token) { if *self.token == *t { self.bump(); } else { @@ -98,7 +98,7 @@ pub impl Parser { } } - fn parse_ident(&self) -> ast::ident { + pub fn parse_ident(&self) -> ast::ident { self.check_strict_keywords(); self.check_reserved_keywords(); match *self.token { @@ -120,7 +120,7 @@ pub impl Parser { } } - fn parse_path_list_ident(&self) -> ast::path_list_ident { + pub fn parse_path_list_ident(&self) -> ast::path_list_ident { let lo = self.span.lo; let ident = self.parse_ident(); let hi = self.last_span.hi; @@ -130,17 +130,17 @@ pub impl Parser { // consume token 'tok' if it exists. Returns true if the given // token was present, false otherwise. - fn eat(&self, tok: &token::Token) -> bool { + pub fn eat(&self, tok: &token::Token) -> bool { return if *self.token == *tok { self.bump(); true } else { false }; } - fn is_keyword(&self, kw: keywords::Keyword) -> bool { + pub fn is_keyword(&self, kw: keywords::Keyword) -> bool { token::is_keyword(kw, self.token) } // if the next token is the given keyword, eat it and return // true. Otherwise, return false. - fn eat_keyword(&self, kw: keywords::Keyword) -> bool { + pub fn eat_keyword(&self, kw: keywords::Keyword) -> bool { let is_kw = match *self.token { token::IDENT(sid, false) => kw.to_ident().repr == sid.repr, _ => false @@ -152,7 +152,7 @@ pub impl Parser { // if the given word is not a keyword, signal an error. // if the next token is not the given word, signal an error. // otherwise, eat it. - fn expect_keyword(&self, kw: keywords::Keyword) { + pub fn expect_keyword(&self, kw: keywords::Keyword) { if !self.eat_keyword(kw) { self.fatal( fmt!( @@ -165,7 +165,7 @@ pub impl Parser { } // signal an error if the given string is a strict keyword - fn check_strict_keywords(&self) { + 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())); @@ -173,7 +173,7 @@ pub impl Parser { } // signal an error if the current token is a reserved keyword - fn check_reserved_keywords(&self) { + 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())); } @@ -182,7 +182,7 @@ pub impl Parser { // expect and consume a GT. if a >> is seen, replace it // with a single > and continue. If a GT is not seen, // signal an error. - fn expect_gt(&self) { + pub fn expect_gt(&self) { if *self.token == token::GT { self.bump(); } else if *self.token == token::BINOP(token::SHR) { @@ -203,11 +203,10 @@ pub impl Parser { // parse a sequence bracketed by '<' and '>', stopping // before the '>'. - fn parse_seq_to_before_gt<T: Copy>( - &self, - sep: Option<token::Token>, - f: &fn(&Parser) -> T - ) -> OptVec<T> { + pub fn parse_seq_to_before_gt<T: Copy>(&self, + sep: Option<token::Token>, + f: &fn(&Parser) -> T) + -> OptVec<T> { let mut first = true; let mut v = opt_vec::Empty; while *self.token != token::GT @@ -224,11 +223,10 @@ pub impl Parser { return v; } - fn parse_seq_to_gt<T: Copy>( - &self, - sep: Option<token::Token>, - f: &fn(&Parser) -> T - ) -> OptVec<T> { + pub fn parse_seq_to_gt<T: Copy>(&self, + sep: Option<token::Token>, + f: &fn(&Parser) -> T) + -> OptVec<T> { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; @@ -237,12 +235,11 @@ pub impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_seq_to_end<T: Copy>( - &self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_seq_to_end<T: Copy>(&self, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { let val = self.parse_seq_to_before_end(ket, sep, f); self.bump(); val @@ -251,12 +248,11 @@ pub impl Parser { // parse a sequence, not including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_seq_to_before_end<T: Copy>( - &self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_seq_to_before_end<T: Copy>(&self, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { let mut first: bool = true; let mut v: ~[T] = ~[]; while *self.token != *ket { @@ -276,13 +272,12 @@ pub impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_unspanned_seq<T: Copy>( - &self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_unspanned_seq<T: Copy>(&self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); @@ -291,13 +286,12 @@ pub impl Parser { // NB: Do not use this function unless you actually plan to place the // spanned list in the AST. - fn parse_seq<T: Copy>( - &self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> spanned<~[T]> { + pub fn parse_seq<T: Copy>(&self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> spanned<~[T]> { let lo = self.span.lo; self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 085d24d7e68..f11219f6c9e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -73,9 +73,9 @@ impl to_bytes::IterBytes for ObsoleteSyntax { } } -pub impl Parser { +impl Parser { /// Reports an obsolete syntax non-fatal error. - fn obsolete(&self, sp: span, kind: ObsoleteSyntax) { + pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) { let (kind_str, desc) = match kind { ObsoleteLowerCaseKindBounds => ( "lower-case kind bounds", @@ -232,13 +232,16 @@ pub impl Parser { // Reports an obsolete syntax non-fatal error, and returns // a placeholder expression - fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr { + pub fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr { self.obsolete(sp, kind); self.mk_expr(sp.lo, sp.hi, expr_lit(@respan(sp, lit_nil))) } - priv fn report(&self, sp: span, kind: ObsoleteSyntax, kind_str: &str, - desc: &str) { + fn report(&self, + sp: span, + kind: ObsoleteSyntax, + kind_str: &str, + desc: &str) { self.span_err(sp, fmt!("obsolete syntax: %s", kind_str)); if !self.obsolete_set.contains(&kind) { @@ -247,7 +250,8 @@ pub impl Parser { } } - fn token_is_obsolete_ident(&self, ident: &str, token: &Token) -> bool { + pub fn token_is_obsolete_ident(&self, ident: &str, token: &Token) + -> bool { match *token { token::IDENT(sid, _) => { str::eq_slice(*self.id_to_str(sid), ident) @@ -256,11 +260,11 @@ pub impl Parser { } } - fn is_obsolete_ident(&self, ident: &str) -> bool { + pub fn is_obsolete_ident(&self, ident: &str) -> bool { self.token_is_obsolete_ident(ident, self.token) } - fn eat_obsolete_ident(&self, ident: &str) -> bool { + pub fn eat_obsolete_ident(&self, ident: &str) -> bool { if self.is_obsolete_ident(ident) { self.bump(); true @@ -269,7 +273,7 @@ pub impl Parser { } } - fn try_parse_obsolete_struct_ctor(&self) -> bool { + pub fn try_parse_obsolete_struct_ctor(&self) -> bool { if self.eat_obsolete_ident("new") { self.obsolete(*self.last_span, ObsoleteStructCtor); self.parse_fn_decl(); @@ -280,7 +284,7 @@ pub impl Parser { } } - fn try_parse_obsolete_with(&self) -> bool { + pub fn try_parse_obsolete_with(&self) -> bool { if *self.token == token::COMMA && self.token_is_obsolete_ident("with", &self.look_ahead(1u)) { @@ -295,7 +299,8 @@ pub impl Parser { } } - fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) -> bool { + pub fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) + -> bool { if self.is_keyword(keywords::Priv) && self.look_ahead(1) == token::LBRACE { self.obsolete(copy *self.span, ObsoletePrivSection); self.eat_keyword(keywords::Priv); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c47092ef61c..00ad12ce402 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -272,9 +272,9 @@ impl Drop for Parser { fn finalize(&self) {} } -pub impl Parser { +impl Parser { // advance the parser by one token - fn bump(&self) { + pub fn bump(&self) { *self.last_span = copy *self.span; let next = if *self.buffer_start == *self.buffer_end { self.reader.next_token() @@ -288,17 +288,20 @@ pub impl Parser { *self.tokens_consumed += 1u; } // EFFECT: replace the current token and span with the given one - fn replace_token(&self, next: token::Token, lo: BytePos, hi: BytePos) { + pub fn replace_token(&self, + next: token::Token, + lo: BytePos, + hi: BytePos) { *self.token = next; *self.span = mk_sp(lo, hi); } - fn buffer_length(&self) -> int { + pub fn buffer_length(&self) -> int { if *self.buffer_start <= *self.buffer_end { return *self.buffer_end - *self.buffer_start; } return (4 - *self.buffer_start) + *self.buffer_end; } - fn look_ahead(&self, distance: uint) -> token::Token { + pub fn look_ahead(&self, distance: uint) -> token::Token { let dist = distance as int; while self.buffer_length() < dist { self.buffer[*self.buffer_end] = self.reader.next_token(); @@ -306,49 +309,49 @@ pub impl Parser { } return copy self.buffer[(*self.buffer_start + dist - 1) & 3].tok; } - fn fatal(&self, m: &str) -> ! { + pub fn fatal(&self, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(*copy self.span, m) } - fn span_fatal(&self, sp: span, m: &str) -> ! { + pub fn span_fatal(&self, sp: span, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(sp, m) } - fn span_note(&self, sp: span, m: &str) { + pub fn span_note(&self, sp: span, m: &str) { self.sess.span_diagnostic.span_note(sp, m) } - fn bug(&self, m: &str) -> ! { + pub fn bug(&self, m: &str) -> ! { self.sess.span_diagnostic.span_bug(*copy self.span, m) } - fn warn(&self, m: &str) { + pub fn warn(&self, m: &str) { self.sess.span_diagnostic.span_warn(*copy self.span, m) } - fn span_err(&self, sp: span, m: &str) { + pub fn span_err(&self, sp: span, m: &str) { self.sess.span_diagnostic.span_err(sp, m) } - fn abort_if_errors(&self) { + pub fn abort_if_errors(&self) { self.sess.span_diagnostic.handler().abort_if_errors(); } - fn get_id(&self) -> node_id { next_node_id(self.sess) } + pub fn get_id(&self) -> node_id { next_node_id(self.sess) } - fn id_to_str(&self, id: ident) -> @~str { + pub fn id_to_str(&self, id: ident) -> @~str { self.sess.interner.get(id) } // is this one of the keywords that signals a closure type? - fn token_is_closure_keyword(&self, tok: &token::Token) -> bool { + pub fn token_is_closure_keyword(&self, tok: &token::Token) -> bool { token::is_keyword(keywords::Pure, tok) || token::is_keyword(keywords::Unsafe, tok) || token::is_keyword(keywords::Once, tok) || token::is_keyword(keywords::Fn, tok) } - fn token_is_lifetime(&self, tok: &token::Token) -> bool { + pub fn token_is_lifetime(&self, tok: &token::Token) -> bool { match *tok { token::LIFETIME(*) => true, _ => false, } } - fn get_lifetime(&self, tok: &token::Token) -> ast::ident { + pub fn get_lifetime(&self, tok: &token::Token) -> ast::ident { match *tok { token::LIFETIME(ref ident) => copy *ident, _ => self.bug("not a lifetime"), @@ -356,8 +359,7 @@ pub impl Parser { } // parse a ty_bare_fun type: - fn parse_ty_bare_fn(&self) -> ty_ - { + pub fn parse_ty_bare_fn(&self) -> ty_ { /* extern "ABI" [pure|unsafe] fn <'lt> (S) -> T @@ -386,10 +388,10 @@ pub impl Parser { } // parse a ty_closure type - fn parse_ty_closure(&self, - sigil: ast::Sigil, - region: Option<@ast::Lifetime>) - -> ty_ { + pub fn parse_ty_closure(&self, + sigil: ast::Sigil, + region: Option<@ast::Lifetime>) + -> ty_ { /* (&|~|@) ['r] [pure|unsafe] [once] fn [:Bounds] <'lt> (S) -> T @@ -440,7 +442,7 @@ pub impl Parser { } // looks like this should be called parse_unsafety - fn parse_unsafety(&self) -> purity { + pub fn parse_unsafety(&self) -> purity { if self.eat_keyword(keywords::Pure) { self.obsolete(*self.last_span, ObsoletePurity); return impure_fn; @@ -452,7 +454,7 @@ pub impl Parser { } // parse a function type (following the 'fn') - fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec<ast::Lifetime>) { + pub fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec<ast::Lifetime>) { /* (fn) <'lt> (S) -> T @@ -487,7 +489,7 @@ pub impl Parser { } // parse the methods in a trait declaration - fn parse_trait_methods(&self) -> ~[trait_method] { + pub fn parse_trait_methods(&self) -> ~[trait_method] { do self.parse_unspanned_seq( &token::LBRACE, &token::RBRACE, @@ -563,9 +565,8 @@ pub impl Parser { } } - // parse a possibly mutable type - fn parse_mt(&self) -> mt { + pub fn parse_mt(&self) -> mt { let mutbl = self.parse_mutability(); let t = self.parse_ty(false); mt { ty: t, mutbl: mutbl } @@ -573,7 +574,7 @@ pub impl Parser { // parse [mut/const/imm] ID : TY // now used only by obsolete record syntax parser... - fn parse_ty_field(&self) -> ty_field { + pub fn parse_ty_field(&self) -> ty_field { let lo = self.span.lo; let mutbl = self.parse_mutability(); let id = self.parse_ident(); @@ -590,7 +591,7 @@ pub impl Parser { } // parse optional return type [ -> TY ] in function decl - fn parse_ret_ty(&self) -> (ret_style, @Ty) { + pub fn parse_ret_ty(&self) -> (ret_style, @Ty) { return if self.eat(&token::RARROW) { let lo = self.span.lo; if self.eat(&token::NOT) { @@ -621,7 +622,7 @@ pub impl Parser { // parse a type. // Useless second parameter for compatibility with quasiquote macros. // Bleh! - fn parse_ty(&self, _: bool) -> @Ty { + pub fn parse_ty(&self, _: bool) -> @Ty { maybe_whole!(self, nt_ty); let lo = self.span.lo; @@ -722,11 +723,9 @@ pub impl Parser { } // parse the type following a @ or a ~ - fn parse_box_or_uniq_pointee( - &self, - sigil: ast::Sigil, - ctor: &fn(v: mt) -> ty_) -> ty_ - { + pub fn parse_box_or_uniq_pointee(&self, + sigil: ast::Sigil, + ctor: &fn(v: mt) -> ty_) -> ty_ { // @'foo fn() or @foo/fn() or @fn() are parsed directly as fn types: match *self.token { token::LIFETIME(*) => { @@ -765,7 +764,7 @@ pub impl Parser { ctor(mt) } - fn parse_borrowed_pointee(&self) -> ty_ { + pub fn parse_borrowed_pointee(&self) -> ty_ { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: let opt_lifetime = self.parse_opt_lifetime(); @@ -778,7 +777,7 @@ pub impl Parser { } // parse an optional, obsolete argument mode. - fn parse_arg_mode(&self) { + pub fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); } else if self.eat(&token::ANDAND) { @@ -794,7 +793,7 @@ pub impl Parser { } } - fn is_named_argument(&self) -> bool { + pub fn is_named_argument(&self) -> bool { let offset = if *self.token == token::BINOP(token::AND) { 1 } else if *self.token == token::BINOP(token::MINUS) { @@ -819,7 +818,7 @@ pub impl Parser { // This version of parse arg doesn't necessarily require // identifier names. - fn parse_arg_general(&self, require_name: bool) -> arg { + pub fn parse_arg_general(&self, require_name: bool) -> arg { let mut is_mutbl = false; let pat = if require_name || self.is_named_argument() { self.parse_arg_mode(); @@ -844,12 +843,12 @@ pub impl Parser { } // parse a single function argument - fn parse_arg(&self) -> arg_or_capture_item { + pub fn parse_arg(&self) -> arg_or_capture_item { either::Left(self.parse_arg_general(true)) } // parse an argument in a lambda header e.g. |arg, arg| - fn parse_fn_block_arg(&self) -> arg_or_capture_item { + pub fn parse_fn_block_arg(&self) -> arg_or_capture_item { self.parse_arg_mode(); let is_mutbl = self.eat_keyword(keywords::Mut); let pat = self.parse_pat(); @@ -870,7 +869,7 @@ pub impl Parser { }) } - fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { + pub fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { if self.eat(&token::BINOP(token::STAR)) { self.obsolete(*self.last_span, ObsoleteFixedLengthVectorType); Some(self.parse_expr()) @@ -885,7 +884,7 @@ pub impl Parser { } // matches token_lit = LIT_INT | ... - fn lit_from_token(&self, tok: &token::Token) -> lit_ { + pub fn lit_from_token(&self, tok: &token::Token) -> lit_ { match *tok { token::LIT_INT(i, it) => lit_int(i, it), token::LIT_UINT(u, ut) => lit_uint(u, ut), @@ -900,7 +899,7 @@ pub impl Parser { } // matches lit = true | false | token_lit - fn parse_lit(&self) -> lit { + pub fn parse_lit(&self) -> lit { let lo = self.span.lo; let lit = if self.eat_keyword(keywords::True) { lit_bool(true) @@ -916,7 +915,7 @@ pub impl Parser { } // matches '-' lit | lit - fn parse_literal_maybe_minus(&self) -> @expr { + pub fn parse_literal_maybe_minus(&self) -> @expr { let minus_lo = self.span.lo; let minus_present = self.eat(&token::BINOP(token::MINUS)); @@ -935,7 +934,7 @@ pub impl Parser { // parse a path into a vector of idents, whether the path starts // with ::, and a span. - fn parse_path(&self) -> (~[ast::ident],bool,span) { + pub fn parse_path(&self) -> (~[ast::ident],bool,span) { let lo = self.span.lo; let is_global = self.eat(&token::MOD_SEP); let (ids,span{lo:_,hi,expn_info}) = self.parse_path_non_global(); @@ -943,7 +942,7 @@ pub impl Parser { } // parse a path beginning with an identifier into a vector of idents and a span - fn parse_path_non_global(&self) -> (~[ast::ident],span) { + pub fn parse_path_non_global(&self) -> (~[ast::ident],span) { let lo = self.span.lo; let mut ids = ~[]; // must be at least one to begin: @@ -966,8 +965,7 @@ pub impl Parser { } // parse a path that doesn't have type parameters attached - fn parse_path_without_tps(&self) - -> @ast::Path { + pub fn parse_path_without_tps(&self) -> @ast::Path { maybe_whole!(self, nt_path); let (ids,is_global,sp) = self.parse_path(); @ast::Path { span: sp, @@ -980,7 +978,7 @@ pub impl Parser { // parse a path optionally with type parameters. If 'colons' // is true, then type parameters must be preceded by colons, // as in a::t::<t1,t2> - fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { + pub fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { debug!("parse_path_with_tps(colons=%b)", colons); maybe_whole!(self, nt_path); @@ -1042,7 +1040,7 @@ pub impl Parser { } /// parses 0 or 1 lifetime - fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> { + pub fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> { match *self.token { token::LIFETIME(*) => { Some(@self.parse_lifetime()) @@ -1064,7 +1062,7 @@ pub impl Parser { } } - fn token_is_lifetime(&self, tok: &token::Token) -> bool { + pub fn token_is_lifetime(&self, tok: &token::Token) -> bool { match *tok { token::LIFETIME(_) => true, _ => false @@ -1073,7 +1071,7 @@ pub impl Parser { /// Parses a single lifetime // matches lifetime = ( LIFETIME ) | ( IDENT / ) - fn parse_lifetime(&self) -> ast::Lifetime { + pub fn parse_lifetime(&self) -> ast::Lifetime { match *self.token { token::LIFETIME(i) => { let span = copy self.span; @@ -1107,7 +1105,7 @@ pub impl Parser { // matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) // actually, it matches the empty one too, but putting that in there // messes up the grammar.... - fn parse_lifetimes(&self) -> OptVec<ast::Lifetime> { + pub fn parse_lifetimes(&self) -> OptVec<ast::Lifetime> { /*! * * Parses zero or more comma separated lifetimes. @@ -1139,13 +1137,13 @@ pub impl Parser { } } - fn token_is_mutability(&self, tok: &token::Token) -> bool { + pub fn token_is_mutability(&self, tok: &token::Token) -> bool { token::is_keyword(keywords::Mut, tok) || token::is_keyword(keywords::Const, tok) } // parse mutability declaration (mut/const/imm) - fn parse_mutability(&self) -> mutability { + pub fn parse_mutability(&self) -> mutability { if self.eat_keyword(keywords::Mut) { m_mutbl } else if self.eat_keyword(keywords::Const) { @@ -1156,7 +1154,7 @@ pub impl Parser { } // parse ident COLON expr - fn parse_field(&self) -> field { + pub fn parse_field(&self) -> field { let lo = self.span.lo; let i = self.parse_ident(); self.expect(&token::COLON); @@ -1167,7 +1165,7 @@ pub impl Parser { }) } - fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { + pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { @expr { id: self.get_id(), callee_id: self.get_id(), @@ -1176,7 +1174,7 @@ pub impl Parser { } } - fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr { + pub fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr { @expr { id: self.get_id(), callee_id: self.get_id(), @@ -1185,7 +1183,7 @@ pub impl Parser { } } - fn mk_lit_u32(&self, i: u32) -> @expr { + pub fn mk_lit_u32(&self, i: u32) -> @expr { let span = self.span; let lv_lit = @codemap::spanned { node: lit_uint(i as u64, ty_u32), @@ -1203,7 +1201,7 @@ pub impl Parser { // at the bottom (top?) of the precedence hierarchy, // parse things like parenthesized exprs, // macros, return, etc. - fn parse_bottom_expr(&self) -> @expr { + pub fn parse_bottom_expr(&self) -> @expr { maybe_whole_expr!(self); let lo = self.span.lo; @@ -1414,23 +1412,20 @@ pub impl Parser { } // parse a block or unsafe block - fn parse_block_expr( - &self, - lo: BytePos, - blk_mode: blk_check_mode - ) -> @expr { + pub fn parse_block_expr(&self, lo: BytePos, blk_mode: blk_check_mode) + -> @expr { self.expect(&token::LBRACE); let blk = self.parse_block_tail(lo, blk_mode); return self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk)); } // parse a.b or a(13) or a[4] or just a - fn parse_dot_or_call_expr(&self) -> @expr { + pub fn parse_dot_or_call_expr(&self) -> @expr { let b = self.parse_bottom_expr(); self.parse_dot_or_call_expr_with(b) } - fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr { + pub fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr { let mut e = e0; let lo = e.span.lo; let mut hi; @@ -1504,7 +1499,7 @@ pub impl Parser { // parse an optional separator followed by a kleene-style // repetition token (+ or *). - fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) { + pub fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) { if *self.token == token::BINOP(token::STAR) || *self.token == token::BINOP(token::PLUS) { let zerok = *self.token == token::BINOP(token::STAR); @@ -1525,7 +1520,7 @@ pub impl Parser { } // parse a single token tree from the input. - fn parse_token_tree(&self) -> token_tree { + pub fn parse_token_tree(&self) -> token_tree { maybe_whole!(deref self, nt_tt); // this is the fall-through for the 'match' below. @@ -1612,7 +1607,7 @@ pub impl Parser { // parse a stream of tokens into a list of token_trees, // up to EOF. - fn parse_all_token_trees(&self) -> ~[token_tree] { + pub fn parse_all_token_trees(&self) -> ~[token_tree] { let mut tts = ~[]; while *self.token != token::EOF { tts.push(self.parse_token_tree()); @@ -1620,7 +1615,7 @@ pub impl Parser { tts } - fn parse_matchers(&self) -> ~[matcher] { + pub fn parse_matchers(&self) -> ~[matcher] { // unification of matchers and token_trees would vastly improve // the interpolation of matchers maybe_whole!(self, nt_matchers); @@ -1642,12 +1637,11 @@ pub impl Parser { // This goofy function is necessary to correctly match parens in matchers. // Otherwise, `$( ( )` would be a valid matcher, and `$( () )` would be // invalid. It's similar to common::parse_seq. - fn parse_matcher_subseq( - &self, - name_idx: @mut uint, - bra: token::Token, - ket: token::Token - ) -> ~[matcher] { + pub fn parse_matcher_subseq(&self, + name_idx: @mut uint, + bra: token::Token, + ket: token::Token) + -> ~[matcher] { let mut ret_val = ~[]; let mut lparens = 0u; @@ -1664,7 +1658,7 @@ pub impl Parser { return ret_val; } - fn parse_matcher(&self, name_idx: @mut uint) -> matcher { + pub fn parse_matcher(&self, name_idx: @mut uint) -> matcher { let lo = self.span.lo; let m = if *self.token == token::DOLLAR { @@ -1699,7 +1693,7 @@ pub impl Parser { } // parse a prefix-operator expr - fn parse_prefix_expr(&self) -> @expr { + pub fn parse_prefix_expr(&self) -> @expr { let lo = self.span.lo; let hi; @@ -1791,13 +1785,12 @@ pub impl Parser { } // parse an expression of binops - fn parse_binops(&self) -> @expr { + pub fn parse_binops(&self) -> @expr { self.parse_more_binops(self.parse_prefix_expr(), 0) } // parse an expression of binops of at least min_prec precedence - fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> - @expr { + pub fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> @expr { if self.expr_is_complete(lhs) { return lhs; } let peeked = copy *self.token; if peeked == token::BINOP(token::OR) && @@ -1841,7 +1834,7 @@ pub impl Parser { // parse an assignment expression.... // actually, this seems to be the main entry point for // parsing an arbitrary expression. - fn parse_assign_expr(&self) -> @expr { + pub fn parse_assign_expr(&self) -> @expr { let lo = self.span.lo; let lhs = self.parse_binops(); match *self.token { @@ -1892,7 +1885,7 @@ pub impl Parser { } // parse an 'if' expression ('if' token already eaten) - fn parse_if_expr(&self) -> @expr { + pub fn parse_if_expr(&self) -> @expr { let lo = self.last_span.lo; let cond = self.parse_expr(); let thn = self.parse_block(); @@ -1907,7 +1900,7 @@ pub impl Parser { } // `|args| { ... }` or `{ ...}` like in `do` expressions - fn parse_lambda_block_expr(&self) -> @expr { + pub fn parse_lambda_block_expr(&self) -> @expr { self.parse_lambda_expr_( || { match *self.token { @@ -1935,7 +1928,7 @@ pub impl Parser { } // `|args| expr` - fn parse_lambda_expr(&self) -> @expr { + pub fn parse_lambda_expr(&self) -> @expr { self.parse_lambda_expr_(|| self.parse_fn_block_decl(), || self.parse_expr()) } @@ -1943,11 +1936,10 @@ pub impl Parser { // parse something of the form |args| expr // this is used both in parsing a lambda expr // and in parsing a block expr as e.g. in for... - fn parse_lambda_expr_( - &self, - parse_decl: &fn() -> fn_decl, - parse_body: &fn() -> @expr - ) -> @expr { + pub fn parse_lambda_expr_(&self, + parse_decl: &fn() -> fn_decl, + parse_body: &fn() -> @expr) + -> @expr { let lo = self.last_span.lo; let decl = parse_decl(); let body = parse_body(); @@ -1964,7 +1956,7 @@ pub impl Parser { expr_fn_block(decl, fakeblock)); } - fn parse_else_expr(&self) -> @expr { + pub fn parse_else_expr(&self) -> @expr { if self.eat_keyword(keywords::If) { return self.parse_if_expr(); } else { @@ -1976,9 +1968,11 @@ pub impl Parser { // parse a 'for' or 'do'. // the 'for' and 'do' expressions parse as calls, but look like // function calls followed by a closure expression. - fn parse_sugary_call_expr(&self, keyword: ~str, - sugar: CallSugar, - ctor: &fn(v: @expr) -> expr_) -> @expr { + pub fn parse_sugary_call_expr(&self, + keyword: ~str, + sugar: CallSugar, + ctor: &fn(v: @expr) -> expr_) + -> @expr { let lo = self.last_span; // Parse the callee `foo` in // for foo || { @@ -2035,7 +2029,7 @@ pub impl Parser { } } - fn parse_while_expr(&self) -> @expr { + pub fn parse_while_expr(&self) -> @expr { let lo = self.last_span.lo; let cond = self.parse_expr(); let body = self.parse_block(); @@ -2043,7 +2037,7 @@ pub impl Parser { return self.mk_expr(lo, hi, expr_while(cond, body)); } - fn parse_loop_expr(&self, opt_ident: Option<ast::ident>) -> @expr { + pub fn parse_loop_expr(&self, opt_ident: Option<ast::ident>) -> @expr { // loop headers look like 'loop {' or 'loop unsafe {' let is_loop_header = *self.token == token::LBRACE @@ -2126,7 +2120,7 @@ pub impl Parser { } // parse an expression - fn parse_expr(&self) -> @expr { + pub fn parse_expr(&self) -> @expr { return self.parse_expr_res(UNRESTRICTED); } @@ -2257,7 +2251,7 @@ pub impl Parser { } // parse a pattern. - fn parse_pat(&self) -> @pat { + pub fn parse_pat(&self) -> @pat { maybe_whole!(self, nt_pat); let lo = self.span.lo; @@ -2580,7 +2574,7 @@ pub impl Parser { // parse a statement. may include decl. // precondition: any attributes are parsed already - fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt { + pub fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt { maybe_whole!(self, nt_stmt); fn check_expected_item(p: &Parser, current_attrs: &[attribute]) { @@ -2674,7 +2668,7 @@ pub impl Parser { } // parse a block. No inner attrs are allowed. - fn parse_block(&self) -> blk { + pub fn parse_block(&self) -> blk { maybe_whole!(self, nt_block); let lo = self.span.lo; @@ -2924,7 +2918,7 @@ pub impl Parser { // matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > ) // | ( < lifetimes , typaramseq ( , )? > ) // where typaramseq = ( typaram ) | ( typaram , typaramseq ) - fn parse_generics(&self) -> ast::Generics { + pub fn parse_generics(&self) -> ast::Generics { if self.eat(&token::LT) { let lifetimes = self.parse_lifetimes(); let ty_params = self.parse_seq_to_gt( @@ -2958,9 +2952,7 @@ pub impl Parser { } // parse the argument list and result type of a function declaration - fn parse_fn_decl(&self) - -> fn_decl - { + pub fn parse_fn_decl(&self) -> fn_decl { let args_or_capture_items: ~[arg_or_capture_item] = self.parse_unspanned_seq( &token::LPAREN, @@ -3398,9 +3390,10 @@ pub impl Parser { } // parse a structure field declaration - fn parse_single_struct_field(&self, - vis: visibility, - attrs: ~[attribute]) -> @struct_field { + pub fn parse_single_struct_field(&self, + vis: visibility, + attrs: ~[attribute]) + -> @struct_field { if self.eat_obsolete_ident("let") { self.obsolete(*self.last_span, ObsoleteLet); } @@ -4214,7 +4207,7 @@ pub impl Parser { return iovi_none; } - fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> { + pub fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> { match self.parse_item_or_view_item(attrs, true) { iovi_none => None, @@ -4493,7 +4486,7 @@ pub impl Parser { // Parses a source module as a crate. This is the main // entry point for the parser. - fn parse_crate_mod(&self) -> @crate { + pub fn parse_crate_mod(&self) -> @crate { let lo = self.span.lo; // parse the crate's inner attrs, maybe (oops) one // of the attrs of an item: @@ -4507,7 +4500,7 @@ pub impl Parser { config: copy self.cfg }) } - fn parse_str(&self) -> @~str { + pub fn parse_str(&self) -> @~str { match *self.token { token::LIT_STR(s) => { self.bump(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index f50b9f8936a..b716384c6cc 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -393,21 +393,22 @@ pub struct ident_interner { priv interner: StrInterner, } -pub impl ident_interner { - fn intern(&self, val: &str) -> ast::ident { +impl ident_interner { + pub fn intern(&self, val: &str) -> ast::ident { ast::ident { repr: self.interner.intern(val), ctxt: 0 } } - fn gensym(&self, val: &str) -> ast::ident { + pub fn gensym(&self, val: &str) -> ast::ident { ast::ident { repr: self.interner.gensym(val), ctxt: 0 } } - fn get(&self, idx: ast::ident) -> @~str { + pub fn get(&self, idx: ast::ident) -> @~str { self.interner.get(idx.repr) } - fn len(&self) -> uint { + pub fn len(&self) -> uint { self.interner.len() } - fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q) - -> Option<ast::ident> { + pub fn find_equiv<Q:Hash + + IterBytes + + Equiv<@~str>>(&self, val: &Q) -> Option<ast::ident> { match self.interner.find_equiv(val) { Some(v) => Some(ast::ident { repr: v, ctxt: 0 }), None => None, @@ -586,8 +587,8 @@ pub mod keywords { Be, } - pub impl Keyword { - fn to_ident(&self) -> ident { + impl Keyword { + pub fn to_ident(&self) -> ident { match *self { As => ident { repr: 35, ctxt: 0 }, Break => ident { repr: 36, ctxt: 0 }, diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 11830dc3c29..f6059980697 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -87,11 +87,12 @@ pub enum token { EOF, } -pub impl token { - fn is_eof(&self) -> bool { +impl token { + pub fn is_eof(&self) -> bool { match *self { EOF => true, _ => false } } - fn is_hardbreak_tok(&self) -> bool { + + pub fn is_hardbreak_tok(&self) -> bool { match *self { BREAK(break_t { offset: 0, @@ -274,11 +275,13 @@ pub struct Printer { pending_indentation: int, } -pub impl Printer { - fn last_token(&mut self) -> token { self.token[self.right] } +impl Printer { + pub fn last_token(&mut self) -> token { self.token[self.right] } // be very careful with this! - fn replace_last_token(&mut self, t: token) { self.token[self.right] = t; } - fn pretty_print(&mut self, t: token) { + pub fn replace_last_token(&mut self, t: token) { + self.token[self.right] = t; + } + pub fn pretty_print(&mut self, t: token) { debug!("pp ~[%u,%u]", self.left, self.right); match t { EOF => { @@ -346,7 +349,7 @@ pub impl Printer { } } } - fn check_stream(&mut self) { + pub fn check_stream(&mut self) { debug!("check_stream ~[%u, %u] with left_total=%d, right_total=%d", self.left, self.right, self.left_total, self.right_total); if self.right_total - self.left_total > self.space { @@ -362,7 +365,7 @@ pub impl Printer { if self.left != self.right { self.check_stream(); } } } - fn scan_push(&mut self, x: uint) { + pub fn scan_push(&mut self, x: uint) { debug!("scan_push %u", x); if self.scan_stack_empty { self.scan_stack_empty = false; @@ -373,7 +376,7 @@ pub impl Printer { } self.scan_stack[self.top] = x; } - fn scan_pop(&mut self) -> uint { + pub fn scan_pop(&mut self) -> uint { assert!((!self.scan_stack_empty)); let x = self.scan_stack[self.top]; if self.top == self.bottom { @@ -381,11 +384,11 @@ pub impl Printer { } else { self.top += self.buf_len - 1u; self.top %= self.buf_len; } return x; } - fn scan_top(&mut self) -> uint { + pub fn scan_top(&mut self) -> uint { assert!((!self.scan_stack_empty)); return self.scan_stack[self.top]; } - fn scan_pop_bottom(&mut self) -> uint { + pub fn scan_pop_bottom(&mut self) -> uint { assert!((!self.scan_stack_empty)); let x = self.scan_stack[self.bottom]; if self.top == self.bottom { @@ -393,12 +396,12 @@ pub impl Printer { } else { self.bottom += 1u; self.bottom %= self.buf_len; } return x; } - fn advance_right(&mut self) { + pub fn advance_right(&mut self) { self.right += 1u; self.right %= self.buf_len; assert!((self.right != self.left)); } - fn advance_left(&mut self, x: token, L: int) { + pub fn advance_left(&mut self, x: token, L: int) { debug!("advnce_left ~[%u,%u], sizeof(%u)=%d", self.left, self.right, self.left, L); if L >= 0 { @@ -418,7 +421,7 @@ pub impl Printer { } } } - fn check_stack(&mut self, k: int) { + pub fn check_stack(&mut self, k: int) { if !self.scan_stack_empty { let x = self.scan_top(); match copy self.token[x] { @@ -441,17 +444,17 @@ pub impl Printer { } } } - fn print_newline(&mut self, amount: int) { + pub fn print_newline(&mut self, amount: int) { debug!("NEWLINE %d", amount); (*self.out).write_str("\n"); self.pending_indentation = 0; self.indent(amount); } - fn indent(&mut self, amount: int) { + pub fn indent(&mut self, amount: int) { debug!("INDENT %d", amount); self.pending_indentation += amount; } - fn get_top(&mut self) -> print_stack_elt { + pub fn get_top(&mut self) -> print_stack_elt { let print_stack = &mut *self.print_stack; let n = print_stack.len(); if n != 0u { @@ -463,14 +466,14 @@ pub impl Printer { } } } - fn print_str(&mut self, s: &str) { + pub fn print_str(&mut self, s: &str) { while self.pending_indentation > 0 { (*self.out).write_str(" "); self.pending_indentation -= 1; } (*self.out).write_str(s); } - fn print(&mut self, x: token, L: int) { + pub fn print(&mut self, x: token, L: int) { debug!("print %s %d (remaining line space=%d)", tok_str(x), L, self.space); debug!("%s", buf_str(copy self.token, diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index e2736a00564..c3deb65163d 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -27,21 +27,21 @@ pub struct Interner<T> { } // when traits can extend traits, we should extend index<uint,T> to get [] -pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { - fn new() -> Interner<T> { +impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { + pub fn new() -> Interner<T> { Interner { map: @mut HashMap::new(), vect: @mut ~[], } } - fn prefill(init: &[T]) -> Interner<T> { + pub fn prefill(init: &[T]) -> Interner<T> { let rv = Interner::new(); for init.each() |v| { rv.intern(*v); } rv } - fn intern(&self, val: T) -> uint { + pub fn intern(&self, val: T) -> uint { match self.map.find(&val) { Some(&idx) => return idx, None => (), @@ -54,7 +54,7 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { new_idx } - fn gensym(&self, val: T) -> uint { + pub fn gensym(&self, val: T) -> uint { let new_idx = { let vect = &*self.vect; vect.len() @@ -67,11 +67,11 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - fn get(&self, idx: uint) -> T { self.vect[idx] } + pub fn get(&self, idx: uint) -> T { self.vect[idx] } - fn len(&self) -> uint { let vect = &*self.vect; vect.len() } + pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } - fn find_equiv<Q:Hash + IterBytes + Equiv<T>>(&self, val: &Q) + pub fn find_equiv<Q:Hash + IterBytes + Equiv<T>>(&self, val: &Q) -> Option<uint> { match self.map.find_equiv(val) { Some(v) => Some(*v), @@ -88,21 +88,21 @@ pub struct StrInterner { } // when traits can extend traits, we should extend index<uint,T> to get [] -pub impl StrInterner { - fn new() -> StrInterner { +impl StrInterner { + pub fn new() -> StrInterner { StrInterner { map: @mut HashMap::new(), vect: @mut ~[], } } - fn prefill(init: &[&str]) -> StrInterner { + pub fn prefill(init: &[&str]) -> StrInterner { let rv = StrInterner::new(); for init.each() |v| { rv.intern(*v); } rv } - fn intern(&self, val: &str) -> uint { + pub fn intern(&self, val: &str) -> uint { match self.map.find_equiv(&StringRef(val)) { Some(&idx) => return idx, None => (), @@ -114,7 +114,7 @@ pub impl StrInterner { new_idx } - fn gensym(&self, val: &str) -> uint { + pub fn gensym(&self, val: &str) -> uint { let new_idx = self.len(); // leave out of .map to avoid colliding self.vect.push(@val.to_owned()); @@ -124,12 +124,12 @@ pub impl StrInterner { // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - fn get(&self, idx: uint) -> @~str { self.vect[idx] } + pub fn get(&self, idx: uint) -> @~str { self.vect[idx] } - fn len(&self) -> uint { let vect = &*self.vect; vect.len() } + pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } - fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q) - -> Option<uint> { + pub fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q) + -> Option<uint> { match self.map.find_equiv(val) { Some(v) => Some(*v), None => None, |
