blob: f552ffd4ebb079b2742737f996c16ec1ee8cad7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* MRustC - Rust Compiler
* - By John Hodge (Mutabah/thePowersGang)
*
* expand/stringify.cpp
* - stringify! macro
*/
#include <synext.hpp>
#include "../parse/common.hpp"
#include "../parse/ttstream.hpp"
class CExpander:
public ExpandProcMacro
{
::std::unique_ptr<TokenStream> expand(const 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(sp, tt);
while( GET_TOK(tok, lex) != TOK_EOF )
{
if(!rv.empty())
rv += " ";
DEBUG(" += " << tok);
rv += tok.to_str();
}
// TODO: Strip out any `{...}` sequences that aren't from nested
// strings.
return box$( TTStreamO(sp, TokenTree(Token(TOK_STRING, mv$(rv)))) );
}
};
STATIC_MACRO("stringify", CExpander);
|