summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-15 10:48:21 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-15 10:48:21 +0800
commita67b21cc097dc4ab7cd2a17646ccbd8e8dcb7c2f (patch)
tree3a1cb48a5cfb1ab1dd77591d6a0e3163ce38d58b
parentd523aaf365639c24c7082c1d7903043782e68a1c (diff)
downloadmrust-a67b21cc097dc4ab7cd2a17646ccbd8e8dcb7c2f.tar.gz
Expand include! - Expand argument string
-rw-r--r--src/expand/include.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/expand/include.cpp b/src/expand/include.cpp
index 6b1a5508..c41cc03b 100644
--- a/src/expand/include.cpp
+++ b/src/expand/include.cpp
@@ -6,6 +6,7 @@
* - include!/include_str!/include_bytes! support
*/
#include <synext_macro.hpp>
+#include <synext.hpp> // for Expand_BareExpr
#include <parse/common.hpp>
#include <parse/parseerror.hpp> // for GET_CHECK_TOK
#include <parse/ttstream.hpp>
@@ -13,6 +14,20 @@
#include <ast/expr.hpp>
namespace {
+
+ ::std::string get_string(const Span& sp, TokenStream& lex, const ::AST::Crate& crate, AST::Module& mod)
+ {
+ auto n = Parse_ExprVal(lex);
+ ASSERT_BUG(sp, n, "No expression returned");
+ Expand_BareExpr(crate, mod, n);
+
+ auto* string_np = dynamic_cast<AST::ExprNode_String*>(&*n);
+ if( !string_np ) {
+ ERROR(sp, E0000, "include! requires a string literal - got " << *n);
+ }
+ return mv$( string_np->m_value );
+ }
+
::std::string get_path_relative_to(const ::std::string& base_path, ::std::string path)
{
if( base_path.size() == 0 ) {
@@ -52,9 +67,7 @@ class CIncludeExpander:
Token tok;
auto lex = TTStream(tt);
- // TODO: Parse+expand
- GET_CHECK_TOK(tok, lex, TOK_STRING);
- auto path = mv$(tok.str());
+ auto path = get_string(sp, lex, crate, mod);
GET_CHECK_TOK(tok, lex, TOK_EOF);
::std::string file_path = get_path_relative_to(mod.m_file_info.path, mv$(path));