diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-06 12:34:08 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-06 15:36:30 -0700 |
| commit | ecaf9e39c9435fa2de4fe393c4b263be36eb2d99 (patch) | |
| tree | 775f69be65adff65551d96173dd797e32e2c3157 /src/libsyntax/ext | |
| parent | d3a9bb1bd4a1d510bbaca2ab1121e4c85a239247 (diff) | |
| download | rust-ecaf9e39c9435fa2de4fe393c4b263be36eb2d99.tar.gz rust-ecaf9e39c9435fa2de4fe393c4b263be36eb2d99.zip | |
Convert alt to match. Stop parsing alt
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/auto_serialize.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/env.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/ext/fmt.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/check.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/parse_proto.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/qquote.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/ext/simplext.rs | 112 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/earley_parser.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 24 |
15 files changed, 174 insertions, 173 deletions
diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 6e9673f4bc2..c87ea71fc47 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -101,7 +101,7 @@ fn expand(cx: ext_ctxt, } do vec::flat_map(in_items) |in_item| { - alt in_item.node { + match in_item.node { ast::item_ty(ty, tps) => { vec::append(~[filter_attrs(in_item)], ty_fns(cx, in_item.ident, ty, tps)) @@ -375,7 +375,7 @@ 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 { + match ty.node { ast::ty_vec(_) => true, // This may be wrong if the user has shadowed (!) str ast::ty_path(@{span: _, global: _, idents: ids, @@ -391,7 +391,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, let ext_cx = cx; // required for #ast{} - alt ty.node { + match ty.node { ast::ty_nil => { ~[#ast[stmt]{$(s).emit_nil()}] } @@ -447,7 +447,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ast::ty_tup(tys) => { // Generate code like // - // alt v { + // match v { // (v1, v2, v3) { // .. serialize v1, v2, v3 .. // } @@ -483,7 +483,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, vec::is_empty(path.types) { let ident = path.idents[0]; - alt tps.find(*ident) { + match tps.find(*ident) { some(f) => f(v), none => ser_path(cx, tps, path, s, v) } @@ -634,7 +634,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, let ext_cx = cx; // required for #ast{} - alt ty.node { + match ty.node { ast::ty_nil => { #ast{ $(d).read_nil() } } @@ -709,7 +709,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, vec::is_empty(path.types) { let ident = path.idents[0]; - alt tps.find(*ident) { + match tps.find(*ident) { some(f) => f(), none => deser_path(cx, tps, path, d) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index b8cce21190c..f2e1855c0f5 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -150,7 +150,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn mod_pop() { vec::pop(self.mod_path); } fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { - alt ei { + match ei { expanded_from({call_site: cs, callie: callie}) => { self.backtrace = some(@expanded_from({ @@ -161,7 +161,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, } } fn bt_pop() { - alt self.backtrace { + match self.backtrace { some(@expanded_from({call_site: {expn_info: prev, _}, _})) => { self.backtrace = prev } @@ -206,8 +206,8 @@ 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 { + match expr.node { + ast::expr_lit(l) => match l.node { ast::lit_str(s) => return *s, _ => cx.span_fatal(l.span, error) } @@ -216,7 +216,7 @@ fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { } fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident { - alt expr.node { + match expr.node { ast::expr_path(p) => { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { cx.span_fatal(expr.span, error); @@ -233,11 +233,11 @@ 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<uint>, name: ~str) -> ~[@ast::expr] { - alt arg { - some(expr) => alt expr.node { + match arg { + some(expr) => match expr.node { ast::expr_vec(elts, _) => { let elts_len = vec::len(elts); - alt max { + match max { some(max) if ! (min <= elts_len && elts_len <= max) => { cx.span_fatal(sp, fmt!{"#%s takes between %u and %u arguments.", @@ -261,7 +261,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) -> ast::mac_body_ { - alt (args) { + match (args) { some(body) => body, none => cx.span_fatal(sp, ~"missing macro body") } @@ -289,10 +289,10 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic, cx.parse_sess().interner, none, arg); let args = - alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, + match 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 { + match lf { @matched_nonterminal(parse::token::nt_expr(arg)) => { arg /* whew! list of exprs, here we come! */ } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 143a675fa63..01030591da9 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -16,7 +16,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, // option<str> rather than just an maybe-empty string. let var = expr_to_str(cx, args[0], ~"#env requires a string"); - alt os::getenv(var) { + match os::getenv(var) { 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 ee1ec62e4e2..9b50101683a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -15,18 +15,18 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, orig: fn@(expr_, span, ast_fold) -> (expr_, span)) -> (expr_, span) { - return alt e { + return match e { // expr_mac should really be expr_ext or something; it's the // entry-point for all syntax extensions. expr_mac(mac) => { // Old-style macros, for compatibility, will erase this whole // block once we've transitioned. - alt mac.node { + match mac.node { mac_invoc(pth, args, body) => { assert (vec::len(pth.idents) > 0u); let extname = pth.idents[0]; - alt exts.find(*extname) { + match exts.find(*extname) { none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) @@ -69,13 +69,13 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, mac_invoc_tt(pth, tts) => { assert (vec::len(pth.idents) == 1u); let extname = pth.idents[0]; - alt exts.find(*extname) { + match exts.find(*extname) { none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) } some(expr_tt({expander: exp, span: exp_sp})) => { - let expanded = alt exp(cx, mac.span, tts) { + let expanded = match exp(cx, mac.span, tts) { mr_expr(e) => e, _ => cx.span_fatal( pth.span, fmt!{"non-expr macro in expr pos: %s", @@ -141,12 +141,12 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, // the item into a new set of items. 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 { + let mname = match attr.node.value.node { ast::meta_word(n) => n, ast::meta_name_value(n, _) => n, ast::meta_list(n, _) => n }; - alt exts.find(*mname) { + match exts.find(*mname) { none | some(normal(_)) | some(macro_defining(_)) | some(expr_tt(_)) | some(item_tt(*)) => items, some(item_decorator(dec_fn)) => { @@ -166,16 +166,16 @@ fn expand_item(exts: hashmap<~str, syntax_extension>, orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>) -> option<@ast::item> { - let is_mod = alt it.node { + let is_mod = match it.node { ast::item_mod(_) | ast::item_foreign_mod(_) => true, _ => false }; - let maybe_it = alt it.node { + let maybe_it = match it.node { ast::item_mac(*) => expand_item_mac(exts, cx, it, fld), _ => some(it) }; - alt maybe_it { + match maybe_it { some(it) => { if is_mod { cx.mod_push(it.ident); } let ret_val = orig(it, fld); @@ -192,10 +192,10 @@ fn expand_item(exts: hashmap<~str, syntax_extension>, fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt, &&it: @ast::item, fld: ast_fold) -> option<@ast::item> { - alt it.node { + match it.node { item_mac({node: mac_invoc_tt(pth, tts), span}) => { let extname = pth.idents[0]; - alt exts.find(*extname) { + match exts.find(*extname) { none => { cx.span_fatal(pth.span, fmt!{"macro undefined: '%s'", *extname}) @@ -205,7 +205,7 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>, cx.bt_push(expanded_from({call_site: it.span, callie: {name: *extname, span: expand.span}})); - let maybe_it = alt expanded { + let maybe_it = match expanded { mr_item(it) => fld.fold_item(it), mr_expr(e) => cx.span_fatal(pth.span, ~"expr macro in item position: " + diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index d1acf622c1f..19b5fefc1cf 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -52,7 +52,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, fn make_flags(cx: ext_ctxt, sp: span, flags: ~[flag]) -> @ast::expr { let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none"); for flags.each |f| { - let fstr = alt f { + let fstr = match f { flag_left_justify => ~"flag_left_justify", flag_left_zero_pad => ~"flag_left_zero_pad", flag_space_for_sign => ~"flag_space_for_sign", @@ -65,7 +65,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, return tmp_expr; } fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { - alt cnt { + match cnt { count_implied => { return make_rt_path_expr(cx, sp, @~"count_implied"); } @@ -80,8 +80,8 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { let mut rt_type; - alt t { - ty_hex(c) => alt c { + match t { + ty_hex(c) => match c { case_upper => rt_type = ~"ty_hex_upper", case_lower => rt_type = ~"ty_hex_lower" } @@ -121,8 +121,8 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, // FIXME: Move validation code into core::extfmt (Issue #2249) fn is_signed_type(cnv: conv) -> bool { - alt cnv.ty { - ty_int(s) => alt s { + match cnv.ty { + ty_int(s) => match s { signed => return true, unsigned => return false } @@ -131,12 +131,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } } let unsupported = ~"conversion not supported in #fmt string"; - alt cnv.param { + match cnv.param { option::none => (), _ => cx.span_unimpl(sp, unsupported) } for cnv.flags.each |f| { - alt f { + match f { flag_left_justify => (), flag_sign_always => { if !is_signed_type(cnv) { @@ -156,19 +156,19 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, _ => cx.span_unimpl(sp, unsupported) } } - alt cnv.width { + match cnv.width { count_implied => (), count_is(_) => (), _ => cx.span_unimpl(sp, unsupported) } - alt cnv.precision { + match cnv.precision { count_implied => (), count_is(_) => (), _ => cx.span_unimpl(sp, unsupported) } - alt cnv.ty { + match cnv.ty { ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg), - ty_int(sign) => alt sign { + ty_int(sign) => match sign { signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg), unsigned => { return make_conv_call(cx, arg.span, ~"uint", cnv, arg) @@ -188,12 +188,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } } fn log_conv(c: conv) { - alt c.param { + match c.param { some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); } _ => debug!{"param: none"} } for c.flags.each |f| { - alt f { + match 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"}, @@ -201,7 +201,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, flag_alternate => debug!{"flag: alternate"} } } - alt c.width { + match c.width { count_is(i) => log( debug, ~"width: count is " + int::to_str(i, 10u)), count_is_param(i) => log( @@ -209,7 +209,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, count_is_next_param => debug!{"width: count is next param"}, count_implied => debug!{"width: count is implied"} } - alt c.precision { + match c.precision { count_is(i) => log( debug, ~"prec: count is " + int::to_str(i, 10u)), count_is_param(i) => log( @@ -217,16 +217,16 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, count_is_next_param => debug!{"prec: count is next param"}, count_implied => debug!{"prec: count is implied"} } - alt c.ty { + match c.ty { ty_bool => debug!{"type: bool"}, ty_str => debug!{"type: str"}, ty_char => debug!{"type: char"}, - ty_int(s) => alt s { + ty_int(s) => match s { signed => debug!{"type: signed"}, unsigned => debug!{"type: unsigned"} } ty_bits => debug!{"type: bits"}, - ty_hex(cs) => alt cs { + ty_hex(cs) => match cs { case_upper => debug!{"type: uhex"}, case_lower => debug!{"type: lhex"}, } @@ -240,7 +240,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, let mut piece_exprs = ~[]; let nargs = args.len(); for pieces.each |pc| { - alt pc { + match pc { piece_string(s) => { vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)) } diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 59687eda96d..8595a991e24 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -44,7 +44,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 { + match next { some({state: next, tys: next_tys}) => { let proto = this.proto; if !proto.has_state(next) { diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index 678f5b36c45..aa553d8ae53 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -25,12 +25,12 @@ impl proto_parser of proto_parser for parser { fn parse_state(proto: protocol) { let id = self.parse_ident(); self.expect(token::COLON); - let dir = alt copy self.token { + let dir = match copy self.token { token::IDENT(n, _) => self.get_str(n), _ => fail }; self.bump(); - let dir = alt dir { + let dir = match dir { @~"send" => send, @~"recv" => recv, _ => fail @@ -64,7 +64,7 @@ impl proto_parser of proto_parser for parser { self.expect(token::RARROW); - let next = alt copy self.token { + let next = match copy self.token { token::IDENT(_, _) => { let name = self.parse_ident(); let ntys = if self.token == token::LT { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index f61601a2aa0..16ba6d3a063 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -47,7 +47,7 @@ trait gen_init { impl compile of gen_send for message { fn gen_send(cx: ext_ctxt) -> @ast::item { debug!{"pipec: gen_send"}; - alt self { + match self { message(id, span, tys, this, some({state: next, tys: next_tys})) => { debug!{"pipec: next state exists"}; @@ -71,7 +71,7 @@ impl compile of gen_send for message { let mut body = ~"{\n"; if this.proto.is_bounded() { - let (sp, rp) = alt (this.dir, next.dir) { + let (sp, rp) = match (this.dir, next.dir) { (send, send) => (~"c", ~"s"), (send, recv) => (~"s", ~"c"), (recv, send) => (~"s", ~"c"), @@ -87,7 +87,7 @@ impl compile of gen_send for message { rp, *next.name}; } else { - let pat = alt (this.dir, next.dir) { + let pat = match (this.dir, next.dir) { (send, send) => ~"(c, s)", (send, recv) => ~"(s, c)", (recv, send) => ~"(s, c)", @@ -181,12 +181,12 @@ impl compile of to_type_decls for state { for self.messages.each |m| { let message(name, _span, tys, this, next) = m; - let tys = alt next { + let tys = match next { some({state: next, tys: next_tys}) => { let next = this.proto.get_state(next); let next_name = next.data_name(); - let dir = alt this.dir { + let dir = match this.dir { send => @~"server", recv => @~"client" }; @@ -208,7 +208,7 @@ 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 { + let dir = match dir { send => (*self).dir, recv => (*self).dir.reverse() }; @@ -255,7 +255,7 @@ impl compile of gen_init for protocol { let start_state = self.states[0]; let body = if !self.is_bounded() { - alt start_state.dir { + match start_state.dir { send => #ast { pipes::entangle() }, recv => { #ast {{ @@ -267,7 +267,7 @@ impl compile of gen_init for protocol { } else { let body = self.gen_init_bounded(ext_cx); - alt start_state.dir { + match start_state.dir { send => body, recv => { #ast {{ @@ -322,7 +322,7 @@ impl compile of gen_init for protocol { let mut params: ~[ast::ty_param] = ~[]; for (copy self.states).each |s| { for s.ty_params.each |tp| { - alt params.find(|tpp| *tp.ident == *tpp.ident) { + match params.find(|tpp| *tp.ident == *tpp.ident) { none => vec::push(params, tp), _ => () } @@ -338,7 +338,7 @@ impl compile of gen_init for protocol { let mut params: ~[ast::ty_param] = ~[]; let fields = do (copy self.states).map_to_vec |s| { for s.ty_params.each |tp| { - alt params.find(|tpp| *tp.ident == *tpp.ident) { + match params.find(|tpp| *tp.ident == *tpp.ident) { none => vec::push(params, tp), _ => () } @@ -439,7 +439,7 @@ impl parse_utils of ext_ctxt_parse_utils for ext_ctxt { self.cfg(), ~[], self.parse_sess()); - alt res { + match res { some(ast) => ast, none => { error!{"Parse error with ```\n%s\n```", s}; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index bd9ea96ee33..5769125225e 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -11,7 +11,7 @@ enum direction { impl of to_str for direction { fn to_str() -> ~str { - alt self { + match self { send => ~"send", recv => ~"recv" } @@ -20,7 +20,7 @@ impl of to_str for direction { impl methods for direction { fn reverse() -> direction { - alt self { + match self { send => recv, recv => send } @@ -36,20 +36,20 @@ enum message { impl methods for message { fn name() -> ident { - alt self { + match self { message(id, _, _, _, _) => id } } fn span() -> span { - alt self { + match self { message(_, span, _, _, _) => span } } /// Return the type parameters actually used by this message fn get_params() -> ~[ast::ty_param] { - alt self { + match self { message(_, _, _, this, _) => this.ty_params } } @@ -92,7 +92,7 @@ impl methods for state { /// from this state. fn reachable(f: fn(state) -> bool) { for self.messages.each |m| { - alt m { + match m { 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 21ba9599240..491d6104c7b 100644 --- a/src/libsyntax/ext/qquote.rs +++ b/src/libsyntax/ext/qquote.rs @@ -48,7 +48,7 @@ impl of qq_helper for @ast::expr { fn span() -> span {self.span} fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);} fn extract_mac() -> option<ast::mac_> { - alt (self.node) { + match (self.node) { ast::expr_mac({node: mac, _}) => some(mac), _ => none } @@ -63,7 +63,7 @@ impl of qq_helper for @ast::ty { fn span() -> span {self.span} fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);} fn extract_mac() -> option<ast::mac_> { - alt (self.node) { + match (self.node) { ast::ty_mac({node: mac, _}) => some(mac), _ => none } @@ -124,7 +124,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>) { - alt (node.extract_mac()) { + match (node.extract_mac()) { some(mac_aq(sp, e)) => { cx.gather.push(gather_item { lo: sp.lo - cx.lo, @@ -147,7 +147,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, let mut what = ~"expr"; do option::iter(arg) |arg| { let args: ~[@ast::expr] = - alt arg.node { + match arg.node { ast::expr_vec(elts, _) => elts, _ => { ecx.span_fatal @@ -157,7 +157,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, if vec::len::<@ast::expr>(args) != 1u { ecx.span_fatal(_sp, ~"#ast requires exactly one arg"); } - alt (args[0].node) { + match (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") @@ -165,7 +165,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, } let body = get_mac_body(ecx,_sp,body); - return alt what { + return match what { ~"crate" => finish(ecx, body, parse_crate), ~"expr" => finish(ecx, body, parse_expr), ~"ty" => finish(ecx, body, parse_ty), @@ -183,7 +183,7 @@ fn parse_expr(p: parser) -> @ast::expr { p.parse_expr() } fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) } fn parse_item(p: parser) -> @ast::item { - alt p.parse_item(~[]) { + match p.parse_item(~[]) { some(item) => item, none => fail ~"parse_item: parsing an item failed" } @@ -225,7 +225,7 @@ fn finish<T: qq_helper> state = skip(str::char_len(repl)); str2 += repl; } - alt copy state { + match copy state { active => str::push_char(str2, ch), skip(1u) => state = blank, skip(sk) => state = skip (sk-1u), @@ -308,8 +308,8 @@ fn replace_expr(repls: ~[fragment], orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span)) -> (ast::expr_, span) { - alt e { - ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) { + match e { + ast::expr_mac({node: mac_var(i), _}) => match (repls[i]) { from_expr(r) => (r.node, r.span), _ => fail /* fixme error message */ } @@ -322,8 +322,8 @@ fn replace_ty(repls: ~[fragment], orig: fn@(ast::ty_, span, ast_fold)->(ast::ty_, span)) -> (ast::ty_, span) { - alt e { - ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) { + match e { + ast::ty_mac({node: mac_var(i), _}) => match (repls[i]) { from_ty(r) => (r.node, r.span), _ => fail /* fixme error message */ } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index 79b609113ab..bdb0c663fc7 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -36,7 +36,7 @@ enum matchable { /* for when given an incompatible bit of AST */ fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! { - alt m { + match m { match_expr(x) => cx.span_fatal( x.span, ~"this argument is an expr, expected " + expected), match_path(x) => cx.span_fatal( @@ -65,8 +65,8 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> let mut idx: uint = 0u; let mut res = none; for elts.each |elt| { - alt elt.node { - expr_mac(m) => alt m.node { + match elt.node { + expr_mac(m) => match m.node { ast::mac_ellipsis => { if res != none { cx.span_fatal(m.span, ~"only one ellipsis allowed"); @@ -82,7 +82,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> } idx += 1u; } - return alt res { + return match res { some(val) => val, none => {pre: elts, rep: none, post: ~[]} } @@ -92,7 +92,7 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) -> option<~[U]> { let mut res = ~[]; for v.each |elem| { - alt f(elem) { + match f(elem) { none => return none, some(fv) => vec::push(res, fv) } @@ -101,9 +101,9 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) -> } fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { - alt ad { + match ad { leaf(x) => return f(x), - seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) { + seq(ads, span) => match option_flatten_map(|x| a_d_map(x, f), *ads) { none => return none, some(ts) => return some(seq(@ts, span)) } @@ -112,7 +112,7 @@ fn a_d_map(ad: arb_depth<matchable>, 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) { + return match s1(m) { none => none, some(matches) => a_d_map(matches, s2) } @@ -156,11 +156,11 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> { let res = box_str_hash::<arb_depth<matchable>>(); //need to do this first, to check vec lengths. for b.literal_ast_matchers.each |sel| { - alt sel(match_expr(e)) { none => return none, _ => () } + match 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)) { + match val(match_expr(e)) { none => never_mind = true, some(mtc) => { res.insert(key, mtc); } } @@ -209,7 +209,7 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) -> arb_depth<matchable> { let mut res: arb_depth<matchable> = m; for vec::each(*idx_path) |idx| { - res = alt res { + res = match res { leaf(_) => return res,/* end of the line */ seq(new_ms, _) => new_ms[idx] } @@ -219,10 +219,10 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) -> fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>, idx_path: @mut ~[uint]) -> option<matchable> { - alt mmaybe { + match mmaybe { none => return none, some(m) => { - return alt follow(m, idx_path) { + return match follow(m, idx_path) { seq(_, sp) => { cx.span_fatal(sp, ~"syntax matched under ... but not " + @@ -258,10 +258,10 @@ fn free_vars(b: bindings, e: @expr, it: fn(ident)) { 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) { + match elts_to_ell(cx, exprs) { {pre: pre, rep: repeat_me_maybe, post: post} => { let mut res = vec::map(pre, recur); - alt repeat_me_maybe { + match repeat_me_maybe { none => (), some(repeat_me) => { let mut repeat: option<{rep_count: uint, name: ident}> = none; @@ -269,10 +269,10 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], 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 { + match cur_pos { leaf(_) => (), seq(ms, _) => { - alt repeat { + match repeat { none => { repeat = some({rep_count: vec::len(*ms), name: fv}); } @@ -290,7 +290,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], } } }; - alt repeat { + match repeat { none => { cx.span_fatal(repeat_me.span, ~"'...' surrounds an expression without any" + @@ -320,7 +320,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], // substitute, in a position that's required to be an ident 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) { + return match 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 @@ -332,7 +332,7 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], p: path, _fld: ast_fold) -> path { // 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) { + match follow_for_trans(cx, b.find(p.idents[0]), idx_path) { some(match_ident(id)) => { {span: id.span, global: false, idents: ~[id.node], rp: none, types: ~[]} @@ -349,13 +349,13 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span)) -> (ast::expr_, span) { - return alt e { + return match e { 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) { + match follow_for_trans(cx, b.find(p.idents[0]), idx_path) { some(match_ident(id)) => { (expr_path(@{span: id.span, global: false, @@ -378,11 +378,11 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], orig: fn@(ast::ty_, span, ast_fold) -> (ast::ty_, span)) -> (ast::ty_, span) { - return alt t { + return match t { ast::ty_path(pth, _) => { - alt path_to_ident(pth) { + match path_to_ident(pth) { some(id) => { - alt follow_for_trans(cx, b.find(id), idx_path) { + match 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) @@ -404,9 +404,9 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], orig: fn@(blk_, span, ast_fold) -> (blk_, span)) -> (blk_, span) { - return alt block_to_ident(blk) { + return match block_to_ident(blk) { some(id) => { - alt follow_for_trans(cx, b.find(id), idx_path) { + match follow_for_trans(cx, b.find(id), idx_path) { some(match_block(new_blk)) => (new_blk.node, new_blk.span), // possibly allow promotion of ident/path/expr to blocks? @@ -424,12 +424,12 @@ argument. ps accumulates instructions on navigating the tree.*/ 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 m { match_expr(e) => { - alt e.node { + match e.node { 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) { + match elts_to_ell(cx, p_elts) { {pre: pre, rep: some(repeat_me), post: post} => { p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s, b); @@ -459,7 +459,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { _ => { fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> match_result { - return alt m { + return match m { match_expr(e) => { if e == pat { some(leaf(match_exact)) } else { none } } @@ -477,11 +477,11 @@ 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 { + return match m { match_expr(e) => { - alt e.node { + match e.node { expr_path(pth) => { - alt path_to_ident(pth) { + match path_to_ident(pth) { some(id) => match_ident(respan(pth.span, id)), none => match_path(pth) } @@ -495,10 +495,10 @@ fn specialize_match(m: matchable) -> matchable { /* 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) { + match path_to_ident(p) { some(p_id) => { fn select(cx: ext_ctxt, m: matchable) -> match_result { - return alt m { + return match m { match_expr(e) => some(leaf(specialize_match(m))), _ => cx.bug(~"broken traversal in p_t_s_r") } @@ -514,8 +514,8 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { fn block_to_ident(blk: blk_) -> option<ident> { if vec::len(blk.stmts) != 0u { return none; } - return alt blk.expr { - some(expr) => alt expr.node { + return match blk.expr { + some(expr) => match expr.node { expr_path(pth) => path_to_ident(pth), _ => none } @@ -526,8 +526,8 @@ fn block_to_ident(blk: blk_) -> option<ident> { 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 { + return match m { + match_expr(e) => match e.node { expr_mac(mac) => fn_m(mac), _ => none } @@ -537,7 +537,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! { cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported"); } - alt mac.node { + match 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"), @@ -550,9 +550,9 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, b: binders) { fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> match_result { - return alt m { + return match m { match_expr(e) => { - alt e.node { + match e.node { expr_vec(arg_elts, _) => { let mut elts = ~[]; let mut idx = offset; @@ -580,9 +580,9 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector, b: binders) { fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> match_result { - return alt m { + return match m { match_expr(e) => { - alt e.node { + match e.node { expr_vec(arg_elts, _) => { let actual_len = vec::len(arg_elts); if at_least && actual_len >= len || actual_len == len { @@ -604,9 +604,9 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool, let mut idx: uint = 0u; while idx < vec::len(elts) { fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { - return alt m { + return match m { match_expr(e) => { - alt e.node { + match e.node { expr_vec(arg_elts, _) => { some(leaf(match_expr(arg_elts[idx]))) } @@ -629,7 +629,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let mut macro_name: option<@~str> = none; let mut clauses: ~[@clause] = ~[]; for args.each |arg| { - alt arg.node { + match arg.node { expr_vec(elts, mutbl) => { if vec::len(elts) != 2u { cx.span_fatal((*arg).span, @@ -638,12 +638,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, } - alt elts[0u].node { + match elts[0u].node { expr_mac(mac) => { - alt mac.node { + match mac.node { mac_invoc(pth, invoc_arg, body) => { - alt path_to_ident(pth) { - some(id) => alt macro_name { + match path_to_ident(pth) { + some(id) => match macro_name { none => macro_name = some(id), some(other_id) => if id != other_id { cx.span_fatal(pth.span, @@ -654,7 +654,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, none => cx.span_fatal(pth.span, ~"macro name must not be a path") } - let arg = alt invoc_arg { + let arg = match invoc_arg { some(arg) => arg, none => cx.span_fatal(mac.span, ~"macro must have arguments") @@ -689,7 +689,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses); return {ident: - alt macro_name { + match macro_name { some(id) => id, none => cx.span_fatal(sp, ~"macro definition must have " + ~"at least one clause") @@ -699,12 +699,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body, clauses: ~[@clause]) -> @expr { - let arg = alt arg { + let arg = match arg { some(arg) => arg, none => cx.span_fatal(sp, ~"macro must have arguments") }; for clauses.each |c| { - alt use_selectors_to_bind(c.params, arg) { + match use_selectors_to_bind(c.params, arg) { some(bindings) => return transcribe(cx, bindings, c.body), none => again } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index c55f1e67be2..3fdd5239e65 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -70,7 +70,7 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, let file = expr_to_str(cx, args[0], ~"#include_str requires a string"); let res = io::read_whole_file_str(res_rel_file(cx, sp, file)); - alt res { + match res { result::ok(_) => { /* Continue. */ } result::err(e) => { cx.parse_sess().span_diagnostic.handler().fatal(e); @@ -86,7 +86,7 @@ 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)) { + match io::read_whole_file(res_rel_file(cx, sp, file)) { result::ok(src) => { let u8_exprs = vec::map(src, |char: u8| { mk_u8(cx, sp, char) diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index 6a801f33aa6..f1c7ebb7dad 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -31,7 +31,7 @@ enum matcher_pos_up { /* to break a circularity */ } fn is_some(&&mpu: matcher_pos_up) -> bool { - alt mpu { + match mpu { matcher_pos_up(none) => false, _ => true } @@ -48,7 +48,7 @@ type matcher_pos = ~{ }; fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos { - alt mpu { + match mpu { matcher_pos_up(some(mp)) => copy mp, _ => fail } @@ -56,7 +56,7 @@ fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos { fn count_names(ms: &[matcher]) -> uint { vec::foldl(0u, ms, |ct, m| { - ct + alt m.node { + ct + match m.node { match_tok(_) => 0u, match_seq(more_ms, _, _, _, _) => count_names(more_ms), match_nonterminal(_,_,_) => 1u @@ -68,7 +68,7 @@ fn initial_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint) -> matcher_pos { let mut match_idx_hi = 0u; for ms.each() |elt| { - alt elt.node { + match elt.node { match_tok(_) => (), match_seq(_,_,_,_,hi) => { match_idx_hi = hi; // it is monotonic... @@ -113,7 +113,7 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match]) -> hashmap<ident,@named_match> { fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match], ret_val: hashmap<ident, @named_match>) { - alt m { + match m { {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) }; @@ -139,7 +139,7 @@ enum parse_result { fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) -> hashmap<ident, @named_match> { - alt parse(sess, cfg, rdr, ms) { + match parse(sess, cfg, rdr, ms) { success(m) => m, failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str) } @@ -202,7 +202,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) // can we go around again? // the *_t vars are workarounds for the lack of unary move - alt copy ei.sep { + match copy ei.sep { some(t) if idx == len => { // we need a separator if tok == t { //pass the separator let ei_t <- ei; @@ -220,7 +220,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) vec::push(eof_eis, ei); } } else { - alt copy ei.elts[idx].node { + match copy ei.elts[idx].node { /* need to descend into sequence */ match_seq(matchers, sep, zero_ok, match_idx_lo, match_idx_hi) => { @@ -270,7 +270,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) if (bb_eis.len() > 0u && next_eis.len() > 0u) || bb_eis.len() > 1u { let nts = str::connect(vec::map(bb_eis, |ei| { - alt ei.elts[ei.idx].node { + match ei.elts[ei.idx].node { match_nonterminal(bind,name,_) => { fmt!{"%s ('%s')", *name, *bind} } @@ -293,7 +293,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE); let ei = vec::pop(bb_eis); - alt ei.elts[ei.idx].node { + match ei.elts[ei.idx].node { match_nonterminal(_, name, idx) => { ei.matches[idx].push(@matched_nonterminal( parse_nt(rust_parser, *name))); @@ -318,8 +318,8 @@ 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(~[]) { + match name { + ~"item" => match p.parse_item(~[]) { some(i) => token::nt_item(i), none => p.fatal(~"expected an item keyword") } @@ -329,7 +329,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal { ~"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 { + ~"ident" => match 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)) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index b4fc1f5c484..a870928d50b 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -37,11 +37,11 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, arg_reader as reader, argument_gram); // Extract the arguments: - let lhses:~[@named_match] = alt argument_map.get(@~"lhs") { + let lhses:~[@named_match] = match argument_map.get(@~"lhs") { @matched_seq(s, sp) => s, _ => cx.span_bug(sp, ~"wrong-structured lhs") }; - let rhses:~[@named_match] = alt argument_map.get(@~"rhs") { + let rhses:~[@named_match] = match argument_map.get(@~"rhs") { @matched_seq(s, sp) => s, _ => cx.span_bug(sp, ~"wrong-structured rhs") }; @@ -58,13 +58,14 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, let itr = cx.parse_sess().interner; for lhses.eachi() |i, lhs| { // try each arm's matchers - alt lhs { + match lhs { @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) { + match parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) { success(named_matches) => { - let rhs = alt rhses[i] { // okay, what's your transcriber? + let rhs = match rhses[i] { + // okay, what's your transcriber? @matched_nonterminal(nt_tt(@tt)) => tt, _ => cx.span_bug(sp, ~"bad thing in rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index c704fd351ec..693b538ec6d 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -46,7 +46,7 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>, let r = @{sp_diag: sp_diag, interner: itr, mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::none)}, - interpolations: alt interp { /* just a convienience */ + interpolations: match interp { /* just a convienience */ none => std::map::box_str_hash::<@named_match>(), some(x) => x }, @@ -61,7 +61,7 @@ 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 { + sep: f.sep, up: match f.up { tt_frame_up(some(up_frame)) => { tt_frame_up(some(dup_tt_frame(up_frame))) } @@ -82,7 +82,7 @@ pure fn dup_tt_reader(&&r: tt_reader) -> tt_reader { 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 { + match *ad { matched_nonterminal(_) => { // end of the line; duplicate henceforth ad @@ -102,10 +102,10 @@ enum lis { fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis { fn lis_merge(lhs: lis, rhs: lis) -> lis { - alt lhs { + match lhs { lis_unconstrained => rhs, lis_contradiction(_) => lhs, - lis_constraint(l_len, l_id) => alt rhs { + lis_constraint(l_len, l_id) => match rhs { lis_unconstrained => lhs, lis_contradiction(_) => rhs, lis_constraint(r_len, _) if l_len == r_len => lhs, @@ -117,13 +117,13 @@ fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis { } } } - alt t { + match t { 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) { + tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { matched_nonterminal(_) => lis_unconstrained, matched_seq(ads, _) => lis_constraint(ads.len(), name) } @@ -138,7 +138,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { if ! r.cur.dotdotdoted || r.repeat_idx.last() == r.repeat_len.last() - 1 { - alt r.cur.up { + match r.cur.up { tt_frame_up(none) => { r.cur_tok = EOF; return ret_val; @@ -156,7 +156,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } else { /* repeat */ r.cur.idx = 0u; r.repeat_idx[r.repeat_idx.len() - 1u] += 1u; - alt r.cur.sep { + match r.cur.sep { some(tk) => { r.cur_tok = tk; /* repeat same span, I guess */ return ret_val; @@ -167,7 +167,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } 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] { + match r.cur.readme[r.cur.idx] { tt_delim(tts) => { r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false, sep: none, up: tt_frame_up(option::some(r.cur)) }; @@ -179,7 +179,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { return ret_val; } tt_seq(sp, tts, sep, zerok) => { - alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { + match lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { lis_unconstrained => { r.sp_diag.span_fatal( sp, /* blame macro writer */ @@ -212,7 +212,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } // FIXME #2887: think about span stuff here tt_nonterminal(sp, ident) => { - alt *lookup_cur_matched(r, ident) { + match *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. */ |
