From e76fdeb3a6411f151aafb6a48df26bc6c8f977a5 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Tue, 31 Jan 2012 20:30:26 -0700 Subject: [PATCH] Change the type for the macro body to also store the span. Note: the body is the part of the macro syntax between the {}. --- src/comp/syntax/ast.rs | 5 ++++- src/comp/syntax/ext/base.rs | 4 ++-- src/comp/syntax/ext/concat_idents.rs | 2 +- src/comp/syntax/ext/env.rs | 2 +- src/comp/syntax/ext/fmt.rs | 2 +- src/comp/syntax/ext/ident_to_str.rs | 2 +- src/comp/syntax/ext/log_syntax.rs | 2 +- src/comp/syntax/ext/simplext.rs | 4 ++-- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index ea8dcbf7f4b9..8ed392d011b7 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -272,8 +272,11 @@ enum blk_sort { type mac = spanned; +type mac_body_ = {str: str, span: span}; +type mac_body = option::t; + enum mac_ { - mac_invoc(@path, @expr, option), + mac_invoc(@path, @expr, mac_body), mac_embed_type(@ty), mac_embed_block(blk), mac_ellipsis, diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index bfe3e36c0bc4..d15d74c89518 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -6,10 +6,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn@(ext_ctxt, span, @ast::expr, option) -> @ast::expr; + fn@(ext_ctxt, span, @ast::expr, ast::mac_body) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn@(ext_ctxt, span, @ast::expr, option) -> macro_def; + fn@(ext_ctxt, span, @ast::expr, ast::mac_body) -> macro_def; enum syntax_extension { normal(syntax_expander), diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 0a9d5b4cf3e4..3a4c59e4960c 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -3,7 +3,7 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option) -> @ast::expr { + _body: ast::mac_body) -> @ast::expr { 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 fe464473e031..509f721127c9 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -10,7 +10,7 @@ import base::*; export expand_syntax_ext; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option) -> @ast::expr { + _body: ast::mac_body) -> @ast::expr { 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 84994c0e5dca..b0a346131d63 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -14,7 +14,7 @@ import syntax::ext::build::*; export expand_syntax_ext; fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr, - _body: option) -> @ast::expr { + _body: ast::mac_body) -> @ast::expr { 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 5fbc05062ee5..f5e61bbae3ed 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -3,7 +3,7 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option) -> @ast::expr { + _body: ast::mac_body) -> @ast::expr { 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 b7be75e349f8..bfdd336e1ef0 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -3,7 +3,7 @@ import syntax::ast; import std::io::writer_util; fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option) -> @ast::expr { + _body: ast::mac_body) -> @ast::expr { 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 3ee7a422d2ea..d35c76838fce 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -670,7 +670,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: @expr, - _body: option) -> base::macro_def { + _body: ast::mac_body) -> base::macro_def { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -754,7 +754,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: @expr, ext: normal(ext)}; fn generic_extension(cx: ext_ctxt, sp: span, arg: @expr, - _body: option, clauses: [@clause]) -> @expr { + _body: ast::mac_body, clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body); }