Skip to content

Commit

Permalink
Refactor MatchSpec::parse (#3205)
Browse files Browse the repository at this point in the history
* Add find_not_in_parentheses with multiple parens

* Refactor MatchSpec URL with md5

* Refactor find_not_in_parentheses

* Refactor find_not_in_parentheses for genericity

* Use npos ins find_not_in_parentheses

* Add rfind_not_in_parentheses

* Use rfind_not_in_parentheses in MatchSpec

* Refactor chan ns spec split

* Allocation guard

* Refactor MatchSpec filename handling

* Remove MatchSpec::url

* Refactor MatchSpec::subdirs

* Refactor MatchSpec attribute parsing

* Flexible build and version setting

* Refactor find_matching_parenthesis

* Refactor find_matching_parenthesis

* Simplify parsers

* Add find_matching_parentheses with multiple parenthesese

* Add rfind_matching_parentheses

* Refactor MatchSpec section parsing

* Refacator MatchSpec name parsing

* Simplify version and build parsing
  • Loading branch information
AntoinePrv authored Feb 29, 2024
1 parent 7da4263 commit 9141381
Show file tree
Hide file tree
Showing 8 changed files with 1,523 additions and 472 deletions.
47 changes: 38 additions & 9 deletions libmamba/include/mamba/specs/match_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef MAMBA_SPECS_MATCH_SPEC
#define MAMBA_SPECS_MATCH_SPEC

#include <functional>
#include <optional>
#include <string>
#include <string_view>
Expand All @@ -25,6 +26,21 @@ namespace mamba::specs

using NameSpec = GlobSpec;
using BuildStringSpec = GlobSpec;
using subdir_list = typename UnresolvedChannel::dynamic_platform_set;
using subdir_list_const_ref = std::reference_wrapper<const subdir_list>;

inline static constexpr char url_md5_sep = '#';
inline static constexpr char prefered_list_open = '[';
inline static constexpr char prefered_list_close = ']';
inline static constexpr char alt_list_open = '(';
inline static constexpr char alt_list_close = ')';
inline static constexpr char prefered_quote = '"';
inline static constexpr char alt_quote = '\'';
inline static constexpr char channel_namespace_spec_sep = ':';
inline static constexpr char attribute_sep = ',';
inline static constexpr char attribute_assign = '=';
inline static constexpr auto package_version_sep = std::array{ ' ', '=', '<', '>', '~', '!' };


[[nodiscard]] static auto parse(std::string_view spec) -> MatchSpec;

Expand All @@ -33,6 +49,14 @@ namespace mamba::specs
[[nodiscard]] auto channel() const -> const std::optional<UnresolvedChannel>&;
void set_channel(std::optional<UnresolvedChannel> chan);

[[nodiscard]] auto filename() const -> std::string_view;
void set_filename(std::string val);

[[nodiscard]] auto is_file() const -> bool;

[[nodiscard]] auto subdirs() const -> std::optional<subdir_list_const_ref>;
void set_subdirs(subdir_list val);

[[nodiscard]] auto name_space() const -> const std::string&;
void set_name_space(std::string ns);

Expand Down Expand Up @@ -69,21 +93,19 @@ namespace mamba::specs
[[nodiscard]] auto optional() const -> bool;
void set_optional(bool opt);

[[nodiscard]] auto filename() const -> const std::string&;

[[nodiscard]] auto url() const -> const std::string&;

[[nodiscard]] auto conda_build_form() const -> std::string;
[[nodiscard]] auto str() const -> std::string;

[[nodiscard]] auto is_simple() const -> bool;

[[nodiscard]] auto is_file() const -> bool;

private:

struct ExtraMembers
{
// The filename is stored as part of the channel when it is a full Package URL
std::string filename = {};
// The filename is stored as part of the channel when it is available
subdir_list subdirs = {};
std::string md5 = {};
std::string sha256 = {};
std::string license = {};
Expand All @@ -100,11 +122,18 @@ namespace mamba::specs
std::string m_name_space;
BuildNumberSpec m_build_number;
util::heap_optional<ExtraMembers> m_extra = {}; // unlikely data
// TODO can put inside channel
std::string m_filename;
std::string m_url;

auto extra() -> ExtraMembers&;

[[nodiscard]] auto channel_is_file() const -> bool;
[[nodiscard]] auto channel_filename() const -> std::string_view;
void set_channel_filename(std::string val);

[[nodiscard]] auto extra_filename() const -> std::string_view;
void set_extra_filename(std::string val);

[[nodiscard]] auto extra_subdirs() const -> std::optional<subdir_list_const_ref>;
void set_extra_subdirs(subdir_list val);
};

namespace match_spec_literals
Expand Down
2 changes: 2 additions & 0 deletions libmamba/include/mamba/specs/unresolved_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace mamba::specs

using dynamic_platform_set = util::flat_set<std::string>;

[[nodiscard]] static auto parse_platform_list(std::string_view plats) -> dynamic_platform_set;

[[nodiscard]] static auto parse(std::string_view str) -> expected_parse_t<UnresolvedChannel>;

UnresolvedChannel() = default;
Expand Down
Loading

0 comments on commit 9141381

Please sign in to comment.