summaryrefslogtreecommitdiff
path: root/src/expand/stringify.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-03-11 23:10:54 +0800
committerJohn Hodge <tpg@mutabah.net>2016-03-11 23:10:54 +0800
commit990102479e927dd175b2e3ae7aa4c5c1a977d5d1 (patch)
treee587bdc3c218f784b42e1f20ceaae13575ec8ba2 /src/expand/stringify.cpp
parent76a037ed785148fb271135b5c17c06fd5d036f94 (diff)
downloadmrust-990102479e927dd175b2e3ae7aa4c5c1a977d5d1.tar.gz
Expand - Macros expansion improved
Diffstat (limited to 'src/expand/stringify.cpp')
-rw-r--r--src/expand/stringify.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/expand/stringify.cpp b/src/expand/stringify.cpp
new file mode 100644
index 00000000..e4abb99b
--- /dev/null
+++ b/src/expand/stringify.cpp
@@ -0,0 +1,28 @@
+/*
+ */
+#include <synext.hpp>
+#include "../parse/common.hpp"
+
+class CExpander:
+ public ExpandProcMacro
+{
+ bool expand_early() const override { return true; }
+
+ ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ {
+ Token tok;
+ ::std::string rv;
+
+ auto lex = TTStream(tt);
+ while( GET_TOK(tok, lex) != TOK_EOF )
+ {
+ rv += tok.to_str();
+ rv += " ";
+ }
+
+ return box$( TTStreamO(TokenTree(Token(TOK_STRING, mv$(rv)))) );
+ }
+};
+
+STATIC_MACRO("stringify", CExpander);
+