about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-26 17:03:20 -0700
committerKevin Atkinson <kevina@cs.utah.edu>2012-02-03 20:28:11 -0700
commit485e489ba2cb025bb84606396b1cea3023c8c99c (patch)
treeb1aac45bf7543db123777c4605f74cc060fbd270
parent98450d0dade3c9a1b91a3384426cc4e824b82052 (diff)
downloadrust-485e489ba2cb025bb84606396b1cea3023c8c99c.tar.gz
rust-485e489ba2cb025bb84606396b1cea3023c8c99c.zip
Implement basic quasi-quoter. No anti-quotes yet.
-rw-r--r--src/comp/rustc.rc1
-rw-r--r--src/comp/syntax/ext/expand.rs8
-rw-r--r--src/comp/syntax/ext/qquote.rs38
3 files changed, 40 insertions, 7 deletions
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index 40e66037f3a..bfb26382a84 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -74,6 +74,7 @@ mod syntax {
     mod ext {
         mod base;
         mod expand;
+        mod qquote;
         mod build;
 
         mod fmt;
diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs
index 9deceaeccf7..5c81da6f492 100644
--- a/src/comp/syntax/ext/expand.rs
+++ b/src/comp/syntax/ext/expand.rs
@@ -8,6 +8,7 @@ import vec;
 import syntax::ast::{crate, expr_, expr_mac, mac_invoc, mac_qq};
 import syntax::fold::*;
 import syntax::ext::base::*;
+import syntax::ext::qquote::expand_qquote;
 import syntax::parse::parser::parse_expr_from_source_str;
 
 import codemap::span;
@@ -53,13 +54,6 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
         };
 }
 
-fn expand_qquote(cx: ext_ctxt, sp: span, e: @ast::expr) -> ast::expr_ {
-    import syntax::ext::build::*;
-    let str = codemap::span_to_snippet(sp, cx.session().parse_sess.cm);
-    let expr = mk_str(cx, e.span, str);
-    ret expr.node;
-}
-
 // FIXME: this is a terrible kludge to inject some macros into the default
 // compilation environment. When the macro-definition system is substantially
 // more mature, these should move from here, into a compiled part of libcore
diff --git a/src/comp/syntax/ext/qquote.rs b/src/comp/syntax/ext/qquote.rs
new file mode 100644
index 00000000000..e1912ce0087
--- /dev/null
+++ b/src/comp/syntax/ext/qquote.rs
@@ -0,0 +1,38 @@
+import driver::session;
+
+import option::{none, some};
+
+import syntax::ast::{crate, expr_, expr_mac, mac_invoc, mac_qq};
+import syntax::fold::*;
+import syntax::ext::base::*;
+import syntax::ext::build::*;
+import syntax::parse::parser::parse_expr_from_source_str;
+
+import codemap::span;
+
+fn expand_qquote(cx: ext_ctxt, sp: span, _e: @ast::expr) -> ast::expr_ {
+    let str = codemap::span_to_snippet(sp, cx.session().parse_sess.cm);
+    let session_call = bind mk_call_(cx,sp,
+                                     mk_access(cx,sp,["ext_cx"], "session"),
+                                     []);
+    let call = mk_call(cx,sp,
+                       ["syntax", "parse", "parser",
+                        "parse_expr_from_source_str"],
+                       [mk_str(cx,sp, "<anon>"),
+                        mk_unary(cx,sp, ast::box(ast::imm),
+                                 mk_str(cx,sp, str)),
+                        mk_access_(cx,sp,
+                                   mk_access_(cx,sp, session_call(), "opts"),
+                                   "cfg"),
+                        mk_access_(cx,sp, session_call(), "parse_sess")]
+                      );
+    ret call.node;
+}
+
+// Local Variables:
+// mode: rust
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End: