summaryrefslogtreecommitdiff
path: root/src/expand/stringify.cpp
diff options
context:
space:
mode:
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);
+