about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-31 23:50:12 -0700
committerKevin Atkinson <kevina@cs.utah.edu>2012-02-03 20:41:48 -0700
commit5ea04c65c151708272b92d00c8448156239affb2 (patch)
treeea37e5cb51bb04e9c7c20d01d080865ac12a4255 /src/comp/syntax
parente76fdeb3a6411f151aafb6a48df26bc6c8f977a5 (diff)
downloadrust-5ea04c65c151708272b92d00c8448156239affb2.tar.gz
rust-5ea04c65c151708272b92d00c8448156239affb2.zip
Add support for recognizing macro body, completely untested.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs6
-rw-r--r--src/comp/syntax/ext/base.rs13
-rw-r--r--src/comp/syntax/ext/concat_idents.rs2
-rw-r--r--src/comp/syntax/ext/env.rs2
-rw-r--r--src/comp/syntax/ext/fmt.rs2
-rw-r--r--src/comp/syntax/ext/ident_to_str.rs2
-rw-r--r--src/comp/syntax/ext/log_syntax.rs3
-rw-r--r--src/comp/syntax/ext/simplext.rs10
-rw-r--r--src/comp/syntax/parse/parser.rs19
9 files changed, 43 insertions, 16 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 8ed392d011b..235485fe3f5 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -272,11 +272,13 @@ enum blk_sort {
 
 type mac = spanned<mac_>;
 
-type mac_body_ = {str: str, span: span};
+type mac_arg = @expr;
+
+type mac_body_ = {span: span};
 type mac_body = option::t<mac_body_>;
 
 enum mac_ {
-    mac_invoc(@path, @expr, mac_body),
+    mac_invoc(@path, mac_arg, 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 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) {
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index ecbae8a1fc2..ae00c9fbce7 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -993,7 +993,24 @@ fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr {
         };
     let hi = es.span.hi;
     let e = mk_expr(p, es.span.lo, hi, ast::expr_vec(es.node, ast::imm));
-    ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none));
+    let b = none;
+    if p.token == token::LBRACE {
+        p.bump();
+        let lo = p.span.lo;
+        let depth = 1u;
+        while (depth > 0u) {
+            alt (p.token) {
+              token::LBRACE {depth += 1u;}
+              token::RBRACE {depth -= 1u;}
+              token::EOF {p.fatal("unexpected EOF in macro body");}
+              _ {}
+            }
+            p.bump();
+        }
+        let hi = p.last_span.hi;
+        b = some({span: mk_sp(lo,hi)});
+    }
+    ret mk_mac_expr(p, lo, p.span.hi, ast::mac_invoc(pth, e, b));
 }
 
 fn parse_dot_or_call_expr(p: parser) -> pexpr {