summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-12-12 17:08:09 -0800
committerGraydon Hoare <graydon@mozilla.com>2012-12-12 17:08:09 -0800
commit9a4c669867765d42bdd13fc09eb9a32b7a667a43 (patch)
tree64a4ba0ae49ece9b0a1b29c112d0a5b21fba7efe /src/libsyntax/ext
parente24ae85025e40aa17915f6c604d89aefbca274bd (diff)
downloadrust-9a4c669867765d42bdd13fc09eb9a32b7a667a43.tar.gz
rust-9a4c669867765d42bdd13fc09eb9a32b7a667a43.zip
syntax: remove remaining #syntaxext machinery. Close #3516.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/base.rs151
-rw-r--r--src/libsyntax/ext/concat_idents.rs35
-rw-r--r--src/libsyntax/ext/env.rs17
-rw-r--r--src/libsyntax/ext/expand.rs35
-rw-r--r--src/libsyntax/ext/fmt.rs11
-rw-r--r--src/libsyntax/ext/ident_to_str.rs20
-rw-r--r--src/libsyntax/ext/source_util.rs76
7 files changed, 124 insertions, 221 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 08f8746c45e..a5ed1f5e101 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -13,11 +13,8 @@ use parse::parser;
 use diagnostic::span_handler;
 use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom};
 use ast_util::dummy_sp;
+use parse::token;
 
-// obsolete old-style #macro code:
-//
-//    syntax_expander, normal, builtin
-//
 // new-style macro! tt code:
 //
 //    syntax_expander_tt, syntax_expander_tt_item, mac_result,
@@ -27,12 +24,6 @@ use ast_util::dummy_sp;
 // is now probably a redundant AST node, can be merged with
 // ast::mac_invoc_tt.
 
-// second argument is the span to blame for general argument problems
-type syntax_expander_ =
-    fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> @ast::expr;
-// second argument is the origin of the macro, if user-defined
-type syntax_expander = {expander: syntax_expander_, span: Option<span>};
-
 type macro_def = {name: ~str, ext: syntax_extension};
 
 type item_decorator =
@@ -56,10 +47,7 @@ enum mac_result {
 
 enum syntax_extension {
 
-    // normal() is obsolete, remove when #old_macros go away.
-    normal(syntax_expander),
-
-    // #[auto_serialize] and such. will probably survive death of #old_macros
+    // #[auto_serialize] and such
     item_decorator(item_decorator),
 
     // Token-tree expanders
@@ -73,8 +61,6 @@ enum syntax_extension {
 // A temporary hard-coded map of methods for expanding syntax extension
 // AST nodes into full ASTs
 fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
-    fn builtin(f: syntax_expander_) -> syntax_extension
-        {normal({expander: f, span: None})}
     fn builtin_normal_tt(f: syntax_expander_tt_) -> syntax_extension {
         normal_tt({expander: f, span: None})
     }
@@ -85,18 +71,19 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
     syntax_expanders.insert(~"macro_rules",
                             builtin_item_tt(
                                 ext::tt::macro_rules::add_new_extension));
-    syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext));
+    syntax_expanders.insert(~"fmt",
+                            builtin_normal_tt(ext::fmt::expand_syntax_ext));
     syntax_expanders.insert(
         ~"auto_serialize",
         item_decorator(ext::auto_serialize::expand_auto_serialize));
     syntax_expanders.insert(
         ~"auto_deserialize",
         item_decorator(ext::auto_serialize::expand_auto_deserialize));
-    syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext));
+    syntax_expanders.insert(~"env",
+                            builtin_normal_tt(ext::env::expand_syntax_ext));
     syntax_expanders.insert(~"concat_idents",
-                            builtin(ext::concat_idents::expand_syntax_ext));
-    syntax_expanders.insert(~"ident_to_str",
-                            builtin(ext::ident_to_str::expand_syntax_ext));
+                            builtin_normal_tt(
+                                ext::concat_idents::expand_syntax_ext));
     syntax_expanders.insert(~"log_syntax",
                             builtin_normal_tt(
                                 ext::log_syntax::expand_syntax_ext));
@@ -122,21 +109,29 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
                             builtin_normal_tt(ext::quote::expand_quote_stmt));
 
     syntax_expanders.insert(~"line",
-                            builtin(ext::source_util::expand_line));
+                            builtin_normal_tt(
+                                ext::source_util::expand_line));
     syntax_expanders.insert(~"col",
-                            builtin(ext::source_util::expand_col));
+                            builtin_normal_tt(
+                                ext::source_util::expand_col));
     syntax_expanders.insert(~"file",
-                            builtin(ext::source_util::expand_file));
+                            builtin_normal_tt(
+                                ext::source_util::expand_file));
     syntax_expanders.insert(~"stringify",
-                            builtin(ext::source_util::expand_stringify));
+                            builtin_normal_tt(
+                                ext::source_util::expand_stringify));
     syntax_expanders.insert(~"include",
-                            builtin(ext::source_util::expand_include));
+                            builtin_normal_tt(
+                                ext::source_util::expand_include));
     syntax_expanders.insert(~"include_str",
-                            builtin(ext::source_util::expand_include_str));
+                            builtin_normal_tt(
+                                ext::source_util::expand_include_str));
     syntax_expanders.insert(~"include_bin",
-                            builtin(ext::source_util::expand_include_bin));
+                            builtin_normal_tt(
+                                ext::source_util::expand_include_bin));
     syntax_expanders.insert(~"module_path",
-                            builtin(ext::source_util::expand_mod));
+                            builtin_normal_tt(
+                                ext::source_util::expand_mod));
     syntax_expanders.insert(~"proto",
                             builtin_item_tt(ext::pipes::expand_proto));
     syntax_expanders.insert(
@@ -292,87 +287,39 @@ fn expr_to_ident(cx: ext_ctxt,
     }
 }
 
-fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-                       min: uint, name: ~str) -> ~[@ast::expr] {
-    return get_mac_args(cx, sp, arg, min, None, name);
+fn check_zero_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree],
+                  name: &str) {
+    if tts.len() != 0 {
+        cx.span_fatal(sp, fmt!("%s takes no arguments", name));
+    }
 }
 
-fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-                min: uint, max: Option<uint>, name: ~str) -> ~[@ast::expr] {
-    match arg {
-      Some(expr) => match expr.node {
-        ast::expr_vec(elts, _) => {
-            let elts_len = vec::len(elts);
-              match max {
-                Some(max) if ! (min <= elts_len && elts_len <= max) => {
-                  cx.span_fatal(sp,
-                                fmt!("%s! takes between %u and %u arguments.",
-                                     name, min, max));
-                }
-                None if ! (min <= elts_len) => {
-                  cx.span_fatal(sp, fmt!("%s! needs at least %u arguments.",
-                                         name, min));
-                }
-                _ => return elts /* we are good */
-              }
-          }
-        _ => {
-            cx.span_fatal(sp, fmt!("%s!: malformed invocation", name))
-        }
-      },
-      None => cx.span_fatal(sp, fmt!("%s!: missing arguments", name))
+fn get_single_str_from_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree],
+                           name: &str) -> ~str {
+    if tts.len() != 1 {
+        cx.span_fatal(sp, fmt!("%s takes 1 argument.", name));
     }
-}
 
-fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
-    -> ast::mac_body_
-{
-    match (args) {
-      Some(body) => body,
-      None => cx.span_fatal(sp, ~"missing macro body")
+    match tts[0] {
+        ast::tt_tok(_, token::LIT_STR(ident)) => cx.str_of(ident),
+        _ =>
+        cx.span_fatal(sp, fmt!("%s requires a string.", name))
     }
 }
 
-// Massage syntactic form of new-style arguments to internal representation
-// of old-style macro args, such that old-style macro can be run and invoked
-// using new syntax. This will be obsolete when #old_macros go away.
-fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
-    -> ast::mac_arg {
-    use ast::{matcher, matcher_, match_tok, match_seq, match_nonterminal};
-    use parse::lexer::{new_tt_reader, reader};
-    use tt::macro_parser::{parse_or_else, matched_seq,
-                              matched_nonterminal};
-
-    // these spans won't matter, anyways
-    fn ms(m: matcher_) -> matcher {
-        {node: m, span: dummy_sp()}
+fn get_exprs_from_tts(cx: ext_ctxt, tts: ~[ast::token_tree])
+    -> ~[@ast::expr] {
+    let p = parse::new_parser_from_tts(cx.parse_sess(),
+                                       cx.cfg(),
+                                       tts);
+    let mut es = ~[];
+    while p.token != token::EOF {
+        if es.len() != 0 {
+            p.eat(token::COMMA);
+        }
+        es.push(p.parse_expr());
     }
-    let arg_nm = cx.parse_sess().interner.gensym(@~"arg");
-
-    let argument_gram = ~[ms(match_seq(~[
-        ms(match_nonterminal(arg_nm, parse::token::special_idents::expr, 0u))
-    ], Some(parse::token::COMMA), true, 0u, 1u))];
-
-    let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
-                                   cx.parse_sess().interner, None, arg);
-    let args =
-        match parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
-                          argument_gram).get(arg_nm) {
-          @matched_seq(s, _) => {
-            do s.map() |lf| {
-                match *lf {
-                  @matched_nonterminal(parse::token::nt_expr(arg)) =>
-                    arg, /* whew! list of exprs, here we come! */
-                  _ => fail ~"badly-structured parse result"
-                }
-            }
-          },
-          _ => fail ~"badly-structured parse result"
-        };
-
-    return Some(@{id: parse::next_node_id(cx.parse_sess()),
-               callee_id: parse::next_node_id(cx.parse_sess()),
-               node: ast::expr_vec(args, ast::m_imm), span: sp});
+    es
 }
 
 //
diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs
index b6fb3a75938..a47b64bea3a 100644
--- a/src/libsyntax/ext/concat_idents.rs
+++ b/src/libsyntax/ext/concat_idents.rs
@@ -10,19 +10,32 @@
 
 use base::*;
 
-fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
-                     _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args_no_max(cx,sp,arg,1u,~"concat_idents");
+fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
     let mut res_str = ~"";
-    for args.each |e| {
-        res_str += *cx.parse_sess().interner.get(
-            expr_to_ident(cx, *e, ~"expected an ident"));
+    for tts.eachi |i, e| {
+        if i & 1 == 1 {
+            match *e {
+                ast::tt_tok(_, token::COMMA) => (),
+                _ => cx.span_fatal(sp, ~"concat_idents! \
+                                         expecting comma.")
+            }
+        } else {
+            match *e {
+                ast::tt_tok(_, token::IDENT(ident,_)) =>
+                res_str += cx.str_of(ident),
+                _ => cx.span_fatal(sp, ~"concat_idents! \
+                                         requires ident args.")
+            }
+        }
     }
     let res = cx.parse_sess().interner.intern(@res_str);
 
-    return @{id: cx.next_id(),
-          callee_id: cx.next_id(),
-          node: ast::expr_path(@{span: sp, global: false, idents: ~[res],
-                                 rp: None, types: ~[]}),
-          span: sp};
+    let e = @{id: cx.next_id(),
+              callee_id: cx.next_id(),
+              node: ast::expr_path(@{span: sp, global: false,
+                                     idents: ~[res],
+                                     rp: None, types: ~[]}),
+              span: sp};
+    mr_expr(e)
 }
diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs
index 51db63c819a..68db1b41781 100644
--- a/src/libsyntax/ext/env.rs
+++ b/src/libsyntax/ext/env.rs
@@ -18,18 +18,19 @@ use base::*;
 use build::mk_uniq_str;
 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 args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"env");
+fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+
+    let var = get_single_str_from_tts(cx, sp, tts, "env!");
 
     // FIXME (#2248): if this was more thorough it would manufacture an
     // Option<str> rather than just an maybe-empty string.
 
-    let var = expr_to_str(cx, args[0], ~"env! requires a string");
-    match os::getenv(var) {
-      option::None => return mk_uniq_str(cx, sp, ~""),
-      option::Some(ref s) => return mk_uniq_str(cx, sp, (*s))
-    }
+    let e = match os::getenv(var) {
+      option::None => mk_uniq_str(cx, sp, ~""),
+      option::Some(ref s) => mk_uniq_str(cx, sp, (*s))
+    };
+    mr_expr(e)
 }
 
 //
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 391edbbb799..a35f351451b 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -62,21 +62,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
 
                     (fully_expanded, s)
                   }
-                  Some(normal({expander: exp, span: exp_sp})) => {
-                    cx.bt_push(ExpandedFrom({call_site: s,
-                                callie: {name: *extname, span: exp_sp}}));
-
-                    //convert the new-style invoc for the old-style macro
-                    let arg = base::tt_args_to_original_flavor(cx, pth.span,
-                                                               (*tts));
-                    let expanded = exp(cx, (*mac).span, arg, None);
-
-                    //keep going, outside-in
-                    let fully_expanded = fld.fold_expr(expanded).node;
-                    cx.bt_pop();
-
-                    (fully_expanded, s)
-                  }
                   _ => {
                     cx.span_fatal(pth.span,
                                   fmt!("'%s' is not a tt-style macro",
@@ -119,8 +104,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
               ast::meta_list(ref n, _) => (*n)
             };
             match exts.find(mname) {
-              None | Some(normal(_))
-                | Some(normal_tt(_)) | Some(item_tt(*)) => items,
+              None | Some(normal_tt(_)) | Some(item_tt(*)) => items,
               Some(item_decorator(dec_fn)) => {
                   cx.bt_push(ExpandedFrom({call_site: attr.span,
                                            callie: {name: copy mname,
@@ -262,23 +246,6 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
             (fully_expanded, sp)
         }
 
-        Some(normal({expander: exp, span: exp_sp})) => {
-            cx.bt_push(ExpandedFrom({call_site: sp,
-                                      callie: {name: *extname,
-                                               span: exp_sp}}));
-            //convert the new-style invoc for the old-style macro
-            let arg = base::tt_args_to_original_flavor(cx, pth.span, tts);
-            let exp_expr = exp(cx, mac.span, arg, None);
-            let expanded = @{node: stmt_expr(exp_expr, cx.next_id()),
-                             span: exp_expr.span};
-
-            //keep going, outside-in
-            let fully_expanded = fld.fold_stmt(expanded).node;
-            cx.bt_pop();
-
-            (fully_expanded, sp)
-        }
-
         _ => {
             cx.span_fatal(pth.span,
                           fmt!("'%s' is not a tt-style macro", *extname))
diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs
index e0d3bd03f42..46003624a76 100644
--- a/src/libsyntax/ext/fmt.rs
+++ b/src/libsyntax/ext/fmt.rs
@@ -21,9 +21,12 @@ use codemap::span;
 use ext::build::*;
 export expand_syntax_ext;
 
-fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-                     _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args_no_max(cx, sp, arg, 1u, ~"fmt");
+fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    let args = get_exprs_from_tts(cx, copy tts);
+    if args.len() == 0 {
+        cx.span_fatal(sp, "fmt! takes at least 1 argument.");
+    }
     let fmt =
         expr_to_str(cx, args[0],
                     ~"first argument to fmt! must be a string literal.");
@@ -37,7 +40,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
         parse_fmt_err_(cx, fmtspan, s)
     };
     let pieces = parse_fmt_string(fmt, parse_fmt_err);
-    return pieces_to_expr(cx, sp, pieces, args);
+    mr_expr(pieces_to_expr(cx, sp, pieces, args))
 }
 
 // FIXME (#2249): A lot of these functions for producing expressions can
diff --git a/src/libsyntax/ext/ident_to_str.rs b/src/libsyntax/ext/ident_to_str.rs
deleted file mode 100644
index ededc1a5f7f..00000000000
--- a/src/libsyntax/ext/ident_to_str.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use base::*;
-use build::mk_uniq_str;
-
-fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
-                     _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"ident_to_str");
-
-    return mk_uniq_str(cx, sp, *cx.parse_sess().interner.get(
-        expr_to_ident(cx, args[0u], ~"expected an ident")));
-}
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index aa97646c054..8d2b9163f15 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -23,63 +23,58 @@ export expand_include_str;
 export expand_include_bin;
 
 /* line!(): expands to the current line number */
-fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-               _body: ast::mac_body) -> @ast::expr {
-    get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"line");
+fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    base::check_zero_tts(cx, sp, tts, "line!");
     let loc = cx.codemap().lookup_char_pos(sp.lo);
-    return mk_uint(cx, sp, loc.line);
+    base::mr_expr(mk_uint(cx, sp, loc.line))
 }
 
 /* col!(): expands to the current column number */
-fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-              _body: ast::mac_body) -> @ast::expr {
-    get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"col");
+fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    base::check_zero_tts(cx, sp, tts, "col!");
     let loc = cx.codemap().lookup_char_pos(sp.lo);
-    return mk_uint(cx, sp, loc.col.to_uint());
+    base::mr_expr(mk_uint(cx, sp, loc.col.to_uint()))
 }
 
 /* file!(): expands to the current filename */
 /* The filemap (`loc.file`) contains a bunch more information we could spit
  * out if we wanted. */
-fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-               _body: ast::mac_body) -> @ast::expr {
-    get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
+fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    base::check_zero_tts(cx, sp, tts, "file!");
     let Loc { file: @FileMap { name: filename, _ }, _ } =
         cx.codemap().lookup_char_pos(sp.lo);
-    return mk_uniq_str(cx, sp, filename);
+    base::mr_expr(mk_uniq_str(cx, sp, filename))
 }
 
-fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-                    _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"stringify");
-    let s = pprust::expr_to_str(args[0], cx.parse_sess().interner);
-    return mk_uniq_str(cx, sp, s);
+fn expand_stringify(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    let s = pprust::tts_to_str(tts, cx.parse_sess().interner);
+    base::mr_expr(mk_uniq_str(cx, sp, s))
 }
 
-fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
-    -> @ast::expr {
-    get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
-    return mk_uniq_str(cx, sp,
-                       str::connect(cx.mod_path().map(
-                           |x| cx.str_of(*x)), ~"::"));
+fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    base::check_zero_tts(cx, sp, tts, "module_path!");
+    base::mr_expr(mk_uniq_str(cx, sp,
+                              str::connect(cx.mod_path().map(
+                                  |x| cx.str_of(*x)), ~"::")))
 }
 
-fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
-                  _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"include");
-    let file = expr_to_str(cx, args[0], ~"include_str! requires a string");
+fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    let file = get_single_str_from_tts(cx, sp, tts, "include!");
     let p = parse::new_sub_parser_from_file(
         cx.parse_sess(), cx.cfg(),
         &res_rel_file(cx, sp, &Path(file)), sp);
-    return p.parse_expr();
+    base::mr_expr(p.parse_expr())
 }
 
-fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
-                      _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_str");
-
-    let file = expr_to_str(cx, args[0], ~"include_str! requires a string");
-
+fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
     let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file)));
     match res {
       result::Ok(_) => { /* Continue. */ }
@@ -88,21 +83,18 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
       }
     }
 
-    return mk_uniq_str(cx, sp, result::unwrap(res));
+    base::mr_expr(mk_uniq_str(cx, sp, result::unwrap(res)))
 }
 
-fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
-                      _body: ast::mac_body) -> @ast::expr {
-    let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_bin");
-
-    let file = expr_to_str(cx, args[0], ~"include_bin! requires a string");
-
+fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
+    -> base::mac_result {
+    let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
     match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
       result::Ok(src) => {
         let u8_exprs = vec::map(src, |char| {
             mk_u8(cx, sp, *char)
         });
-        return mk_base_vec_e(cx, sp, u8_exprs);
+        base::mr_expr(mk_base_vec_e(cx, sp, u8_exprs))
       }
       result::Err(ref e) => {
         cx.parse_sess().span_diagnostic.handler().fatal((*e))