From da74a7f9ca774cd8addcb00a361bb230facc3b31 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 1 Feb 2012 00:20:31 -0700 Subject: Make macro arg optional in syntax, again untested. --- src/comp/syntax/ext/base.rs | 7 +++++++ src/comp/syntax/ext/concat_idents.rs | 1 + src/comp/syntax/ext/env.rs | 1 + src/comp/syntax/ext/fmt.rs | 1 + src/comp/syntax/ext/ident_to_str.rs | 1 + src/comp/syntax/ext/log_syntax.rs | 1 + src/comp/syntax/ext/simplext.rs | 4 +++- 7 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/comp/syntax/ext') diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 824931a759b..415c6cb5d9b 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -118,6 +118,13 @@ fn make_new_lit(cx: ext_ctxt, sp: codemap::span, lit: ast::lit_) -> ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; } +fn get_mac_arg(cx: ext_ctxt, sp: span, arg: ast::mac_arg) -> @ast::expr { + alt (arg) { + some(expr) {expr} + none {cx.span_fatal(sp, "missing macro args")} + } +} + fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) -> ast::mac_body_ { diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index b451e449b30..538c40a9d66 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -4,6 +4,7 @@ import syntax::ast; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { + let arg = get_mac_arg(cx,sp,arg); let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 8cf299c5e67..b9b42028c0f 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -11,6 +11,7 @@ export expand_syntax_ext; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { + let arg = get_mac_arg(cx,sp,arg); let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index b2425079ed8..b7834175d2f 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -15,6 +15,7 @@ export expand_syntax_ext; fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { + let arg = get_mac_arg(cx,sp,arg); let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index a5a2dedcbf9..9245e5aa6d4 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -4,6 +4,7 @@ import syntax::ast; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { + let arg = get_mac_arg(cx,sp,arg); let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index 4047a1b95d3..911cf9ff2eb 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -4,6 +4,7 @@ import std::io::writer_util; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { + let arg = get_mac_arg(cx,sp,arg); cx.print_backtrace(); std::io::stdout().write_line(print::pprust::expr_to_str(arg)); diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index b8722122b69..d8496203e3d 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -671,6 +671,7 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: [@expr], _repeat_after: bool, fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) -> base::macro_def { + let arg = get_mac_arg(cx,sp,arg); let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -716,7 +717,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, } clauses += [@{params: pattern_to_selectors - (cx, invoc_arg), + (cx, get_mac_arg(cx,mac.span,invoc_arg)), body: elts[1u]}]; // FIXME: check duplicates (or just simplify @@ -757,6 +758,7 @@ 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 = get_mac_arg(cx,sp,arg); for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body); } -- cgit 1.4.1-3-g733a5