diff options
| author | Kevin Atkinson <kevina@cs.utah.edu> | 2012-01-31 23:50:12 -0700 |
|---|---|---|
| committer | Kevin Atkinson <kevina@cs.utah.edu> | 2012-02-03 20:41:48 -0700 |
| commit | 5ea04c65c151708272b92d00c8448156239affb2 (patch) | |
| tree | ea37e5cb51bb04e9c7c20d01d080865ac12a4255 /src/comp/syntax/ext | |
| parent | e76fdeb3a6411f151aafb6a48df26bc6c8f977a5 (diff) | |
| download | rust-5ea04c65c151708272b92d00c8448156239affb2.tar.gz rust-5ea04c65c151708272b92d00c8448156239affb2.zip | |
Add support for recognizing macro body, completely untested.
Diffstat (limited to 'src/comp/syntax/ext')
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 13 | ||||
| -rw-r--r-- | src/comp/syntax/ext/concat_idents.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/env.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ident_to_str.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/log_syntax.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 10 |
7 files changed, 21 insertions, 13 deletions
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index d15d74c8951..824931a759b 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, ast::mac_body) -> @ast::expr; + fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn@(ext_ctxt, span, @ast::expr, ast::mac_body) -> macro_def; + fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> macro_def; enum syntax_extension { normal(syntax_expander), @@ -118,7 +118,14 @@ 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_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")} + } +} // // Local Variables: diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 3a4c59e4960..b451e449b30 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -2,7 +2,7 @@ import option; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { let args: [@ast::expr] = alt arg.node { diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 509f721127c..8cf299c5e67 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -9,7 +9,7 @@ import std::generic_os; import base::*; export expand_syntax_ext; -fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { let args: [@ast::expr] = alt arg.node { diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index b0a346131d6..b2425079ed8 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -13,7 +13,7 @@ import codemap::span; import syntax::ext::build::*; export expand_syntax_ext; -fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr, +fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { let args: [@ast::expr] = alt arg.node { diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index f5e61bbae3e..a5a2dedcbf9 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -2,7 +2,7 @@ import core::{vec, option}; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _body: ast::mac_body) -> @ast::expr { let args: [@ast::expr] = alt arg.node { diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index bfdd336e1ef..4047a1b95d3 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -2,9 +2,8 @@ import base::*; import syntax::ast; import std::io::writer_util; -fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, _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 d35c76838fc..b8722122b69 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -6,7 +6,7 @@ import std::map::{hashmap, new_str_hash}; import option::{some, none}; import driver::session::session; -import base::{ext_ctxt, normal}; +import base::*; import fold::*; import ast_util::respan; @@ -669,7 +669,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, +fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) -> base::macro_def { let args: [@ast::expr] = alt arg.node { @@ -715,8 +715,10 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: @expr, } } clauses += - [@{params: pattern_to_selectors(cx, invoc_arg), + [@{params: pattern_to_selectors + (cx, invoc_arg), body: elts[1u]}]; + // FIXME: check duplicates (or just simplify // the macro arg situation) } @@ -753,7 +755,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, + fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body, clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { |
