diff options
author | John Hodge <tpg@mutabah.net> | 2017-08-22 21:21:16 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-08-22 21:21:16 +0800 |
commit | ae2c2e15bea28bd03efd70060fcb4c49e43477f6 (patch) | |
tree | 0c628db764901a93477eae00eac24609b0fbddcd | |
parent | 1fbd12d2954f22b96f8da0ae9bc3e0b091d9a838 (diff) | |
download | mrust-ae2c2e15bea28bd03efd70060fcb4c49e43477f6.tar.gz |
Expand - Handle windows paths in `include!`
-rw-r--r-- | src/expand/include.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/expand/include.cpp b/src/expand/include.cpp index a6eb9fe1..22b7d1a9 100644 --- a/src/expand/include.cpp +++ b/src/expand/include.cpp @@ -30,18 +30,19 @@ namespace { ::std::string get_path_relative_to(const ::std::string& base_path, ::std::string path) { - if( path[0] == '/' ) { + DEBUG(base_path << ", " << path); + if( path[0] == '/' || path[0] == '\\' ) { return path; } else if( base_path.size() == 0 ) { return path; } - else if( base_path[base_path.size()-1] == '/' ) { + else if( base_path.back() == '/' || base_path.back() == '\\' ) { return base_path + path; } else { - auto slash = base_path.find_last_of('/'); + auto slash = ::std::min( base_path.find_last_of('/'), base_path.find_last_of('\\') ); if( slash == ::std::string::npos ) { return path; @@ -75,7 +76,13 @@ class CIncludeExpander: ::std::string file_path = get_path_relative_to(mod.m_file_info.path, mv$(path)); - return box$( Lexer(file_path) ); + try { + return box$( Lexer(file_path) ); + } + catch(::std::runtime_error& e) + { + ERROR(sp, E0000, e.what()); + } } }; |