From 025d86624de982cdab7e6b13600fec1499c02b56 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 3 Aug 2012 19:59:04 -0700 Subject: Switch alts to use arrows --- src/libsyntax/ext/auto_serialize.rs | 76 ++++---- src/libsyntax/ext/base.rs | 72 ++++---- src/libsyntax/ext/env.rs | 4 +- src/libsyntax/ext/expand.rs | 85 +++++---- src/libsyntax/ext/fmt.rs | 171 +++++++++--------- src/libsyntax/ext/pipes/check.rs | 4 +- src/libsyntax/ext/pipes/parse_proto.rs | 18 +- src/libsyntax/ext/pipes/pipec.rs | 53 +++--- src/libsyntax/ext/pipes/proto.rs | 24 +-- src/libsyntax/ext/qquote.rs | 68 ++++---- src/libsyntax/ext/simplext.rs | 307 +++++++++++++++------------------ src/libsyntax/ext/source_util.rs | 8 +- src/libsyntax/ext/tt/earley_parser.rs | 87 +++++----- src/libsyntax/ext/tt/macro_rules.rs | 25 ++- src/libsyntax/ext/tt/transcribe.rs | 72 ++++---- 15 files changed, 505 insertions(+), 569 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index cc37b5cc8d0..6e9673f4bc2 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -102,18 +102,18 @@ fn expand(cx: ext_ctxt, do vec::flat_map(in_items) |in_item| { alt in_item.node { - ast::item_ty(ty, tps) { + ast::item_ty(ty, tps) => { vec::append(~[filter_attrs(in_item)], ty_fns(cx, in_item.ident, ty, tps)) } - ast::item_enum(variants, tps) { + ast::item_enum(variants, tps) => { vec::append(~[filter_attrs(in_item)], enum_fns(cx, in_item.ident, in_item.span, variants, tps)) } - _ { + _ => { cx.span_err(span, ~"#[auto_serialize] can only be \ applied to type and enum \ definitions"); @@ -376,12 +376,12 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty, fn is_vec_or_str(ty: @ast::ty) -> bool { alt ty.node { - ast::ty_vec(_) { true } + ast::ty_vec(_) => true, // This may be wrong if the user has shadowed (!) str ast::ty_path(@{span: _, global: _, idents: ids, rp: none, types: _}, _) - if ids == ~[@~"str"] { true } - _ { false } + if ids == ~[@~"str"] => true, + _ => false } } @@ -392,37 +392,37 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, let ext_cx = cx; // required for #ast{} alt ty.node { - ast::ty_nil { + ast::ty_nil => { ~[#ast[stmt]{$(s).emit_nil()}] } - ast::ty_bot { + ast::ty_bot => { cx.span_err( ty.span, fmt!{"Cannot serialize bottom type"}); ~[] } - ast::ty_box(mt) { + ast::ty_box(mt) => { let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) }); ~[#ast[stmt]{$(s).emit_box($(l));}] } // For unique evecs/estrs, just pass through to underlying vec or str - ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => { ser_ty(cx, tps, mt.ty, s, v) } - ast::ty_uniq(mt) { + ast::ty_uniq(mt) => { let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) }); ~[#ast[stmt]{$(s).emit_uniq($(l));}] } - ast::ty_ptr(_) | ast::ty_rptr(_, _) { + ast::ty_ptr(_) | ast::ty_rptr(_, _) => { cx.span_err(ty.span, ~"cannot serialize pointer types"); ~[] } - ast::ty_rec(flds) { + ast::ty_rec(flds) => { let fld_stmts = do vec::from_fn(vec::len(flds)) |fidx| { let fld = flds[fidx]; let vf = cx.expr(fld.span, @@ -439,12 +439,12 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ~[#ast[stmt]{$(s).emit_rec($(fld_lambda));}] } - ast::ty_fn(_, _) { + ast::ty_fn(_, _) => { cx.span_err(ty.span, ~"cannot serialize function types"); ~[] } - ast::ty_tup(tys) { + ast::ty_tup(tys) => { // Generate code like // // alt v { @@ -478,31 +478,31 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ~[cx.alt_stmt(arms, ty.span, v)] } - ast::ty_path(path, _) { + ast::ty_path(path, _) => { if vec::len(path.idents) == 1u && vec::is_empty(path.types) { let ident = path.idents[0]; alt tps.find(*ident) { - some(f) { f(v) } - none { ser_path(cx, tps, path, s, v) } + some(f) => f(v), + none => ser_path(cx, tps, path, s, v) } } else { ser_path(cx, tps, path, s, v) } } - ast::ty_mac(_) { + ast::ty_mac(_) => { cx.span_err(ty.span, ~"cannot serialize macro types"); ~[] } - ast::ty_infer { + ast::ty_infer => { cx.span_err(ty.span, ~"cannot serialize inferred types"); ~[] } - ast::ty_vec(mt) { + ast::ty_vec(mt) => { let ser_e = cx.expr( ty.span, @@ -519,7 +519,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, }] } - ast::ty_fixed_length(_, _) { + ast::ty_fixed_length(_, _) => { cx.span_unimpl(ty.span, ~"serialization for fixed length types"); } } @@ -635,34 +635,34 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, let ext_cx = cx; // required for #ast{} alt ty.node { - ast::ty_nil { + ast::ty_nil => { #ast{ $(d).read_nil() } } - ast::ty_bot { + ast::ty_bot => { #ast{ fail } } - ast::ty_box(mt) { + ast::ty_box(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ @$(d).read_box($(l)) } } // For unique evecs/estrs, just pass through to underlying vec or str - ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => { deser_ty(cx, tps, mt.ty, d) } - ast::ty_uniq(mt) { + ast::ty_uniq(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ ~$(d).read_uniq($(l)) } } - ast::ty_ptr(_) | ast::ty_rptr(_, _) { + ast::ty_ptr(_) | ast::ty_rptr(_, _) => { #ast{ fail } } - ast::ty_rec(flds) { + ast::ty_rec(flds) => { let fields = do vec::from_fn(vec::len(flds)) |fidx| { let fld = flds[fidx]; let d = cx.clone(d); @@ -679,11 +679,11 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ $(d).read_rec($(fld_lambda)) } } - ast::ty_fn(_, _) { + ast::ty_fn(_, _) => { #ast{ fail } } - ast::ty_tup(tys) { + ast::ty_tup(tys) => { // Generate code like // // d.read_tup(3u) {|| @@ -704,34 +704,34 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ $(d).read_tup($(sz), $(body)) } } - ast::ty_path(path, _) { + ast::ty_path(path, _) => { if vec::len(path.idents) == 1u && vec::is_empty(path.types) { let ident = path.idents[0]; alt tps.find(*ident) { - some(f) { f() } - none { deser_path(cx, tps, path, d) } + some(f) => f(), + none => deser_path(cx, tps, path, d) } } else { deser_path(cx, tps, path, d) } } - ast::ty_mac(_) { + ast::ty_mac(_) => { #ast{ fail } } - ast::ty_infer { + ast::ty_infer => { #ast{ fail } } - ast::ty_vec(mt) { + ast::ty_vec(mt) => { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ std::serialization::read_to_vec($(d), $(l)) } } - ast::ty_fixed_length(_, _) { + ast::ty_fixed_length(_, _) => { cx.span_unimpl(ty.span, ~"deserialization for fixed length types"); } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 2947201003f..b8cce21190c 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -151,7 +151,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { alt ei { - expanded_from({call_site: cs, callie: callie}) { + expanded_from({call_site: cs, callie: callie}) => { self.backtrace = some(@expanded_from({ call_site: {lo: cs.lo, hi: cs.hi, @@ -162,10 +162,10 @@ fn mk_ctxt(parse_sess: parse::parse_sess, } fn bt_pop() { alt self.backtrace { - some(@expanded_from({call_site: {expn_info: prev, _}, _})) { + some(@expanded_from({call_site: {expn_info: prev, _}, _})) => { self.backtrace = prev } - _ { self.bug(~"tried to pop without a push"); } + _ => self.bug(~"tried to pop without a push") } } fn span_fatal(sp: span, msg: ~str) -> ! { @@ -207,24 +207,22 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { alt expr.node { - ast::expr_lit(l) { - alt l.node { - ast::lit_str(s) { return *s; } - _ { cx.span_fatal(l.span, error); } - } + ast::expr_lit(l) => alt l.node { + ast::lit_str(s) => return *s, + _ => cx.span_fatal(l.span, error) } - _ { cx.span_fatal(expr.span, error); } + _ => cx.span_fatal(expr.span, error) } } fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident { alt expr.node { - ast::expr_path(p) { + ast::expr_path(p) => { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { cx.span_fatal(expr.span, error); } else { return p.idents[0]; } } - _ { cx.span_fatal(expr.span, error); } + _ => cx.span_fatal(expr.span, error) } } @@ -236,29 +234,27 @@ fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, min: uint, max: option, name: ~str) -> ~[@ast::expr] { alt arg { - some(expr) { - alt expr.node { - ast::expr_vec(elts, _) { + some(expr) => alt expr.node { + ast::expr_vec(elts, _) => { let elts_len = vec::len(elts); - alt max { - some(max) if ! (min <= elts_len && elts_len <= max) { - cx.span_fatal(sp, - fmt!{"#%s takes between %u and %u arguments.", - name, min, max}); - } - none if ! (min <= elts_len) { - cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.", - name, min}); + alt max { + some(max) if ! (min <= elts_len && elts_len <= max) => { + cx.span_fatal(sp, + fmt!{"#%s takes between %u and %u arguments.", + name, min, max}); + } + none if ! (min <= elts_len) => { + cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.", + name, min}); + } + _ => return elts /* we're good */ } - _ { return elts; /* we're good */} - } } - _ { + _ => { cx.span_fatal(sp, fmt!{"#%s: malformed invocation", name}) } - } } - none {cx.span_fatal(sp, fmt!{"#%s: missing arguments", name})} + none => cx.span_fatal(sp, fmt!{"#%s: missing arguments", name}) } } @@ -266,8 +262,8 @@ fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) -> ast::mac_body_ { alt (args) { - some(body) {body} - none {cx.span_fatal(sp, ~"missing macro body")} + some(body) => body, + none => cx.span_fatal(sp, ~"missing macro body") } } @@ -295,17 +291,15 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) let args = alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, argument_gram).get(@~"arg") { - @matched_seq(s, _) { - do s.map() |lf| { - alt lf { - @matched_nonterminal(parse::token::nt_expr(arg)) { - arg /* whew! list of exprs, here we come! */ - } - _ { fail ~"badly-structured parse result"; } - } + @matched_seq(s, _) => do s.map() |lf| { + alt lf { + @matched_nonterminal(parse::token::nt_expr(arg)) => { + arg /* whew! list of exprs, here we come! */ + } + _ => fail ~"badly-structured parse result" } } - _ { fail ~"badly-structured parse result"; } + _ => fail ~"badly-structured parse result" }; return some(@{id: parse::next_node_id(cx.parse_sess()), diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 4aa55e88f16..143a675fa63 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -17,8 +17,8 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let var = expr_to_str(cx, args[0], ~"#env requires a string"); alt os::getenv(var) { - option::none { return mk_uniq_str(cx, sp, ~""); } - option::some(s) { return mk_uniq_str(cx, sp, s); } + option::none => return mk_uniq_str(cx, sp, ~""), + option::some(s) => return mk_uniq_str(cx, sp, s) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 24cc78e366e..ee1ec62e4e2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -18,25 +18,25 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, return alt e { // expr_mac should really be expr_ext or something; it's the // entry-point for all syntax extensions. - expr_mac(mac) { + expr_mac(mac) => { // Old-style macros, for compatibility, will erase this whole // block once we've transitioned. alt mac.node { - mac_invoc(pth, args, body) { + mac_invoc(pth, args, body) => { assert (vec::len(pth.idents) > 0u); let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(item_decorator(_)) { + some(item_decorator(_)) => { cx.span_fatal( pth.span, fmt!{"%s can only be used as a decorator", *extname}); } - some(normal({expander: exp, span: exp_sp})) { + some(normal({expander: exp, span: exp_sp})) => { let expanded = exp(cx, mac.span, args, body); cx.bt_push(expanded_from({call_site: s, @@ -47,17 +47,17 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - some(macro_defining(ext)) { + some(macro_defining(ext)) => { let named_extension = ext(cx, mac.span, args, body); exts.insert(*named_extension.ident, named_extension.ext); (ast::expr_rec(~[], none), s) } - some(expr_tt(_)) { + some(expr_tt(_)) => { cx.span_fatal(pth.span, fmt!{"this tt-style macro should be \ invoked '%s!{...}'", *extname}) } - some(item_tt(*)) { + some(item_tt(*)) => { cx.span_fatal(pth.span, ~"cannot use item macros in this context"); } @@ -66,20 +66,20 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, // Token-tree macros, these will be the only case when we're // finished transitioning. - mac_invoc_tt(pth, tts) { + mac_invoc_tt(pth, tts) => { assert (vec::len(pth.idents) == 1u); let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(expr_tt({expander: exp, span: exp_sp})) { + some(expr_tt({expander: exp, span: exp_sp})) => { let expanded = alt exp(cx, mac.span, tts) { - mr_expr(e) { e } - _ { cx.span_fatal( + mr_expr(e) => e, + _ => cx.span_fatal( pth.span, fmt!{"non-expr macro in expr pos: %s", - *extname}) } + *extname}) }; cx.bt_push(expanded_from({call_site: s, @@ -90,7 +90,7 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - some(normal({expander: exp, span: exp_sp})) { + some(normal({expander: exp, span: exp_sp})) => { //convert the new-style invoc for the old-style macro let arg = base::tt_args_to_original_flavor(cx, pth.span, tts); @@ -104,7 +104,7 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - _ { + _ => { cx.span_fatal(pth.span, fmt!{"'%s' is not a tt-style macro", *extname}) @@ -112,10 +112,10 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, } } - _ { cx.span_bug(mac.span, ~"naked syntactic bit") } + _ => cx.span_bug(mac.span, ~"naked syntactic bit") } } - _ { orig(e, s, fld) } + _ => orig(e, s, fld) }; } @@ -142,17 +142,14 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, let new_items = do vec::flat_map(module_.items) |item| { do vec::foldr(item.attrs, ~[item]) |attr, items| { let mname = alt attr.node.value.node { - ast::meta_word(n) { n } - ast::meta_name_value(n, _) { n } - ast::meta_list(n, _) { n } + ast::meta_word(n) => n, + ast::meta_name_value(n, _) => n, + ast::meta_list(n, _) => n }; alt exts.find(*mname) { none | some(normal(_)) | some(macro_defining(_)) - | some(expr_tt(_)) | some(item_tt(*)) { - items - } - - some(item_decorator(dec_fn)) { + | some(expr_tt(_)) | some(item_tt(*)) => items, + some(item_decorator(dec_fn)) => { dec_fn(cx, attr.span, attr.node.value, items) } } @@ -170,24 +167,22 @@ fn expand_item(exts: hashmap<~str, syntax_extension>, -> option<@ast::item> { let is_mod = alt it.node { - ast::item_mod(_) | ast::item_foreign_mod(_) {true} - _ {false} + ast::item_mod(_) | ast::item_foreign_mod(_) => true, + _ => false }; let maybe_it = alt it.node { - ast::item_mac(*) { - expand_item_mac(exts, cx, it, fld) - } - _ { some(it) } + ast::item_mac(*) => expand_item_mac(exts, cx, it, fld), + _ => some(it) }; alt maybe_it { - some(it) { + some(it) => { if is_mod { cx.mod_push(it.ident); } let ret_val = orig(it, fld); if is_mod { cx.mod_pop(); } return ret_val; } - none { return none; } + none => return none } } @@ -198,24 +193,24 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, &&it: @ast::item, fld: ast_fold) -> option<@ast::item> { alt it.node { - item_mac({node: mac_invoc_tt(pth, tts), span}) { + item_mac({node: mac_invoc_tt(pth, tts), span}) => { let extname = pth.idents[0]; alt exts.find(*extname) { - none { + none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } - some(item_tt(expand)) { + some(item_tt(expand)) => { let expanded = expand.expander(cx, it.span, it.ident, tts); cx.bt_push(expanded_from({call_site: it.span, callie: {name: *extname, span: expand.span}})); let maybe_it = alt expanded { - mr_item(it) { fld.fold_item(it) } - mr_expr(e) { cx.span_fatal(pth.span, + mr_item(it) => fld.fold_item(it), + mr_expr(e) => cx.span_fatal(pth.span, ~"expr macro in item position: " + - *extname) } - mr_def(mdef) { + *extname), + mr_def(mdef) => { exts.insert(*mdef.ident, mdef.ext); none } @@ -223,13 +218,11 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx.bt_pop(); return maybe_it } - _ { cx.span_fatal(it.span, - fmt!{"%s is not a legal here", *extname}) } + _ => cx.span_fatal(it.span, + fmt!{"%s is not a legal here", *extname}) } } - _ { - cx.span_bug(it.span, ~"invalid item macro invocation"); - } + _ => cx.span_bug(it.span, ~"invalid item macro invocation") } } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 10820664344..d1acf622c1f 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -53,11 +53,11 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none"); for flags.each |f| { let fstr = alt f { - flag_left_justify { ~"flag_left_justify" } - flag_left_zero_pad { ~"flag_left_zero_pad" } - flag_space_for_sign { ~"flag_space_for_sign" } - flag_sign_always { ~"flag_sign_always" } - flag_alternate { ~"flag_alternate" } + flag_left_justify => ~"flag_left_justify", + flag_left_zero_pad => ~"flag_left_zero_pad", + flag_space_for_sign => ~"flag_space_for_sign", + flag_sign_always => ~"flag_sign_always", + flag_alternate => ~"flag_alternate" }; tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr, make_rt_path_expr(cx, sp, @fstr)); @@ -66,30 +66,28 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { alt cnt { - count_implied { + count_implied => { return make_rt_path_expr(cx, sp, @~"count_implied"); } - count_is(c) { + count_is(c) => { let count_lit = mk_int(cx, sp, c); let count_is_path = make_path_vec(cx, @~"count_is"); let count_is_args = ~[count_lit]; return mk_call(cx, sp, count_is_path, count_is_args); } - _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); } + _ => cx.span_unimpl(sp, ~"unimplemented #fmt conversion") } } fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { let mut rt_type; alt t { - ty_hex(c) { - alt c { - case_upper { rt_type = ~"ty_hex_upper"; } - case_lower { rt_type = ~"ty_hex_lower"; } - } + ty_hex(c) => alt c { + case_upper => rt_type = ~"ty_hex_upper", + case_lower => rt_type = ~"ty_hex_lower" } - ty_bits { rt_type = ~"ty_bits"; } - ty_octal { rt_type = ~"ty_octal"; } - _ { rt_type = ~"ty_default"; } + ty_bits => rt_type = ~"ty_bits", + ty_octal => rt_type = ~"ty_octal", + _ => rt_type = ~"ty_default" } return make_rt_path_expr(cx, sp, @rt_type); } @@ -124,128 +122,117 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, fn is_signed_type(cnv: conv) -> bool { alt cnv.ty { - ty_int(s) { - alt s { signed { return true; } unsigned { return false; } } + ty_int(s) => alt s { + signed => return true, + unsigned => return false } - ty_float { return true; } - _ { return false; } + ty_float => return true, + _ => return false } } let unsupported = ~"conversion not supported in #fmt string"; alt cnv.param { - option::none { } - _ { cx.span_unimpl(sp, unsupported); } + option::none => (), + _ => cx.span_unimpl(sp, unsupported) } for cnv.flags.each |f| { alt f { - flag_left_justify { } - flag_sign_always { + flag_left_justify => (), + flag_sign_always => { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"+ flag only valid in " + ~"signed #fmt conversion"); } } - flag_space_for_sign { + flag_space_for_sign => { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"space flag only valid in " + ~"signed #fmt conversions"); } } - flag_left_zero_pad { } - _ { cx.span_unimpl(sp, unsupported); } + flag_left_zero_pad => (), + _ => cx.span_unimpl(sp, unsupported) } } alt cnv.width { - count_implied { } - count_is(_) { } - _ { cx.span_unimpl(sp, unsupported); } + count_implied => (), + count_is(_) => (), + _ => cx.span_unimpl(sp, unsupported) } alt cnv.precision { - count_implied { } - count_is(_) { } - _ { cx.span_unimpl(sp, unsupported); } + count_implied => (), + count_is(_) => (), + _ => cx.span_unimpl(sp, unsupported) } alt cnv.ty { - ty_str { return make_conv_call(cx, arg.span, ~"str", cnv, arg); } - ty_int(sign) { - alt sign { - signed { - return make_conv_call(cx, arg.span, ~"int", cnv, arg); - } - unsigned { - return make_conv_call(cx, arg.span, ~"uint", cnv, arg); - } + ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg), + ty_int(sign) => alt sign { + signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg), + unsigned => { + return make_conv_call(cx, arg.span, ~"uint", cnv, arg) } } - ty_bool { return make_conv_call(cx, arg.span, ~"bool", cnv, arg); } - ty_char { return make_conv_call(cx, arg.span, ~"char", cnv, arg); } - ty_hex(_) { + ty_bool => return make_conv_call(cx, arg.span, ~"bool", cnv, arg), + ty_char => return make_conv_call(cx, arg.span, ~"char", cnv, arg), + ty_hex(_) => { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_bits { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_octal { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_float { + ty_bits => return make_conv_call(cx, arg.span, ~"uint", cnv, arg), + ty_octal => return make_conv_call(cx, arg.span, ~"uint", cnv, arg), + ty_float => { return make_conv_call(cx, arg.span, ~"float", cnv, arg); } - ty_poly { return make_conv_call(cx, arg.span, ~"poly", cnv, arg); } + ty_poly => return make_conv_call(cx, arg.span, ~"poly", cnv, arg) } } fn log_conv(c: conv) { alt c.param { - some(p) { log(debug, ~"param: " + int::to_str(p, 10u)); } - _ { debug!{"param: none"}; } + some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); } + _ => debug!{"param: none"} } for c.flags.each |f| { alt f { - flag_left_justify { debug!{"flag: left justify"}; } - flag_left_zero_pad { debug!{"flag: left zero pad"}; } - flag_space_for_sign { debug!{"flag: left space pad"}; } - flag_sign_always { debug!{"flag: sign always"}; } - flag_alternate { debug!{"flag: alternate"}; } + flag_left_justify => debug!{"flag: left justify"}, + flag_left_zero_pad => debug!{"flag: left zero pad"}, + flag_space_for_sign => debug!{"flag: left space pad"}, + flag_sign_always => debug!{"flag: sign always"}, + flag_alternate => debug!{"flag: alternate"} } } alt c.width { - count_is(i) { log(debug, - ~"width: count is " + int::to_str(i, 10u)); } - count_is_param(i) { - log(debug, - ~"width: count is param " + int::to_str(i, 10u)); - } - count_is_next_param { debug!{"width: count is next param"}; } - count_implied { debug!{"width: count is implied"}; } + count_is(i) => log( + debug, ~"width: count is " + int::to_str(i, 10u)), + count_is_param(i) => log( + debug, ~"width: count is param " + int::to_str(i, 10u)), + count_is_next_param => debug!{"width: count is next param"}, + count_implied => debug!{"width: count is implied"} } alt c.precision { - count_is(i) { log(debug, - ~"prec: count is " + int::to_str(i, 10u)); } - count_is_param(i) { - log(debug, - ~"prec: count is param " + int::to_str(i, 10u)); - } - count_is_next_param { debug!{"prec: count is next param"}; } - count_implied { debug!{"prec: count is implied"}; } + count_is(i) => log( + debug, ~"prec: count is " + int::to_str(i, 10u)), + count_is_param(i) => log( + debug, ~"prec: count is param " + int::to_str(i, 10u)), + count_is_next_param => debug!{"prec: count is next param"}, + count_implied => debug!{"prec: count is implied"} } alt c.ty { - ty_bool { debug!{"type: bool"}; } - ty_str { debug!{"type: str"}; } - ty_char { debug!{"type: char"}; } - ty_int(s) { - alt s { - signed { debug!{"type: signed"}; } - unsigned { debug!{"type: unsigned"}; } - } + ty_bool => debug!{"type: bool"}, + ty_str => debug!{"type: str"}, + ty_char => debug!{"type: char"}, + ty_int(s) => alt s { + signed => debug!{"type: signed"}, + unsigned => debug!{"type: unsigned"} } - ty_bits { debug!{"type: bits"}; } - ty_hex(cs) { - alt cs { - case_upper { debug!{"type: uhex"}; } - case_lower { debug!{"type: lhex"}; } - } + ty_bits => debug!{"type: bits"}, + ty_hex(cs) => alt cs { + case_upper => debug!{"type: uhex"}, + case_lower => debug!{"type: lhex"}, } - ty_octal { debug!{"type: octal"}; } - ty_float { debug!{"type: float"}; } - ty_poly { debug!{"type: poly"}; } + ty_octal => debug!{"type: octal"}, + ty_float => debug!{"type: float"}, + ty_poly => debug!{"type: poly"} } } let fmt_sp = args[0].span; @@ -254,10 +241,10 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, let nargs = args.len(); for pieces.each |pc| { alt pc { - piece_string(s) { - vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)); + piece_string(s) => { + vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)) } - piece_conv(conv) { + piece_conv(conv) => { n += 1u; if n >= nargs { cx.span_fatal(sp, diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 24ac18ada6a..59687eda96d 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -45,7 +45,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt { fn visit_message(name: ident, _span: span, _tys: &[@ast::ty], this: state, next: next_state) { alt next { - some({state: next, tys: next_tys}) { + some({state: next, tys: next_tys}) => { let proto = this.proto; if !proto.has_state(next) { // This should be a span fatal, but then we need to @@ -69,7 +69,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt { } } } - none { } + none => () } } } \ No newline at end of file diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index ea8c8c04b0e..678f5b36c45 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -26,16 +26,14 @@ impl proto_parser of proto_parser for parser { let id = self.parse_ident(); self.expect(token::COLON); let dir = alt copy self.token { - token::IDENT(n, _) { - self.get_str(n) - } - _ { fail } + token::IDENT(n, _) => self.get_str(n), + _ => fail }; self.bump(); let dir = alt dir { - @~"send" { send } - @~"recv" { recv } - _ { fail } + @~"send" => send, + @~"recv" => recv, + _ => fail }; let typarms = if self.token == token::LT { @@ -67,7 +65,7 @@ impl proto_parser of proto_parser for parser { self.expect(token::RARROW); let next = alt copy self.token { - token::IDENT(_, _) { + token::IDENT(_, _) => { let name = self.parse_ident(); let ntys = if self.token == token::LT { self.parse_unspanned_seq(token::LT, @@ -79,12 +77,12 @@ impl proto_parser of proto_parser for parser { else { ~[] }; some({state: name, tys: ntys}) } - token::NOT { + token::NOT => { // -> ! self.bump(); none } - _ { self.fatal(~"invalid next state") } + _ => self.fatal(~"invalid next state") }; state.add_message(mname, copy self.span, args, next); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 375ee81faa9..f61601a2aa0 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -48,7 +48,8 @@ impl compile of gen_send for message { fn gen_send(cx: ext_ctxt) -> @ast::item { debug!{"pipec: gen_send"}; alt self { - message(id, span, tys, this, some({state: next, tys: next_tys})) { + message(id, span, tys, this, + some({state: next, tys: next_tys})) => { debug!{"pipec: next state exists"}; let next = this.proto.get_state(next); assert next_tys.len() == next.ty_params.len(); @@ -71,10 +72,10 @@ impl compile of gen_send for message { if this.proto.is_bounded() { let (sp, rp) = alt (this.dir, next.dir) { - (send, send) { (~"c", ~"s") } - (send, recv) { (~"s", ~"c") } - (recv, send) { (~"s", ~"c") } - (recv, recv) { (~"c", ~"s") } + (send, send) => (~"c", ~"s"), + (send, recv) => (~"s", ~"c"), + (recv, send) => (~"s", ~"c"), + (recv, recv) => (~"c", ~"s") }; body += ~"let b = pipe.reuse_buffer();\n"; @@ -87,10 +88,10 @@ impl compile of gen_send for message { } else { let pat = alt (this.dir, next.dir) { - (send, send) { ~"(c, s)" } - (send, recv) { ~"(s, c)" } - (recv, send) { ~"(s, c)" } - (recv, recv) { ~"(c, s)" } + (send, send) => ~"(c, s)", + (send, recv) => ~"(s, c)", + (recv, send) => ~"(s, c)", + (recv, recv) => ~"(c, s)" }; body += fmt!{"let %s = pipes::entangle();\n", pat}; @@ -116,7 +117,7 @@ impl compile of gen_send for message { cx.expr_block(body)) } - message(id, span, tys, this, none) { + message(id, span, tys, this, none) => { debug!{"pipec: no next state"}; let arg_names = tys.mapi(|i, _ty| @(~"x_" + i.to_str())); @@ -181,20 +182,20 @@ impl compile of to_type_decls for state { let message(name, _span, tys, this, next) = m; let tys = alt next { - some({state: next, tys: next_tys}) { + some({state: next, tys: next_tys}) => { let next = this.proto.get_state(next); let next_name = next.data_name(); let dir = alt this.dir { - send { @~"server" } - recv { @~"client" } + send => @~"server", + recv => @~"client" }; vec::append_one(tys, cx.ty_path_ast_builder((dir + next_name) .add_tys(next_tys))) } - none { tys } + none => tys }; let v = cx.variant(name, tys); @@ -208,8 +209,8 @@ impl compile of to_type_decls for state { fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] { debug!{"pipec: to_endpoint_decls"}; let dir = alt dir { - send { (*self).dir } - recv { (*self).dir.reverse() } + send => (*self).dir, + recv => (*self).dir.reverse() }; let mut items = ~[]; for self.messages.each |m| { @@ -255,8 +256,8 @@ impl compile of gen_init for protocol { let body = if !self.is_bounded() { alt start_state.dir { - send { #ast { pipes::entangle() } } - recv { + send => #ast { pipes::entangle() }, + recv => { #ast {{ let (s, c) = pipes::entangle(); (c, s) @@ -267,8 +268,8 @@ impl compile of gen_init for protocol { else { let body = self.gen_init_bounded(ext_cx); alt start_state.dir { - send { body } - recv { + send => body, + recv => { #ast {{ let (s, c) = $(body); (c, s) @@ -322,8 +323,8 @@ impl compile of gen_init for protocol { for (copy self.states).each |s| { for s.ty_params.each |tp| { alt params.find(|tpp| *tp.ident == *tpp.ident) { - none { vec::push(params, tp) } - _ { } + none => vec::push(params, tp), + _ => () } } } @@ -338,8 +339,8 @@ impl compile of gen_init for protocol { let fields = do (copy self.states).map_to_vec |s| { for s.ty_params.each |tp| { alt params.find(|tpp| *tp.ident == *tpp.ident) { - none { vec::push(params, tp) } - _ { } + none => vec::push(params, tp), + _ => () } } let ty = s.to_ty(cx); @@ -439,8 +440,8 @@ impl parse_utils of ext_ctxt_parse_utils for ext_ctxt { ~[], self.parse_sess()); alt res { - some(ast) { ast } - none { + some(ast) => ast, + none => { error!{"Parse error with ```\n%s\n```", s}; fail } diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 1805fd9fa35..bd9ea96ee33 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -12,8 +12,8 @@ enum direction { impl of to_str for direction { fn to_str() -> ~str { alt self { - send { ~"send" } - recv { ~"recv" } + send => ~"send", + recv => ~"recv" } } } @@ -21,8 +21,8 @@ impl of to_str for direction { impl methods for direction { fn reverse() -> direction { alt self { - send { recv } - recv { send } + send => recv, + recv => send } } } @@ -37,26 +37,20 @@ enum message { impl methods for message { fn name() -> ident { alt self { - message(id, _, _, _, _) { - id - } + message(id, _, _, _, _) => id } } fn span() -> span { alt self { - message(_, span, _, _, _) { - span - } + message(_, span, _, _, _) => span } } /// Return the type parameters actually used by this message fn get_params() -> ~[ast::ty_param] { alt self { - message(_, _, _, this, _) { - this.ty_params - } + message(_, _, _, this, _) => this.ty_params } } } @@ -99,11 +93,11 @@ impl methods for state { fn reachable(f: fn(state) -> bool) { for self.messages.each |m| { alt m { - message(_, _, _, _, some({state: id, _})) { + message(_, _, _, _, some({state: id, _})) => { let state = self.proto.get_state(id); if !f(state) { break } } - _ { } + _ => () } } } diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs index 87ecf93aa3c..21ba9599240 100644 --- a/src/libsyntax/ext/qquote.rs +++ b/src/libsyntax/ext/qquote.rs @@ -49,8 +49,8 @@ impl of qq_helper for @ast::expr { fn visit(cx: aq_ctxt, v: vt) {visit_expr(self, cx, v);} fn extract_mac() -> option { alt (self.node) { - ast::expr_mac({node: mac, _}) {some(mac)} - _ {none} + ast::expr_mac({node: mac, _}) => some(mac), + _ => none } } fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr { @@ -64,8 +64,8 @@ impl of qq_helper for @ast::ty { fn visit(cx: aq_ctxt, v: vt) {visit_ty(self, cx, v);} fn extract_mac() -> option { alt (self.node) { - ast::ty_mac({node: mac, _}) {some(mac)} - _ {none} + ast::ty_mac({node: mac, _}) => some(mac), + _ => none } } fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr { @@ -125,14 +125,14 @@ fn gather_anti_quotes(lo: uint, node: N) -> aq_ctxt fn visit_aq(node: T, constr: ~str, &&cx: aq_ctxt, v: vt) { alt (node.extract_mac()) { - some(mac_aq(sp, e)) { + some(mac_aq(sp, e)) => { cx.gather.push(gather_item { lo: sp.lo - cx.lo, hi: sp.hi - cx.lo, e: e, constr: constr}); } - _ {node.visit(cx, v);} + _ => node.visit(cx, v) } } @@ -148,8 +148,8 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, do option::iter(arg) |arg| { let args: ~[@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { + ast::expr_vec(elts, _) => elts, + _ => { ecx.span_fatal (_sp, ~"#ast requires arguments of the form `~[...]`.") } @@ -159,20 +159,20 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, } alt (args[0].node) { ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u - {what = *id[0]} - _ {ecx.span_fatal(args[0].span, ~"expected an identifier");} + => what = *id[0], + _ => ecx.span_fatal(args[0].span, ~"expected an identifier") } } let body = get_mac_body(ecx,_sp,body); return alt what { - ~"crate" {finish(ecx, body, parse_crate)} - ~"expr" {finish(ecx, body, parse_expr)} - ~"ty" {finish(ecx, body, parse_ty)} - ~"item" {finish(ecx, body, parse_item)} - ~"stmt" {finish(ecx, body, parse_stmt)} - ~"pat" {finish(ecx, body, parse_pat)} - _ {ecx.span_fatal(_sp, ~"unsupported ast type")} + ~"crate" => finish(ecx, body, parse_crate), + ~"expr" => finish(ecx, body, parse_expr), + ~"ty" => finish(ecx, body, parse_ty), + ~"item" => finish(ecx, body, parse_item), + ~"stmt" => finish(ecx, body, parse_stmt), + ~"pat" => finish(ecx, body, parse_pat), + _ => ecx.span_fatal(_sp, ~"unsupported ast type") }; } @@ -184,8 +184,8 @@ fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) } fn parse_item(p: parser) -> @ast::item { alt p.parse_item(~[]) { - some(item) { item } - none { fail ~"parse_item: parsing an item failed"; } + some(item) => item, + none => fail ~"parse_item: parsing an item failed" } } @@ -226,11 +226,11 @@ fn finish str2 += repl; } alt copy state { - active {str::push_char(str2, ch);} - skip(1u) {state = blank;} - skip(sk) {state = skip (sk-1u);} - blank if is_space(ch) {str::push_char(str2, ch);} - blank {str::push_char(str2, ' ');} + active => str::push_char(str2, ch), + skip(1u) => state = blank, + skip(sk) => state = skip (sk-1u), + blank if is_space(ch) => str::push_char(str2, ch), + blank => str::push_char(str2, ' ') } i += 1u; if (j < g_len && i == cx.gather[j].hi) { @@ -309,11 +309,11 @@ fn replace_expr(repls: ~[fragment], -> (ast::expr_, span) { alt e { - ast::expr_mac({node: mac_var(i), _}) { - alt (repls[i]) { - from_expr(r) {(r.node, r.span)} - _ {fail /* fixme error message */}}} - _ {orig(e,s,fld)} + ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) { + from_expr(r) => (r.node, r.span), + _ => fail /* fixme error message */ + } + _ => orig(e,s,fld) } } @@ -323,11 +323,11 @@ fn replace_ty(repls: ~[fragment], -> (ast::ty_, span) { alt e { - ast::ty_mac({node: mac_var(i), _}) { - alt (repls[i]) { - from_ty(r) {(r.node, r.span)} - _ {fail /* fixme error message */}}} - _ {orig(e,s,fld)} + ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) { + from_ty(r) => (r.node, r.span), + _ => fail /* fixme error message */ + } + _ => orig(e,s,fld) } } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index b835300d5c7..79b609113ab 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -37,27 +37,17 @@ enum matchable { /* for when given an incompatible bit of AST */ fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! { alt m { - match_expr(x) { - cx.span_fatal(x.span, - ~"this argument is an expr, expected " + expected); - } - match_path(x) { - cx.span_fatal(x.span, - ~"this argument is a path, expected " + expected); - } - match_ident(x) { - cx.span_fatal(x.span, - ~"this argument is an ident, expected " + expected); - } - match_ty(x) { - cx.span_fatal(x.span, - ~"this argument is a type, expected " + expected); - } - match_block(x) { - cx.span_fatal(x.span, - ~"this argument is a block, expected " + expected); - } - match_exact { cx.bug(~"what is a match_exact doing in a bindings?"); } + match_expr(x) => cx.span_fatal( + x.span, ~"this argument is an expr, expected " + expected), + match_path(x) => cx.span_fatal( + x.span, ~"this argument is a path, expected " + expected), + match_ident(x) => cx.span_fatal( + x.span, ~"this argument is an ident, expected " + expected), + match_ty(x) => cx.span_fatal( + x.span, ~"this argument is a type, expected " + expected), + match_block(x) => cx.span_fatal( + x.span, ~"this argument is a block, expected " + expected), + match_exact => cx.bug(~"what is a match_exact doing in a bindings?") } } @@ -76,9 +66,8 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> let mut res = none; for elts.each |elt| { alt elt.node { - expr_mac(m) { - alt m.node { - ast::mac_ellipsis { + expr_mac(m) => alt m.node { + ast::mac_ellipsis => { if res != none { cx.span_fatal(m.span, ~"only one ellipsis allowed"); } @@ -86,37 +75,37 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> some({pre: vec::slice(elts, 0u, idx - 1u), rep: some(elts[idx - 1u]), post: vec::slice(elts, idx + 1u, vec::len(elts))}); - } - _ { } } + _ => () } - _ { } + _ => () } idx += 1u; } return alt res { - some(val) { val } - none { {pre: elts, rep: none, post: ~[]} } - } + some(val) => val, + none => {pre: elts, rep: none, post: ~[]} + } } fn option_flatten_map(f: fn@(T) -> option, v: ~[T]) -> option<~[U]> { let mut res = ~[]; for v.each |elem| { - alt f(elem) { none { return none; } some(fv) { vec::push(res, fv); } } + alt f(elem) { + none => return none, + some(fv) => vec::push(res, fv) + } } return some(res); } fn a_d_map(ad: arb_depth, f: selector) -> match_result { alt ad { - leaf(x) { return f(x); } - seq(ads, span) { - alt option_flatten_map(|x| a_d_map(x, f), *ads) { - none { return none; } - some(ts) { return some(seq(@ts, span)); } - } + leaf(x) => return f(x), + seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) { + none => return none, + some(ts) => return some(seq(@ts, span)) } } } @@ -124,8 +113,8 @@ fn a_d_map(ad: arb_depth, f: selector) -> match_result { fn compose_sels(s1: selector, s2: selector) -> selector { fn scomp(s1: selector, s2: selector, m: matchable) -> match_result { return alt s1(m) { - none { none } - some(matches) { a_d_map(matches, s2) } + none => none, + some(matches) => a_d_map(matches, s2) } } return { |x| scomp(s1, s2, x) }; @@ -167,13 +156,13 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option { let res = box_str_hash::>(); //need to do this first, to check vec lengths. for b.literal_ast_matchers.each |sel| { - alt sel(match_expr(e)) { none { return none; } _ { } } + alt sel(match_expr(e)) { none => return none, _ => () } } let mut never_mind: bool = false; for b.real_binders.each |key, val| { alt val(match_expr(e)) { - none { never_mind = true; } - some(mtc) { res.insert(key, mtc); } + none => never_mind = true, + some(mtc) => { res.insert(key, mtc); } } }; //HACK: `ret` doesn't work in `for each` @@ -221,8 +210,8 @@ fn follow(m: arb_depth, idx_path: @mut ~[uint]) -> let mut res: arb_depth = m; for vec::each(*idx_path) |idx| { res = alt res { - leaf(_) { return res;/* end of the line */ } - seq(new_ms, _) { new_ms[idx] } + leaf(_) => return res,/* end of the line */ + seq(new_ms, _) => new_ms[idx] } } return res; @@ -231,15 +220,15 @@ fn follow(m: arb_depth, idx_path: @mut ~[uint]) -> fn follow_for_trans(cx: ext_ctxt, mmaybe: option>, idx_path: @mut ~[uint]) -> option { alt mmaybe { - none { return none } - some(m) { + none => return none, + some(m) => { return alt follow(m, idx_path) { - seq(_, sp) { + seq(_, sp) => { cx.span_fatal(sp, ~"syntax matched under ... but not " + ~"used that way.") } - leaf(m) { return some(m) } + leaf(m) => return some(m) } } } @@ -270,24 +259,24 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], recur: fn@(&&@expr) -> @expr, exprs: ~[@expr]) -> ~[@expr] { alt elts_to_ell(cx, exprs) { - {pre: pre, rep: repeat_me_maybe, post: post} { + {pre: pre, rep: repeat_me_maybe, post: post} => { let mut res = vec::map(pre, recur); alt repeat_me_maybe { - none { } - some(repeat_me) { + none => (), + some(repeat_me) => { let mut repeat: option<{rep_count: uint, name: ident}> = none; /* we need to walk over all the free vars in lockstep, except for the leaves, which are just duplicated */ do free_vars(b, repeat_me) |fv| { let cur_pos = follow(b.get(fv), idx_path); alt cur_pos { - leaf(_) { } - seq(ms, _) { + leaf(_) => (), + seq(ms, _) => { alt repeat { - none { + none => { repeat = some({rep_count: vec::len(*ms), name: fv}); } - some({rep_count: old_len, name: old_name}) { + some({rep_count: old_len, name: old_name}) => { let len = vec::len(*ms); if old_len != len { let msg = @@ -302,12 +291,12 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], } }; alt repeat { - none { + none => { cx.span_fatal(repeat_me.span, ~"'...' surrounds an expression without any" + ~" repeating syntax variables"); } - some({rep_count: rc, _}) { + some({rep_count: rc, _}) => { /* Whew, we now know how how many times to repeat */ let mut idx: uint = 0u; while idx < rc { @@ -332,9 +321,9 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], &&i: ident, _fld: ast_fold) -> ident { return alt follow_for_trans(cx, b.find(i), idx_path) { - some(match_ident(a_id)) { a_id.node } - some(m) { match_error(cx, m, ~"an identifier") } - none { i } + some(match_ident(a_id)) => a_id.node, + some(m) => match_error(cx, m, ~"an identifier"), + none => i } } @@ -344,13 +333,13 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; } alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { - some(match_ident(id)) { + some(match_ident(id)) => { {span: id.span, global: false, idents: ~[id.node], rp: none, types: ~[]} } - some(match_path(a_pth)) { *a_pth } - some(m) { match_error(cx, m, ~"a path") } - none { p } + some(match_path(a_pth)) => *a_pth, + some(m) => match_error(cx, m, ~"a path"), + none => p } } @@ -361,26 +350,26 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (ast::expr_, span) { return alt e { - expr_path(p) { + expr_path(p) => { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { (e, s); } alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { - some(match_ident(id)) { + some(match_ident(id)) => { (expr_path(@{span: id.span, global: false, idents: ~[id.node], rp: none, types: ~[]}), id.span) } - some(match_path(a_pth)) { (expr_path(a_pth), s) } - some(match_expr(a_exp)) { (a_exp.node, a_exp.span) } - some(m) { match_error(cx, m, ~"an expression") } - none { orig(e, s, fld) } + some(match_path(a_pth)) => (expr_path(a_pth), s), + some(match_expr(a_exp)) => (a_exp.node, a_exp.span), + some(m) => match_error(cx, m, ~"an expression"), + none => orig(e, s, fld) } } - _ { orig(e, s, fld) } + _ => orig(e, s, fld) } } @@ -390,19 +379,19 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (ast::ty_, span) { return alt t { - ast::ty_path(pth, _) { + ast::ty_path(pth, _) => { alt path_to_ident(pth) { - some(id) { + some(id) => { alt follow_for_trans(cx, b.find(id), idx_path) { - some(match_ty(ty)) { (ty.node, ty.span) } - some(m) { match_error(cx, m, ~"a type") } - none { orig(t, s, fld) } + some(match_ty(ty)) => (ty.node, ty.span), + some(m) => match_error(cx, m, ~"a type"), + none => orig(t, s, fld) } } - none { orig(t, s, fld) } + none => orig(t, s, fld) } } - _ { orig(t, s, fld) } + _ => orig(t, s, fld) } } @@ -416,22 +405,16 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], -> (blk_, span) { return alt block_to_ident(blk) { - some(id) { + some(id) => { alt follow_for_trans(cx, b.find(id), idx_path) { - some(match_block(new_blk)) { (new_blk.node, new_blk.span) } - - - - + some(match_block(new_blk)) => (new_blk.node, new_blk.span), // possibly allow promotion of ident/path/expr to blocks? - some(m) { - match_error(cx, m, ~"a block") - } - none { orig(blk, s, fld) } + some(m) => match_error(cx, m, ~"a block"), + none => orig(blk, s, fld) } } - none { orig(blk, s, fld) } + none => orig(blk, s, fld) } } @@ -442,12 +425,12 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { //it might be possible to traverse only exprs, not matchables alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_path(p_pth) { p_t_s_r_path(cx, p_pth, s, b); } - expr_vec(p_elts, _) { + expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b), + expr_vec(p_elts, _) => { alt elts_to_ell(cx, p_elts) { - {pre: pre, rep: some(repeat_me), post: post} { + {pre: pre, rep: some(repeat_me), post: post} => { p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s, b); if vec::len(pre) > 0u { @@ -460,7 +443,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { ~"matching after `...` not yet supported"); } } - {pre: pre, rep: none, post: post} { + {pre: pre, rep: none, post: post} => { if post != ~[] { cx.bug(~"elts_to_ell provided an invalid result"); } @@ -470,26 +453,24 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { } } /* FIXME (#2251): handle embedded types and blocks, at least */ - expr_mac(mac) { + expr_mac(mac) => { p_t_s_r_mac(cx, mac, s, b); } - _ { + _ => { fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { if e == pat { some(leaf(match_exact)) } else { none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } b.literal_ast_matchers.push(|x| select(cx, x, e)); } } } - _ { - cx.bug(~"undocumented invariant in p_t_s_rec"); - } + _ => cx.bug(~"undocumented invariant in p_t_s_rec") } } @@ -497,29 +478,29 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { /* make a match more precise */ fn specialize_match(m: matchable) -> matchable { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_path(pth) { + expr_path(pth) => { alt path_to_ident(pth) { - some(id) { match_ident(respan(pth.span, id)) } - none { match_path(pth) } + some(id) => match_ident(respan(pth.span, id)), + none => match_path(pth) } } - _ { m } + _ => m } } - _ { m } + _ => m } } /* pattern_to_selectors helper functions */ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { alt path_to_ident(p) { - some(p_id) { + some(p_id) => { fn select(cx: ext_ctxt, m: matchable) -> match_result { return alt m { - match_expr(e) { some(leaf(specialize_match(m))) } - _ { cx.bug(~"broken traversal in p_t_s_r") } + match_expr(e) => some(leaf(specialize_match(m))), + _ => cx.bug(~"broken traversal in p_t_s_r") } } if b.real_binders.contains_key(p_id) { @@ -527,17 +508,18 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { } b.real_binders.insert(p_id, compose_sels(s, |x| select(cx, x))); } - none { } + none => () } } fn block_to_ident(blk: blk_) -> option { if vec::len(blk.stmts) != 0u { return none; } return alt blk.expr { - some(expr) { - alt expr.node { expr_path(pth) { path_to_ident(pth) } _ { none } } + some(expr) => alt expr.node { + expr_path(pth) => path_to_ident(pth), + _ => none } - none { none } + none => none } } @@ -545,21 +527,22 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { fn select_pt_1(cx: ext_ctxt, m: matchable, fn_m: fn(ast::mac) -> match_result) -> match_result { return alt m { - match_expr(e) { - alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } + match_expr(e) => alt e.node { + expr_mac(mac) => fn_m(mac), + _ => none } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! { cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported"); } alt mac.node { - ast::mac_ellipsis { cx.span_fatal(mac.span, ~"misused `...`"); } - ast::mac_invoc(_, _, _) { no_des(cx, mac.span, ~"macro calls"); } - ast::mac_invoc_tt(_, _) { no_des(cx, mac.span, ~"macro calls"); } - ast::mac_aq(_,_) { no_des(cx, mac.span, ~"antiquotes"); } - ast::mac_var(_) { no_des(cx, mac.span, ~"antiquote variables"); } + ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"), + ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"), + ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"), + ast::mac_aq(_,_) => no_des(cx, mac.span, ~"antiquotes"), + ast::mac_var(_) => no_des(cx, mac.span, ~"antiquote variables") } } @@ -568,9 +551,9 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { let mut elts = ~[]; let mut idx = offset; while idx < vec::len(arg_elts) { @@ -582,10 +565,10 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, // error we want to report is one in the macro def some(seq(@elts, repeat_me.span)) } - _ { none } + _ => none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } p_t_s_rec(cx, match_expr(repeat_me), @@ -598,18 +581,18 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector, fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { let actual_len = vec::len(arg_elts); if at_least && actual_len >= len || actual_len == len { some(leaf(match_exact)) } else { none } } - _ { none } + _ => none } } - _ { none } + _ => none } } b.literal_ast_matchers.push( @@ -622,15 +605,15 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool, while idx < vec::len(elts) { fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { return alt m { - match_expr(e) { + match_expr(e) => { alt e.node { - expr_vec(arg_elts, _) { + expr_vec(arg_elts, _) => { some(leaf(match_expr(arg_elts[idx]))) } - _ { none } + _ => none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ => cx.bug(~"broken traversal in p_t_s_r") } } p_t_s_rec(cx, match_expr(elts[idx]), @@ -647,7 +630,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let mut clauses: ~[@clause] = ~[]; for args.each |arg| { alt arg.node { - expr_vec(elts, mutbl) { + expr_vec(elts, mutbl) => { if vec::len(elts) != 2u { cx.span_fatal((*arg).span, ~"extension clause must consist of ~[" + @@ -656,31 +639,25 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, alt elts[0u].node { - expr_mac(mac) { + expr_mac(mac) => { alt mac.node { - mac_invoc(pth, invoc_arg, body) { + mac_invoc(pth, invoc_arg, body) => { alt path_to_ident(pth) { - some(id) { - alt macro_name { - none { macro_name = some(id); } - some(other_id) { - if id != other_id { - cx.span_fatal(pth.span, - ~"macro name must be " + - ~"consistent"); - } - } + some(id) => alt macro_name { + none => macro_name = some(id), + some(other_id) => if id != other_id { + cx.span_fatal(pth.span, + ~"macro name must be " + + ~"consistent"); } } - none { - cx.span_fatal(pth.span, - ~"macro name must not be a path"); - } + none => cx.span_fatal(pth.span, + ~"macro name must not be a path") } let arg = alt invoc_arg { - some(arg) { arg } - none { cx.span_fatal(mac.span, - ~"macro must have arguments")} + some(arg) => arg, + none => cx.span_fatal(mac.span, + ~"macro must have arguments") }; vec::push(clauses, @{params: pattern_to_selectors(cx, arg), @@ -689,20 +666,20 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, // FIXME (#2251): check duplicates (or just simplify // the macro arg situation) } - _ { + _ => { cx.span_bug(mac.span, ~"undocumented invariant in \ add_extension"); } } } - _ { + _ => { cx.span_fatal(elts[0u].span, ~"extension clause must" + ~" start with a macro invocation."); } } } - _ { + _ => { cx.span_fatal((*arg).span, ~"extension must be ~[clause, " + ~" ...]"); } @@ -713,11 +690,9 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, return {ident: alt macro_name { - some(id) { id } - none { - cx.span_fatal(sp, ~"macro definition must have " + - ~"at least one clause") - } + some(id) => id, + none => cx.span_fatal(sp, ~"macro definition must have " + + ~"at least one clause") }, ext: normal({expander: ext, span: some(option::get(arg).span)})}; @@ -725,13 +700,13 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body, clauses: ~[@clause]) -> @expr { let arg = alt arg { - some(arg) { arg } - none { cx.span_fatal(sp, ~"macro must have arguments")} + some(arg) => arg, + none => cx.span_fatal(sp, ~"macro must have arguments") }; for clauses.each |c| { alt use_selectors_to_bind(c.params, arg) { - some(bindings) { return transcribe(cx, bindings, c.body); } - none { again; } + some(bindings) => return transcribe(cx, bindings, c.body), + none => again } } cx.span_fatal(sp, ~"no clauses match macro invocation"); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 00c1e4ff47a..c55f1e67be2 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -71,8 +71,8 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let res = io::read_whole_file_str(res_rel_file(cx, sp, file)); alt res { - result::ok(_) { /* Continue. */ } - result::err(e) { + result::ok(_) => { /* Continue. */ } + result::err(e) => { cx.parse_sess().span_diagnostic.handler().fatal(e); } } @@ -87,13 +87,13 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let file = expr_to_str(cx, args[0], ~"#include_bin requires a string"); alt io::read_whole_file(res_rel_file(cx, sp, file)) { - result::ok(src) { + result::ok(src) => { let u8_exprs = vec::map(src, |char: u8| { mk_u8(cx, sp, char) }); return mk_uniq_vec_e(cx, sp, u8_exprs); } - result::err(e) { + result::err(e) => { cx.parse_sess().span_diagnostic.handler().fatal(e) } } diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index dd29ce04eeb..6a801f33aa6 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -32,8 +32,8 @@ enum matcher_pos_up { /* to break a circularity */ fn is_some(&&mpu: matcher_pos_up) -> bool { alt mpu { - matcher_pos_up(none) { false } - _ { true } + matcher_pos_up(none) => false, + _ => true } } @@ -49,17 +49,17 @@ type matcher_pos = ~{ fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos { alt mpu { - matcher_pos_up(some(mp)) { copy mp } - _ { fail } + matcher_pos_up(some(mp)) => copy mp, + _ => fail } } fn count_names(ms: &[matcher]) -> uint { vec::foldl(0u, ms, |ct, m| { ct + alt m.node { - match_tok(_) { 0u } - match_seq(more_ms, _, _, _, _) { count_names(more_ms) } - match_nonterminal(_,_,_) { 1u } + match_tok(_) => 0u, + match_seq(more_ms, _, _, _, _) => count_names(more_ms), + match_nonterminal(_,_,_) => 1u }}) } @@ -69,11 +69,11 @@ fn initial_matcher_pos(ms: ~[matcher], sep: option, lo: uint) let mut match_idx_hi = 0u; for ms.each() |elt| { alt elt.node { - match_tok(_) {} - match_seq(_,_,_,_,hi) { + match_tok(_) => (), + match_seq(_,_,_,_,hi) => { match_idx_hi = hi; // it is monotonic... } - match_nonterminal(_,_,pos) { + match_nonterminal(_,_,pos) => { match_idx_hi = pos+1u; // ...so latest is highest } } @@ -114,11 +114,11 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match]) fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match], ret_val: hashmap) { alt m { - {node: match_tok(_), span: _} { } - {node: match_seq(more_ms, _, _, _, _), span: _} { + {node: match_tok(_), span: _} => (), + {node: match_seq(more_ms, _, _, _, _), span: _} => { for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) }; } - {node: match_nonterminal(bind_name, _, idx), span: sp} { + {node: match_nonterminal(bind_name, _, idx), span: sp} => { if ret_val.contains_key(bind_name) { p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: " + *bind_name) @@ -140,10 +140,8 @@ enum parse_result { fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) -> hashmap { alt parse(sess, cfg, rdr, ms) { - success(m) { m } - failure(sp, str) { - sess.span_diagnostic.span_fatal(sp, str); - } + success(m) => m, + failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str) } } @@ -205,14 +203,14 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) // the *_t vars are workarounds for the lack of unary move alt copy ei.sep { - some(t) if idx == len { // we need a separator + some(t) if idx == len => { // we need a separator if tok == t { //pass the separator let ei_t <- ei; ei_t.idx += 1u; vec::push(next_eis, ei_t); } } - _ { // we don't need a separator + _ => { // we don't need a separator let ei_t <- ei; ei_t.idx = 0u; vec::push(cur_eis, ei_t); @@ -225,7 +223,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) alt copy ei.elts[idx].node { /* need to descend into sequence */ match_seq(matchers, sep, zero_ok, - match_idx_lo, match_idx_hi){ + match_idx_lo, match_idx_hi) => { if zero_ok { let new_ei = copy ei; new_ei.idx += 1u; @@ -248,8 +246,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) sp_lo: sp.lo }); } - match_nonterminal(_,_,_) { vec::push(bb_eis, ei) } - match_tok(t) { + match_nonterminal(_,_,_) => { vec::push(bb_eis, ei) } + match_tok(t) => { let ei_t <- ei; if t == tok { ei_t.idx += 1u; vec::push(next_eis, ei_t)} } @@ -273,10 +271,11 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) || bb_eis.len() > 1u { let nts = str::connect(vec::map(bb_eis, |ei| { alt ei.elts[ei.idx].node { - match_nonterminal(bind,name,_) { + match_nonterminal(bind,name,_) => { fmt!{"%s ('%s')", *name, *bind} } - _ { fail; } } }), ~" or "); + _ => fail + } }), ~" or "); return failure(sp, fmt!{ "Local ambiguity: multiple parsing options: \ built-in NTs %s or %u other options.", @@ -295,12 +294,12 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) let ei = vec::pop(bb_eis); alt ei.elts[ei.idx].node { - match_nonterminal(_, name, idx) { + match_nonterminal(_, name, idx) => { ei.matches[idx].push(@matched_nonterminal( parse_nt(rust_parser, *name))); ei.idx += 1u; } - _ { fail; } + _ => fail } vec::push(cur_eis,ei); @@ -320,30 +319,30 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) fn parse_nt(p: parser, name: ~str) -> nonterminal { alt name { - ~"item" { alt p.parse_item(~[]) { - some(i) { token::nt_item(i) } - none { p.fatal(~"expected an item keyword") } - }} - ~"block" { token::nt_block(p.parse_block()) } - ~"stmt" { token::nt_stmt(p.parse_stmt(~[])) } - ~"pat" { token::nt_pat(p.parse_pat(true)) } - ~"expr" { token::nt_expr(p.parse_expr()) } - ~"ty" { token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)) } + ~"item" => alt p.parse_item(~[]) { + some(i) => token::nt_item(i), + none => p.fatal(~"expected an item keyword") + } + ~"block" => token::nt_block(p.parse_block()), + ~"stmt" => token::nt_stmt(p.parse_stmt(~[])), + ~"pat" => token::nt_pat(p.parse_pat(true)), + ~"expr" => token::nt_expr(p.parse_expr()), + ~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), // this could be handled like a token, since it is one - ~"ident" { alt copy p.token { - token::IDENT(sn,b) { p.bump(); token::nt_ident(sn,b) } - _ { p.fatal(~"expected ident, found " - + token::to_str(*p.reader.interner(), copy p.token)) } - } } - ~"path" { token::nt_path(p.parse_path_with_tps(false)) } - ~"tt" { + ~"ident" => alt copy p.token { + token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) } + _ => p.fatal(~"expected ident, found " + + token::to_str(*p.reader.interner(), copy p.token)) + } + ~"path" => token::nt_path(p.parse_path_with_tps(false)), + ~"tt" => { p.quote_depth += 1u; //but in theory, non-quoted tts might be useful let res = token::nt_tt(@p.parse_token_tree()); p.quote_depth -= 1u; res } - ~"matchers" { token::nt_matchers(p.parse_matchers()) } - _ { p.fatal(~"Unsupported builtin nonterminal parser: " + name)} + ~"matchers" => token::nt_matchers(p.parse_matchers()), + _ => p.fatal(~"Unsupported builtin nonterminal parser: " + name) } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 28bf79be0d5..7655d7c970c 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -38,12 +38,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // Extract the arguments: let lhses:~[@named_match] = alt argument_map.get(@~"lhs") { - @matched_seq(s, sp) { s } - _ { cx.span_bug(sp, ~"wrong-structured lhs") } + @matched_seq(s, sp) => s, + _ => cx.span_bug(sp, ~"wrong-structured lhs") }; let rhses:~[@named_match] = alt argument_map.get(@~"rhs") { - @matched_seq(s, sp) { s } - _ { cx.span_bug(sp, ~"wrong-structured rhs") } + @matched_seq(s, sp) => s, + _ => cx.span_bug(sp, ~"wrong-structured rhs") }; // Given `lhses` and `rhses`, this is the new macro we create @@ -59,14 +59,14 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, for lhses.eachi() |i, lhs| { // try each arm's matchers alt lhs { - @matched_nonterminal(nt_matchers(mtcs)) { + @matched_nonterminal(nt_matchers(mtcs)) => { // `none` is because we're not interpolating let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader; alt parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) { - success(named_matches) { + success(named_matches) => { let rhs = alt rhses[i] { // okay, what's your transcriber? - @matched_nonterminal(nt_tt(@tt)) { tt } - _ { cx.span_bug(sp, ~"bad thing in rhs") } + @matched_nonterminal(nt_tt(@tt)) => tt, + _ => cx.span_bug(sp, ~"bad thing in rhs") }; // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, itr, some(named_matches), @@ -75,14 +75,13 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, trncbr as reader, SOURCE_FILE); return mr_expr(p.parse_expr()); } - failure(sp, msg) { - if sp.lo >= best_fail_spot.lo { - best_fail_spot = sp; best_fail_msg = msg; - } + failure(sp, msg) => if sp.lo >= best_fail_spot.lo { + best_fail_spot = sp; + best_fail_msg = msg; } } } - _ { cx.bug(~"non-matcher found in parsed lhses"); } + _ => cx.bug(~"non-matcher found in parsed lhses") } } cx.span_fatal(best_fail_spot, best_fail_msg); diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 9fda95c464e..c704fd351ec 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -47,8 +47,8 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>, mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::none)}, interpolations: alt interp { /* just a convienience */ - none { std::map::box_str_hash::<@named_match>() } - some(x) { x } + none => std::map::box_str_hash::<@named_match>(), + some(x) => x }, mut repeat_idx: ~[mut], mut repeat_len: ~[], /* dummy values, never read: */ @@ -62,10 +62,10 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>, pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame { @{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted, sep: f.sep, up: alt f.up { - tt_frame_up(some(up_frame)) { + tt_frame_up(some(up_frame)) => { tt_frame_up(some(dup_tt_frame(up_frame))) } - tt_frame_up(none) { tt_frame_up(none) } + tt_frame_up(none) => tt_frame_up(none) } } } @@ -83,11 +83,11 @@ pure fn lookup_cur_matched_by_matched(r: tt_reader, start: @named_match) -> @named_match { pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match { alt *ad { - matched_nonterminal(_) { + matched_nonterminal(_) => { // end of the line; duplicate henceforth ad } - matched_seq(ads, _) { ads[idx] } + matched_seq(ads, _) => ads[idx] } } vec::foldl(start, r.repeat_idx, red) @@ -103,33 +103,29 @@ enum lis { fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis { fn lis_merge(lhs: lis, rhs: lis) -> lis { alt lhs { - lis_unconstrained { rhs } - lis_contradiction(_) { lhs } - lis_constraint(l_len, l_id) { - alt rhs { - lis_unconstrained { lhs } - lis_contradiction(_) { rhs } - lis_constraint(r_len, _) if l_len == r_len { lhs } - lis_constraint(r_len, r_id) { + lis_unconstrained => rhs, + lis_contradiction(_) => lhs, + lis_constraint(l_len, l_id) => alt rhs { + lis_unconstrained => lhs, + lis_contradiction(_) => rhs, + lis_constraint(r_len, _) if l_len == r_len => lhs, + lis_constraint(r_len, r_id) => { lis_contradiction(fmt!{"Inconsistent lockstep iteration: \ - '%s' has %u items, but '%s' has %u", - *l_id, l_len, *r_id, r_len}) - } + '%s' has %u items, but '%s' has %u", + *l_id, l_len, *r_id, r_len}) } } } } alt t { - tt_delim(tts) | tt_seq(_, tts, _, _) { + tt_delim(tts) | tt_seq(_, tts, _, _) => { vec::foldl(lis_unconstrained, tts, {|lis, tt| lis_merge(lis, lockstep_iter_size(tt, r)) }) } - tt_tok(*) { lis_unconstrained } - tt_nonterminal(_, name) { - alt *lookup_cur_matched(r, name) { - matched_nonterminal(_) { lis_unconstrained } - matched_seq(ads, _) { lis_constraint(ads.len(), name) } - } + tt_tok(*) => lis_unconstrained, + tt_nonterminal(_, name) => alt *lookup_cur_matched(r, name) { + matched_nonterminal(_) => lis_unconstrained, + matched_seq(ads, _) => lis_constraint(ads.len(), name) } } } @@ -143,11 +139,11 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { || r.repeat_idx.last() == r.repeat_len.last() - 1 { alt r.cur.up { - tt_frame_up(none) { + tt_frame_up(none) => { r.cur_tok = EOF; return ret_val; } - tt_frame_up(some(tt_f)) { + tt_frame_up(some(tt_f)) => { if r.cur.dotdotdoted { vec::pop(r.repeat_idx); vec::pop(r.repeat_len); } @@ -161,40 +157,40 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { r.cur.idx = 0u; r.repeat_idx[r.repeat_idx.len() - 1u] += 1u; alt r.cur.sep { - some(tk) { + some(tk) => { r.cur_tok = tk; /* repeat same span, I guess */ return ret_val; } - none {} + none => () } } } loop { /* because it's easiest, this handles `tt_delim` not starting with a `tt_tok`, even though it won't happen */ alt r.cur.readme[r.cur.idx] { - tt_delim(tts) { + tt_delim(tts) => { r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::some(r.cur)) }; // if this could be 0-length, we'd need to potentially recur here } - tt_tok(sp, tok) { + tt_tok(sp, tok) => { r.cur_span = sp; r.cur_tok = tok; r.cur.idx += 1u; return ret_val; } - tt_seq(sp, tts, sep, zerok) { + tt_seq(sp, tts, sep, zerok) => { alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { - lis_unconstrained { + lis_unconstrained => { r.sp_diag.span_fatal( sp, /* blame macro writer */ ~"attempted to repeat an expression containing no syntax \ variables matched as repeating at this depth"); } - lis_contradiction(msg) { /* FIXME #2887 blame macro invoker + lis_contradiction(msg) => { /* FIXME #2887 blame macro invoker instead*/ r.sp_diag.span_fatal(sp, msg); } - lis_constraint(len, _) { + lis_constraint(len, _) => { if len == 0 { if !zerok { r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker @@ -215,22 +211,22 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } } // FIXME #2887: think about span stuff here - tt_nonterminal(sp, ident) { + tt_nonterminal(sp, ident) => { alt *lookup_cur_matched(r, ident) { /* sidestep the interpolation tricks for ident because (a) idents can be in lots of places, so it'd be a pain (b) we actually can, since it's a token. */ - matched_nonterminal(nt_ident(sn,b)) { + matched_nonterminal(nt_ident(sn,b)) => { r.cur_span = sp; r.cur_tok = IDENT(sn,b); r.cur.idx += 1u; return ret_val; } - matched_nonterminal(other_whole_nt) { + matched_nonterminal(other_whole_nt) => { r.cur_span = sp; r.cur_tok = INTERPOLATED(other_whole_nt); r.cur.idx += 1u; return ret_val; } - matched_seq(*) { + matched_seq(*) => { r.sp_diag.span_fatal( copy r.cur_span, /* blame the macro writer */ fmt!{"variable '%s' is still repeating at this depth", -- cgit 1.4.1-3-g733a5