| 1 | #ifndef NIX_IRC_RESOLVER_H |
| 2 | #define NIX_IRC_RESOLVER_H |
| 3 | |
| 4 | #include "types.h" |
| 5 | #include <filesystem> |
| 6 | #include <string> |
| 7 | #include <unordered_set> |
| 8 | #include <vector> |
| 9 | |
| 10 | namespace nix_irc { |
| 11 | |
| 12 | struct ImportResult { |
| 13 | bool success; |
| 14 | std::string path; |
| 15 | std::string error; |
| 16 | std::shared_ptr<Node> ast; |
| 17 | }; |
| 18 | |
| 19 | struct ResolverConfig { |
| 20 | std::vector<std::string> search_paths; |
| 21 | bool resolve_imports = true; |
| 22 | }; |
| 23 | |
| 24 | class Resolver { |
| 25 | public: |
| 26 | Resolver(const ResolverConfig& config = {}); |
| 27 | ~Resolver(); |
| 28 | |
| 29 | void add_search_path(const std::string& path); |
| 30 | void set_search_paths(const std::vector<std::string>& paths); |
| 31 | |
| 32 | ImportResult resolve_import(const std::string& path, const std::string& from_file); |
| 33 | ImportResult resolve_import(const Node& import_node, const std::string& from_file); |
| 34 | |
| 35 | std::vector<std::string> get_resolved_files() const; |
| 36 | std::vector<std::pair<std::string, std::string>> get_imports() const; |
| 37 | |
| 38 | private: |
| 39 | struct Impl; |
| 40 | std::unique_ptr<Impl> pImpl; |
| 41 | }; |
| 42 | |
| 43 | bool is_static_import(const Node& node); |
| 44 | std::string normalize_path(const std::string& path); |
| 45 | |
| 46 | } // namespace nix_irc |
| 47 | |
| 48 | #endif |