diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-08-03 00:07:20 -0700 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-08-03 00:07:20 -0700 |
| commit | deddb009f0003734d3c73fa859826d57ec600270 (patch) | |
| tree | 3646e0cc53c8b1203e8b16d6efc21e4b46c52be3 /src/libsyntax | |
| parent | 2a7be1c9e4d5a50dab4f3f95c8f1d843a7d6f084 (diff) | |
| parent | 87cf2864b1e427753f3153ee31aafcff19e253ca (diff) | |
| download | rust-deddb009f0003734d3c73fa859826d57ec600270.tar.gz rust-deddb009f0003734d3c73fa859826d57ec600270.zip | |
Merge pull request #8244 from thestinger/for
make `for` parse as `foreach` does r=huonw, bors is acting up and this has been run through the try bots
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/abi.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/oldvisit.rs | 78 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 11 |
3 files changed, 66 insertions, 58 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index e086334eb48..dc6919efcf9 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -94,12 +94,17 @@ pub fn lookup(name: &str) -> Option<Abi> { * Returns the ABI with the given name (if any). */ - for each_abi |abi| { + let mut res = None; + + do each_abi |abi| { if name == abi.data().name { - return Some(abi); + res = Some(abi); + false + } else { + true } - } - return None; + }; + res } pub fn all_names() -> ~[&'static str] { @@ -193,21 +198,24 @@ impl AbiSet { pub fn for_arch(&self, arch: Architecture) -> Option<Abi> { // NB---Single platform ABIs come first - for self.each |abi| { + + let mut res = None; + + do self.each |abi| { let data = abi.data(); match data.abi_arch { - Archs(a) if (a & arch.bit()) != 0 => { return Some(abi); } - Archs(_) => { } - RustArch | AllArch => { return Some(abi); } + Archs(a) if (a & arch.bit()) != 0 => { res = Some(abi); false } + Archs(_) => { true } + RustArch | AllArch => { res = Some(abi); false } } - } + }; - None + res } pub fn check_valid(&self) -> Option<(Abi, Abi)> { let mut abis = ~[]; - for self.each |abi| { abis.push(abi); } + do self.each |abi| { abis.push(abi); true }; foreach (i, abi) in abis.iter().enumerate() { let data = abi.data(); @@ -261,9 +269,10 @@ impl ToStr for Abi { impl ToStr for AbiSet { fn to_str(&self) -> ~str { let mut strs = ~[]; - for self.each |abi| { + do self.each |abi| { strs.push(abi.data().name); - } + true + }; fmt!("\"%s\"", strs.connect(" ")) } } diff --git a/src/libsyntax/oldvisit.rs b/src/libsyntax/oldvisit.rs index a39dc38a856..2de4aa474e5 100644 --- a/src/libsyntax/oldvisit.rs +++ b/src/libsyntax/oldvisit.rs @@ -126,10 +126,10 @@ pub fn visit_mod<E:Clone>(m: &_mod, _sp: span, _id: NodeId, (e, v): (E, vt<E>)) { - for m.view_items.iter().advance |vi| { + foreach vi in m.view_items.iter() { (v.visit_view_item)(vi, (e.clone(), v)); } - for m.items.iter().advance |i| { + foreach i in m.items.iter() { (v.visit_item)(*i, (e.clone(), v)); } } @@ -173,10 +173,10 @@ pub fn visit_item<E:Clone>(i: &item, (e, v): (E, vt<E>)) { } item_mod(ref m) => (v.visit_mod)(m, i.span, i.id, (e, v)), item_foreign_mod(ref nm) => { - for nm.view_items.iter().advance |vi| { + foreach vi in nm.view_items.iter() { (v.visit_view_item)(vi, (e.clone(), v)); } - for nm.items.iter().advance |ni| { + foreach ni in nm.items.iter() { (v.visit_foreign_item)(*ni, (e.clone(), v)); } } @@ -194,11 +194,11 @@ pub fn visit_item<E:Clone>(i: &item, (e, v): (E, vt<E>)) { } item_impl(ref tps, ref traits, ref ty, ref methods) => { (v.visit_generics)(tps, (e.clone(), v)); - for traits.iter().advance |p| { + foreach p in traits.iter() { visit_trait_ref(p, (e.clone(), v)); } (v.visit_ty)(ty, (e.clone(), v)); - for methods.iter().advance |m| { + foreach m in methods.iter() { visit_method_helper(*m, (e.clone(), v)) } } @@ -208,10 +208,10 @@ pub fn visit_item<E:Clone>(i: &item, (e, v): (E, vt<E>)) { } item_trait(ref generics, ref traits, ref methods) => { (v.visit_generics)(generics, (e.clone(), v)); - for traits.iter().advance |p| { + foreach p in traits.iter() { visit_path(&p.path, (e.clone(), v)); } - for methods.iter().advance |m| { + foreach m in methods.iter() { (v.visit_trait_method)(m, (e.clone(), v)); } } @@ -222,10 +222,10 @@ pub fn visit_item<E:Clone>(i: &item, (e, v): (E, vt<E>)) { pub fn visit_enum_def<E:Clone>(enum_definition: &ast::enum_def, tps: &Generics, (e, v): (E, vt<E>)) { - for enum_definition.variants.iter().advance |vr| { + foreach vr in enum_definition.variants.iter() { match vr.node.kind { tuple_variant_kind(ref variant_args) => { - for variant_args.iter().advance |va| { + foreach va in variant_args.iter() { (v.visit_ty)(&va.ty, (e.clone(), v)); } } @@ -235,7 +235,7 @@ pub fn visit_enum_def<E:Clone>(enum_definition: &ast::enum_def, } } // Visit the disr expr if it exists - for vr.node.disr_expr.iter().advance |ex| { + foreach ex in vr.node.disr_expr.iter() { (v.visit_expr)(*ex, (e.clone(), v)) } } @@ -250,12 +250,12 @@ pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) { (v.visit_ty)(mt.ty, (e, v)); }, ty_tup(ref ts) => { - for ts.iter().advance |tt| { + foreach tt in ts.iter() { (v.visit_ty)(tt, (e.clone(), v)); } }, ty_closure(ref f) => { - for f.decl.inputs.iter().advance |a| { + foreach a in f.decl.inputs.iter() { (v.visit_ty)(&a.ty, (e.clone(), v)); } (v.visit_ty)(&f.decl.output, (e.clone(), v)); @@ -264,7 +264,7 @@ pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) { }; }, ty_bare_fn(ref f) => { - for f.decl.inputs.iter().advance |a| { + foreach a in f.decl.inputs.iter() { (v.visit_ty)(&a.ty, (e.clone(), v)); } (v.visit_ty)(&f.decl.output, (e, v)); @@ -284,27 +284,27 @@ pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) { } pub fn visit_path<E:Clone>(p: &Path, (e, v): (E, vt<E>)) { - for p.types.iter().advance |tp| { (v.visit_ty)(tp, (e.clone(), v)); } + foreach tp in p.types.iter() { (v.visit_ty)(tp, (e.clone(), v)); } } pub fn visit_pat<E:Clone>(p: &pat, (e, v): (E, vt<E>)) { match p.node { pat_enum(ref path, ref children) => { visit_path(path, (e.clone(), v)); - for children.iter().advance |children| { - for children.iter().advance |child| { + foreach children in children.iter() { + foreach child in children.iter() { (v.visit_pat)(*child, (e.clone(), v)); } } } pat_struct(ref path, ref fields, _) => { visit_path(path, (e.clone(), v)); - for fields.iter().advance |f| { + foreach f in fields.iter() { (v.visit_pat)(f.pat, (e.clone(), v)); } } pat_tup(ref elts) => { - for elts.iter().advance |elt| { + foreach elt in elts.iter() { (v.visit_pat)(*elt, (e.clone(), v)) } }, @@ -313,7 +313,7 @@ pub fn visit_pat<E:Clone>(p: &pat, (e, v): (E, vt<E>)) { }, pat_ident(_, ref path, ref inner) => { visit_path(path, (e.clone(), v)); - for inner.iter().advance |subpat| { + foreach subpat in inner.iter() { (v.visit_pat)(*subpat, (e.clone(), v)) } } @@ -324,13 +324,13 @@ pub fn visit_pat<E:Clone>(p: &pat, (e, v): (E, vt<E>)) { } pat_wild => (), pat_vec(ref before, ref slice, ref after) => { - for before.iter().advance |elt| { + foreach elt in before.iter() { (v.visit_pat)(*elt, (e.clone(), v)); } - for slice.iter().advance |elt| { + foreach elt in slice.iter() { (v.visit_pat)(*elt, (e.clone(), v)); } - for after.iter().advance |tail| { + foreach tail in after.iter() { (v.visit_pat)(*tail, (e.clone(), v)); } } @@ -351,7 +351,7 @@ pub fn visit_foreign_item<E:Clone>(ni: &foreign_item, (e, v): (E, vt<E>)) { pub fn visit_ty_param_bounds<E:Clone>(bounds: &OptVec<TyParamBound>, (e, v): (E, vt<E>)) { - for bounds.iter().advance |bound| { + foreach bound in bounds.iter() { match *bound { TraitTyParamBound(ref ty) => visit_trait_ref(ty, (e.clone(), v)), RegionTyParamBound => {} @@ -360,13 +360,13 @@ pub fn visit_ty_param_bounds<E:Clone>(bounds: &OptVec<TyParamBound>, } pub fn visit_generics<E:Clone>(generics: &Generics, (e, v): (E, vt<E>)) { - for generics.ty_params.iter().advance |tp| { + foreach tp in generics.ty_params.iter() { visit_ty_param_bounds(&tp.bounds, (e.clone(), v)); } } pub fn visit_fn_decl<E:Clone>(fd: &fn_decl, (e, v): (E, vt<E>)) { - for fd.inputs.iter().advance |a| { + foreach a in fd.inputs.iter() { (v.visit_pat)(a.pat, (e.clone(), v)); (v.visit_ty)(&a.ty, (e.clone(), v)); } @@ -399,7 +399,7 @@ pub fn visit_fn<E:Clone>(fk: &fn_kind, } pub fn visit_ty_method<E:Clone>(m: &TypeMethod, (e, v): (E, vt<E>)) { - for m.decl.inputs.iter().advance |a| { + foreach a in m.decl.inputs.iter() { (v.visit_ty)(&a.ty, (e.clone(), v)); } (v.visit_generics)(&m.generics, (e.clone(), v)); @@ -420,7 +420,7 @@ pub fn visit_struct_def<E:Clone>( _id: NodeId, (e, v): (E, vt<E>) ) { - for sd.fields.iter().advance |f| { + foreach f in sd.fields.iter() { (v.visit_struct_field)(*f, (e.clone(), v)); } } @@ -430,10 +430,10 @@ pub fn visit_struct_field<E:Clone>(sf: &struct_field, (e, v): (E, vt<E>)) { } pub fn visit_block<E:Clone>(b: &Block, (e, v): (E, vt<E>)) { - for b.view_items.iter().advance |vi| { + foreach vi in b.view_items.iter() { (v.visit_view_item)(vi, (e.clone(), v)); } - for b.stmts.iter().advance |s| { + foreach s in b.stmts.iter() { (v.visit_stmt)(*s, (e.clone(), v)); } visit_expr_opt(b.expr, (e, v)); @@ -460,7 +460,7 @@ pub fn visit_expr_opt<E>(eo: Option<@expr>, (e, v): (E, vt<E>)) { } pub fn visit_exprs<E:Clone>(exprs: &[@expr], (e, v): (E, vt<E>)) { - for exprs.iter().advance |ex| { (v.visit_expr)(*ex, (e.clone(), v)); } + foreach ex in exprs.iter() { (v.visit_expr)(*ex, (e.clone(), v)); } } pub fn visit_mac<E>(_m: &mac, (_e, _v): (E, vt<E>)) { @@ -477,13 +477,13 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { } expr_struct(ref p, ref flds, base) => { visit_path(p, (e.clone(), v)); - for flds.iter().advance |f| { + foreach f in flds.iter() { (v.visit_expr)(f.expr, (e.clone(), v)); } visit_expr_opt(base, (e.clone(), v)); } expr_tup(ref elts) => { - for elts.iter().advance |el| { (v.visit_expr)(*el, (e.clone(), v)) } + foreach el in elts.iter() { (v.visit_expr)(*el, (e.clone(), v)) } } expr_call(callee, ref args, _) => { visit_exprs(*args, (e.clone(), v)); @@ -491,7 +491,7 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { } expr_method_call(_, callee, _, ref tys, ref args, _) => { visit_exprs(*args, (e.clone(), v)); - for tys.iter().advance |tp| { + foreach tp in tys.iter() { (v.visit_ty)(tp, (e.clone(), v)); } (v.visit_expr)(callee, (e.clone(), v)); @@ -524,7 +524,7 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { expr_loop(ref b, _) => (v.visit_block)(b, (e.clone(), v)), expr_match(x, ref arms) => { (v.visit_expr)(x, (e.clone(), v)); - for arms.iter().advance |a| { (v.visit_arm)(a, (e.clone(), v)); } + foreach a in arms.iter() { (v.visit_arm)(a, (e.clone(), v)); } } expr_fn_block(ref decl, ref body) => { (v.visit_fn)( @@ -547,7 +547,7 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { } expr_field(x, _, ref tys) => { (v.visit_expr)(x, (e.clone(), v)); - for tys.iter().advance |tp| { + foreach tp in tys.iter() { (v.visit_ty)(tp, (e.clone(), v)); } } @@ -567,10 +567,10 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { expr_mac(ref mac) => visit_mac(mac, (e.clone(), v)), expr_paren(x) => (v.visit_expr)(x, (e.clone(), v)), expr_inline_asm(ref a) => { - for a.inputs.iter().advance |&(_, input)| { + foreach &(_, input) in a.inputs.iter() { (v.visit_expr)(input, (e.clone(), v)); } - for a.outputs.iter().advance |&(_, out)| { + foreach &(_, out) in a.outputs.iter() { (v.visit_expr)(out, (e.clone(), v)); } } @@ -579,7 +579,7 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) { } pub fn visit_arm<E:Clone>(a: &arm, (e, v): (E, vt<E>)) { - for a.pats.iter().advance |p| { (v.visit_pat)(*p, (e.clone(), v)); } + foreach p in a.pats.iter() { (v.visit_pat)(*p, (e.clone(), v)); } visit_expr_opt(a.guard, (e.clone(), v)); (v.visit_block)(&a.body, (e.clone(), v)); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 386f027d6e1..ac3c50a53de 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -11,7 +11,7 @@ use abi; use abi::AbiSet; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; -use ast::{CallSugar, NoSugar, DoSugar, ForSugar}; +use ast::{CallSugar, NoSugar, DoSugar}; use ast::{TyBareFn, TyClosure}; use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; @@ -24,7 +24,7 @@ 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_do_body}; use ast::{expr_field, expr_fn_block, expr_if, expr_index}; -use ast::{expr_lit, expr_log, expr_loop, expr_loop_body, expr_mac}; +use ast::{expr_lit, expr_log, expr_loop, expr_mac}; use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; @@ -1626,8 +1626,7 @@ impl Parser { } else if self.eat_keyword(keywords::ForEach) { return self.parse_for_expr(); } else if self.eat_keyword(keywords::For) { - return self.parse_sugary_call_expr(lo, ~"for", ForSugar, - expr_loop_body); + return self.parse_for_expr(); } else if self.eat_keyword(keywords::Do) { return self.parse_sugary_call_expr(lo, ~"do", DoSugar, expr_do_body); @@ -2326,9 +2325,9 @@ impl Parser { } } - // parse a 'foreach' .. 'in' expression ('foreach' token already eaten) + // parse a 'for' .. 'in' expression ('for' token already eaten) pub fn parse_for_expr(&self) -> @expr { - // Parse: `foreach <src_pat> in <src_expr> <src_loop_block>` + // Parse: `for <src_pat> in <src_expr> <src_loop_block>` let lo = self.last_span.lo; let pat = self.parse_pat(); |
