-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolver: rework resolvers & parser manager
- Loading branch information
1 parent
e341c26
commit c13ada4
Showing
13 changed files
with
131 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Created by justus on 19.11.23. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <pl/core/resolver.hpp> | ||
|
||
namespace pl::core { | ||
class FileResolver { | ||
public: | ||
|
||
FileResolver() = default; | ||
explicit FileResolver(const std::vector<std::fs::path>& includePaths) : m_includePaths(includePaths) { } | ||
|
||
hlp::Result<api::Source, std::string> resolve(const std::string& path); | ||
inline hlp::Result<api::Source, std::string> operator()(const std::string& path) { | ||
return resolve(path); | ||
} | ||
|
||
void setIncludePaths(const std::vector<std::fs::path>& includePaths) const { | ||
this->m_includePaths = includePaths; | ||
} | ||
|
||
private: | ||
mutable std::vector<std::fs::path> m_includePaths; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <pl/core/resolver.hpp> | ||
|
||
using namespace pl::core; | ||
using namespace pl::api; | ||
using namespace pl::hlp; | ||
|
||
Result<Source *, std::string> Resolver::resolve(const std::string &path) { | ||
using result_t = Result<Source *, std::string>; | ||
// look in cache | ||
auto it = m_cachedSources.find(path); | ||
if (it != m_cachedSources.end()) | ||
return result_t::good(&it->second); | ||
|
||
Result<Source, std::string> result; | ||
|
||
// look for protocol | ||
if(!m_protocolResolvers.empty()){ | ||
auto protocolEnd = path.find("://"); | ||
if (protocolEnd != std::string::npos) { | ||
auto protocol = path.substr(0, protocolEnd); | ||
auto protocolIt = m_protocolResolvers.find(protocol); | ||
if (protocolIt != m_protocolResolvers.end()) { | ||
result = protocolIt->second(path); | ||
} | ||
} | ||
} | ||
|
||
if(!result.is_ok()) { | ||
if (!m_defaultResolver) | ||
return result_t::err("No possible way to resolve path " + path + " and no default resolver set"); | ||
|
||
result = m_defaultResolver(path); | ||
} | ||
|
||
if (result.is_ok()) { | ||
m_cachedSources[path] = result.unwrap(); | ||
return result_t::good(&m_cachedSources[path]); | ||
} | ||
|
||
return result_t::err(result.unwrap_errs()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.