From 2772b2e5c7f85e230bcae13c49eb1386afc6cd0e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 6 Aug 2012 17:14:32 -0700 Subject: syntax: Make match arm parsing more restrictive again Require comma separators for all expression types except the plain block --- src/libsyntax/ext/base.rs | 6 +++--- src/libsyntax/ext/fmt.rs | 10 +++++----- src/libsyntax/ext/qquote.rs | 4 ++-- src/libsyntax/ext/simplext.rs | 8 ++++---- src/libsyntax/ext/tt/earley_parser.rs | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 79ef81f78c1..0f163e73c81 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -214,7 +214,7 @@ fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { ast::expr_lit(l) => match l.node { ast::lit_str(s) => return *s, _ => cx.span_fatal(l.span, error) - } + }, _ => cx.span_fatal(expr.span, error) } } @@ -257,7 +257,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _ => { cx.span_fatal(sp, fmt!{"#%s: malformed invocation", name}) } - } + }, none => cx.span_fatal(sp, fmt!{"#%s: missing arguments", name}) } } @@ -302,7 +302,7 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) } _ => fail ~"badly-structured parse result" } - } + }, _ => fail ~"badly-structured parse result" }; diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 19b5fefc1cf..f8966196749 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -84,7 +84,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_hex(c) => match 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" @@ -125,7 +125,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_int(s) => match s { signed => return true, unsigned => return false - } + }, ty_float => return true, _ => return false } @@ -173,7 +173,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, 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(_) => { @@ -224,12 +224,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_int(s) => match s { signed => debug!{"type: signed"}, unsigned => debug!{"type: unsigned"} - } + }, ty_bits => debug!{"type: bits"}, ty_hex(cs) => match 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"} diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs index 491d6104c7b..8d219ec4395 100644 --- a/src/libsyntax/ext/qquote.rs +++ b/src/libsyntax/ext/qquote.rs @@ -312,7 +312,7 @@ fn replace_expr(repls: ~[fragment], ast::expr_mac({node: mac_var(i), _}) => match (repls[i]) { from_expr(r) => (r.node, r.span), _ => fail /* fixme error message */ - } + }, _ => orig(e,s,fld) } } @@ -326,7 +326,7 @@ fn replace_ty(repls: ~[fragment], ast::ty_mac({node: mac_var(i), _}) => match (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 bdb0c663fc7..426fea346b9 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -77,7 +77,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> post: vec::slice(elts, idx + 1u, vec::len(elts))}); } _ => () - } + }, _ => () } idx += 1u; @@ -518,7 +518,7 @@ fn block_to_ident(blk: blk_) -> option { some(expr) => match expr.node { expr_path(pth) => path_to_ident(pth), _ => none - } + }, none => none } } @@ -530,7 +530,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { match_expr(e) => match e.node { expr_mac(mac) => fn_m(mac), _ => none - } + }, _ => cx.bug(~"broken traversal in p_t_s_r") } } @@ -650,7 +650,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, ~"macro name must be " + ~"consistent"); } - } + }, none => cx.span_fatal(pth.span, ~"macro name must not be a path") } diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index f1c7ebb7dad..d84eb3ec488 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -322,7 +322,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal { ~"item" => match 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)), @@ -333,7 +333,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal { 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 -- cgit 1.4.1-3-g733a5