diff options
| author | bors <bors@rust-lang.org> | 2013-04-29 14:33:37 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-29 14:33:37 -0700 |
| commit | f1ddb8d5cc66941763039d3f727465b7cc34a100 (patch) | |
| tree | 66132a53979403297cbe192ce936cfa7c5b3cb1f /src/libsyntax | |
| parent | dbcc3fe63a71d92d194d99dfd5e73fb62d09e79a (diff) | |
| parent | 78f33437b66793b10eb2a72d0d20cbf2bf0eacb5 (diff) | |
| download | rust-f1ddb8d5cc66941763039d3f727465b7cc34a100.tar.gz rust-f1ddb8d5cc66941763039d3f727465b7cc34a100.zip | |
auto merge of #6080 : pcwalton/rust/demode-everything, r=pcwalton
r? @brson
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/asm.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 75 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 119 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 31 |
11 files changed, 188 insertions, 151 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4137b3b8aa1..ba6fe1cda4f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -198,7 +198,7 @@ pub enum def { def_mod(def_id), def_foreign_mod(def_id), def_const(def_id), - def_arg(node_id, mode, bool /* is_mutbl */), + def_arg(node_id, bool /* is_mutbl */), def_local(node_id, bool /* is_mutbl */), def_variant(def_id /* enum */, def_id /* variant */), def_ty(def_id), @@ -417,43 +417,6 @@ pub enum unop { neg } -// Generally, after typeck you can get the inferred value -// using ty::resolved_T(...). -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum inferable<T> { - expl(T), - infer(node_id) -} - -impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - match *self { - expl(ref t) => - to_bytes::iter_bytes_2(&0u8, t, lsb0, f), - - infer(ref n) => - to_bytes::iter_bytes_2(&1u8, n, lsb0, f), - } - } -} - -// "resolved" mode: the real modes. -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum rmode { by_ref, by_copy } - -impl to_bytes::IterBytes for rmode { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - (*self as u8).iter_bytes(lsb0, f) - } -} - -// inferable mode. -pub type mode = inferable<rmode>; - pub type stmt = spanned<stmt_>; #[auto_encode] @@ -941,7 +904,6 @@ pub struct inline_asm { #[auto_decode] #[deriving(Eq)] pub struct arg { - mode: mode, is_mutbl: bool, ty: @Ty, pat: @pat, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c28d369e7f8..148b713a4f5 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -58,7 +58,7 @@ pub fn def_id_of_def(d: def) -> def_id { def_use(id) | def_struct(id) | def_trait(id) => { id } - def_arg(id, _, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) + def_arg(id, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) | def_upvar(id, _, _, _) | def_binding(id, _) | def_region(id) | def_typaram_binder(id) | def_label(id) => { local_def(id) diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 534027bd295..dfebf6f786a 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -52,7 +52,10 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) let mut dialect = ast::asm_att; let mut state = Asm; - loop outer: { + + // Not using labeled break to get us through one round of bootstrapping. + let mut continue = true; + while continue { match state { Asm => { asm = expr_to_str(cx, p.parse_expr(), @@ -139,20 +142,30 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) p.bump(); match next_state(state) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } } } else if *p.token == token::MOD_SEP { p.bump(); let s = match next_state(state) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } }; match next_state(s) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } } } else if *p.token == token::EOF { - break outer; + continue = false; + break; } else { state }; diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0d451c66edb..2ceb6f0c4bb 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -215,7 +215,50 @@ pub fn expand_auto_decode( } } -priv impl @ext_ctxt { +trait ExtCtxtMethods { + fn bind_path(&self, + span: span, + ident: ast::ident, + path: @ast::Path, + bounds: @OptVec<ast::TyParamBound>) + -> ast::TyParam; + fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; + fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Path; + fn path_tps_global(&self, + span: span, + strs: ~[ast::ident], + tps: ~[@ast::Ty]) + -> @ast::Path; + fn ty_path(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Ty; + fn binder_pat(&self, span: span, nm: ast::ident) -> @ast::pat; + fn stmt(&self, expr: @ast::expr) -> @ast::stmt; + fn lit_str(&self, span: span, s: @~str) -> @ast::expr; + fn lit_uint(&self, span: span, i: uint) -> @ast::expr; + fn lambda(&self, blk: ast::blk) -> @ast::expr; + fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk; + fn expr_blk(&self, expr: @ast::expr) -> ast::blk; + fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_var(&self, span: span, var: ~str) -> @ast::expr; + fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) + -> @ast::expr; + fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) + -> @ast::expr; + fn expr_method_call(&self, + span: span, + expr: @ast::expr, + ident: ast::ident, + args: ~[@ast::expr]) + -> @ast::expr; + fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr; + fn lambda_stmts(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr; +} + +impl ExtCtxtMethods for @ext_ctxt { fn bind_path( &self, _span: span, @@ -608,7 +651,6 @@ fn mk_ser_method( }; let ser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty_s, pat: @ast::pat { @@ -670,20 +712,22 @@ fn mk_deser_method( span: span, }; - let deser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), - is_mutbl: false, - ty: ty_d, - pat: @ast::pat { + let deser_inputs = ~[ + ast::arg { + is_mutbl: false, + ty: ty_d, + pat: @ast::pat { + id: cx.next_id(), + node: ast::pat_ident(ast::bind_by_copy, + ast_util::ident_to_path(span, + cx.ident_of( + ~"__d")), + None), + span: span, + }, id: cx.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - ast_util::ident_to_path(span, cx.ident_of(~"__d")), - None), - span: span, - }, - id: cx.next_id(), - }]; + } + ]; let deser_decl = ast::fn_decl { inputs: deser_inputs, @@ -1120,7 +1164,6 @@ fn mk_enum_deser_body( ast::expr_fn_block( ast::fn_decl { inputs: ~[ast::arg { - mode: ast::infer(ext_cx.next_id()), is_mutbl: false, ty: @ast::Ty { id: ext_cx.next_id(), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c4c2fed778f..4c876669f47 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -419,7 +419,6 @@ pub fn mk_arg(cx: @ext_ctxt, -> ast::arg { let arg_pat = mk_pat_ident(cx, span, ident); ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty, pat: arg_pat, diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index ede3711b052..deaf1b1c754 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -196,7 +196,6 @@ impl ext_ctxt_ast_builder for @ext_ctxt { fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { ast::arg { - mode: ast::infer(self.next_id()), is_mutbl: false, ty: ty, pat: @ast::pat { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index e6f5d3608af..3311c61de8b 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -75,10 +75,10 @@ impl gen_send for message { body += ~"let b = pipe.reuse_buffer();\n"; body += fmt!("let %s = ::core::pipes::SendPacketBuffered(\ - ::ptr::addr_of(&(b.buffer.data.%s)));\n", + &(b.buffer.data.%s));\n", sp, next.name); body += fmt!("let %s = ::core::pipes::RecvPacketBuffered(\ - ::ptr::addr_of(&(b.buffer.data.%s)));\n", + &(b.buffer.data.%s));\n", rp, next.name); } else { @@ -365,9 +365,9 @@ impl gen_init for protocol { |s| ext_cx.parse_stmt( fmt!("data.%s.set_buffer(buffer)", s.name))), - ext_cx.parse_expr( - fmt!("::ptr::addr_of(&(data.%s))", - self.states[0].name)))); + ext_cx.parse_expr(fmt!( + "::core::ptr::to_unsafe_ptr(&(data.%s))", + self.states[0].name)))); quote_expr!({ let buffer = $buffer; diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index da6d0e8bf7b..d82608846ab 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -105,7 +105,6 @@ fn fold_attribute_(at: attribute, fld: @ast_fold) -> attribute { //used in noop_fold_foreign_item and noop_fold_fn_decl fn fold_arg_(a: arg, fld: @ast_fold) -> arg { ast::arg { - mode: a.mode, is_mutbl: a.is_mutbl, ty: fld.fold_ty(a.ty), pat: fld.fold_pat(a.pat), @@ -868,7 +867,11 @@ impl ast_fold for AstFoldFns { } } -pub impl @ast_fold { +pub trait AstFoldExtensions { + fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute]; +} + +impl AstFoldExtensions for @ast_fold { fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute] { attrs.map(|x| fold_attribute_(*x, *self)) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d27d788e23a..7e7931bbb60 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -569,9 +569,8 @@ mod test { let parser = string_to_parser(@~"b : int"); assert_eq!(parser.parse_arg_general(true), ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(4,4), // this is bizarre... // check this in the original parser? @@ -579,9 +578,9 @@ mod test { idents:~[mk_ident(105)], rp: None, types: ~[]}, - 3), + 2), span:sp(4,7)}, - pat: @ast::pat{id:2, + pat: @ast::pat{id:1, node: ast::pat_ident(ast::bind_by_copy, @ast::Path{ span:sp(0,1), @@ -592,7 +591,7 @@ mod test { None // no idea ), span: sp(0,3)}, // really? - id: 5 // fixme + id: 4 // fixme }) } @@ -604,21 +603,20 @@ mod test { Some( @ast::item{ident:mk_ident(100), attrs:~[], - id: 11, // fixme + id: 10, // fixme node: ast::item_fn(ast::fn_decl{ inputs: ~[ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(10,13), global:false, idents:~[mk_ident(106)], rp: None, types: ~[]}, - 3), + 2), span:sp(10,13)}, - pat: @ast::pat{id:2, // fixme + pat: @ast::pat{id:1, // fixme node: ast::pat_ident( ast::bind_by_copy, @ast::Path{ @@ -630,9 +628,9 @@ mod test { None // no idea ), span: sp(6,9)}, // bleah. - id: 5 // fixme + id: 4 // fixme }], - output: @ast::Ty{id:6, // fixme + output: @ast::Ty{id:5, // fixme node: ast::ty_nil, span:sp(15,15)}, // not sure cf: ast::return_val @@ -649,8 +647,8 @@ mod test { view_items: ~[], stmts: ~[@spanned{ node: ast::stmt_semi(@ast::expr{ - id: 7, - callee_id: 8, + id: 6, + callee_id: 7, node: ast::expr_path( @ast::Path{ span:sp(17,18), @@ -659,10 +657,10 @@ mod test { rp:None, types: ~[]}), span: sp(17,18)}, - 9), // fixme + 8), // fixme span: sp(17,18)}], expr: None, - id: 10, // fixme + id: 9, // fixme rules: ast::default_blk // no idea }}), vis: ast::inherited, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 30275436c06..50bdfb2f557 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,10 +17,10 @@ use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; -use ast::{blk_check_mode, box, by_copy, by_ref}; +use ast::{blk_check_mode, box}; use ast::{crate, crate_cfg, decl, decl_item}; use ast::{decl_local, default_blk, deref, quot, enum_def}; -use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again}; +use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; use ast::{expr_field, expr_fn_block, expr_if, expr_index}; @@ -32,13 +32,13 @@ use ast::{expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod}; -use ast::{ident, impure_fn, infer, inherited, item, item_, item_const}; +use ast::{ident, impure_fn, inherited, item, item_, item_const}; use ast::{item_const, item_enum, item_fn, item_foreign_mod, item_impl}; use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int}; use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const}; use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; -use ast::{match_seq, match_tok, method, mode, mt, mul, mutability}; +use ast::{match_seq, match_tok, method, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct}; use ast::{pat_tup, pat_uniq, pat_wild, private}; @@ -348,6 +348,20 @@ pub impl Parser { self.token_is_keyword(&~"fn", tok) } + fn token_is_lifetime(&self, tok: &token::Token) -> bool { + match *tok { + token::LIFETIME(*) => true, + _ => false, + } + } + + fn get_lifetime(&self, tok: &token::Token) -> ast::ident { + match *tok { + token::LIFETIME(ref ident) => copy *ident, + _ => self.bug(~"not a lifetime"), + } + } + // parse a ty_bare_fun type: fn parse_ty_bare_fn(&self) -> ty_ { @@ -765,22 +779,22 @@ pub impl Parser { } // parse an optional mode. - fn parse_arg_mode(&self) -> mode { + // XXX: Remove after snapshot. + fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); - expl(by_copy) } else if self.eat(&token::ANDAND) { - expl(by_ref) + // Ignore. } else if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) { // ++ mode is obsolete, but we need a snapshot // to stop parsing it. - expl(by_copy) + // Ignore. } else { - expl(by_copy) + // Ignore. } } else { - infer(self.get_id()) + // Ignore. } } @@ -810,16 +824,14 @@ pub impl Parser { // This version of parse arg doesn't necessarily require // identifier names. fn parse_arg_general(&self, require_name: bool) -> arg { - let m; let mut is_mutbl = false; let pat = if require_name || self.is_named_argument() { - m = self.parse_arg_mode(); + self.parse_arg_mode(); is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); self.expect(&token::COLON); pat } else { - m = infer(self.get_id()); ast_util::ident_to_pat(self.get_id(), *self.last_span, special_idents::invalid) @@ -827,8 +839,12 @@ pub impl Parser { let t = self.parse_ty(false); - ast::arg { mode: m, is_mutbl: is_mutbl, - ty: t, pat: pat, id: self.get_id() } + ast::arg { + is_mutbl: is_mutbl, + ty: t, + pat: pat, + id: self.get_id(), + } } // parse a single function argument @@ -838,7 +854,7 @@ pub impl Parser { // parse an argument in a lambda header e.g. |arg, arg| fn parse_fn_block_arg(&self) -> arg_or_capture_item { - let m = self.parse_arg_mode(); + self.parse_arg_mode(); let is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); let t = if self.eat(&token::COLON) { @@ -851,7 +867,6 @@ pub impl Parser { } }; either::Left(ast::arg { - mode: m, is_mutbl: is_mutbl, ty: t, pat: pat, @@ -1227,8 +1242,14 @@ pub impl Parser { expr_do_body); } else if self.eat_keyword(&~"while") { return self.parse_while_expr(); + } else if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + self.expect(&token::COLON); + self.expect_keyword(&~"loop"); + return self.parse_loop_expr(Some(lifetime)); } else if self.eat_keyword(&~"loop") { - return self.parse_loop_expr(); + return self.parse_loop_expr(None); } else if self.eat_keyword(&~"match") { return self.parse_match_expr(); } else if self.eat_keyword(&~"unsafe") { @@ -1289,8 +1310,10 @@ pub impl Parser { } else { ex = expr_ret(None); } } else if self.eat_keyword(&~"break") { // BREAK expression - if is_ident(&*self.token) { - ex = expr_break(Some(self.parse_ident())); + if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + ex = expr_break(Some(lifetime)); } else { ex = expr_break(None); } @@ -1994,37 +2017,32 @@ pub impl Parser { return self.mk_expr(lo, hi, expr_while(cond, body)); } - fn parse_loop_expr(&self) -> @expr { + 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 || (is_ident(&*self.token) && self.look_ahead(1) == token::LBRACE); - // labeled loop headers look like 'loop foo: {' - let is_labeled_loop_header = - is_ident(&*self.token) - && !self.is_any_keyword(© *self.token) - && self.look_ahead(1) == token::COLON; - if is_loop_header || is_labeled_loop_header { + if is_loop_header { // This is a loop body - let opt_ident; - if is_labeled_loop_header { - opt_ident = Some(self.parse_ident()); - self.expect(&token::COLON); - } else { - opt_ident = None; - } - let lo = self.last_span.lo; let body = self.parse_block(); let hi = body.span.hi; return self.mk_expr(lo, hi, expr_loop(body, opt_ident)); } else { // This is a 'continue' expression + if opt_ident.is_some() { + self.span_err(*self.last_span, + ~"a label may not be used with a `loop` \ + expression"); + } + let lo = self.span.lo; - let ex = if is_ident(&*self.token) { - expr_again(Some(self.parse_ident())) + let ex = if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + expr_again(Some(lifetime)) } else { expr_again(None) }; @@ -2440,18 +2458,21 @@ pub impl Parser { // used by the copy foo and ref foo patterns to give a good // error message when parsing mistakes like ref foo(a,b) - fn parse_pat_ident(&self, refutable: bool, - binding_mode: ast::binding_mode) -> ast::pat_ { + fn parse_pat_ident(&self, + refutable: bool, + binding_mode: ast::binding_mode) + -> ast::pat_ { if !is_plain_ident(&*self.token) { - self.span_fatal( - *self.last_span, - ~"expected identifier, found path"); + self.span_fatal(*self.last_span, + ~"expected identifier, found path"); } // why a path here, and not just an identifier? let name = self.parse_path_without_tps(); let sub = if self.eat(&token::AT) { Some(self.parse_pat(refutable)) - } else { None }; + } else { + None + }; // just to be friendly, if they write something like // ref Some(i) @@ -4406,10 +4427,11 @@ pub impl Parser { // text that can't be parsed as an item // - mod_items uses extern_mod_allowed = true // - block_tail_ uses extern_mod_allowed = false - fn parse_items_and_view_items(&self, first_item_attrs: ~[attribute], + fn parse_items_and_view_items(&self, + first_item_attrs: ~[attribute], mut extern_mod_allowed: bool, macros_allowed: bool) - -> ParsedItemsAndViewItems { + -> ParsedItemsAndViewItems { let mut attrs = vec::append(first_item_attrs, self.parse_outer_attributes()); // First, parse view items. @@ -4539,8 +4561,11 @@ pub impl Parser { fn parse_str(&self) -> @~str { match *self.token { - token::LIT_STR(s) => { self.bump(); self.id_to_str(s) } - _ => self.fatal(~"expected string literal") + token::LIT_STR(s) => { + self.bump(); + self.id_to_str(s) + } + _ => self.fatal(~"expected string literal") } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 918fc805194..d5645ada929 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1210,12 +1210,13 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { print_block(s, blk); } ast::expr_loop(ref blk, opt_ident) => { - head(s, ~"loop"); - space(s.s); for opt_ident.each |ident| { + word(s.s, ~"'"); print_ident(s, *ident); word_space(s, ~":"); } + head(s, ~"loop"); + space(s.s); print_block(s, blk); } ast::expr_match(expr, ref arms) => { @@ -1363,12 +1364,20 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { ast::expr_break(opt_ident) => { word(s.s, ~"break"); space(s.s); - for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) } + for opt_ident.each |ident| { + word(s.s, ~"'"); + print_ident(s, *ident); + space(s.s); + } } ast::expr_again(opt_ident) => { word(s.s, ~"loop"); space(s.s); - for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) } + for opt_ident.each |ident| { + word(s.s, ~"'"); + print_ident(s, *ident); + space(s.s) + } } ast::expr_ret(result) => { word(s.s, ~"return"); @@ -1718,19 +1727,6 @@ pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -pub fn mode_to_str(m: ast::mode) -> ~str { - match m { - ast::expl(ast::by_ref) => ~"&&", - ast::expl(ast::by_copy) => ~"+", - ast::infer(_) => ~"" - } -} - -pub fn print_arg_mode(s: @ps, m: ast::mode) { - let ms = mode_to_str(m); - if ms != ~"" { word(s.s, ms); } -} - pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) { if !bounds.is_empty() { word(s.s, ~":"); @@ -1879,7 +1875,6 @@ pub fn print_mt(s: @ps, mt: &ast::mt) { pub fn print_arg(s: @ps, input: ast::arg) { ibox(s, indent_unit); - print_arg_mode(s, input.mode); if input.is_mutbl { word_space(s, ~"mut"); } |
