anchor.diff:              cmpl(Dep, rm_ws(Vsn), Repo, HexRegistry, State, fun ec_semver:lt/2);
           <<"==", Vsn/binary>> ->
               {ok, Vsn};
  +        {complex, DepVsns} ->
  +            RVsns = lists:map(fun(DVsn) ->
  +                resolve_version_(Dep, DVsn, Repo, HexRegistry, State)
  +            end, DepVsns),
  +            find_highest_resolved_Version(RVsns);
           Vsn ->
               {ok, Vsn}
       end.
  +
  +find_highest_resolved_Version(Versions) ->
  +    find_highest_resolved_Version(Versions, none).
  +
  +find_highest_resolved_Version([], none) -> none;
  +find_highest_resolved_Version([], HVersion) -> {ok, HVersion};
  +find_highest_resolved_Version([none | Versions], HVersion) ->
  +    find_highest_resolved_Version(Versions, HVersion);
  +find_highest_resolved_Version([{ok, Version} | Versions], HVersion) ->
  +    NHVersion =
  +    case (HVersion =:= none orelse ec_semver:gt(Version, HVersion)) of
  +        true ->
  +            Version;
  +        false ->
  +            HVersion
  +    end,
  +    find_highest_resolved_Version(Versions, NHVersion).
   
   rm_ws(<<" ", R/binary>>) ->
       ec_semver:parse(rm_ws(R));
  
positive.code:     ec_semver:parse(R).
  
  valid_vsn(Vsn) ->
      TVsn = select_complex_version(Vsn),
      %% Regepx from https://github.com/sindresorhus/semver-regex/blob/master/index.js
      SemVerRegExp = "v?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?"
          "(-[0-9a-z-]+(\\.[0-9a-z-]+)*)?(\\+[0-9a-z-]+(\\.[0-9a-z-]+)*)?",
      SupportedVersions = "^" ++ vsn_pre_pattern() ++ SemVerRegExp ++ "$",
      re:run(TVsn, SupportedVersions, [unicode]) =/= nomatch.
  
  vsn_pre_pattern() ->
      "(>=?|<=?|~>|==)?\\s*".
  
  select_complex_version(Vsn) ->
      %% for removing `and` and `or` from dependecy and getting the highest version
      case re:split(Vsn, <<"\\s+or\\s+|\\s+and\\s+">>) of
          [Vsn] ->
              Vsn;
          Vsns ->
              highest_version(Vsns)
      end.
  
  highest_version(Vsns) ->
      {Highest, _} = lists:foldl(
          fun(Vsn, {HVsn, HVsnVal} = Acc) ->
              VsnVal = re:replace(Vsn, vsn_pre_pattern(), "", [{return, binary}]),
              case (HVsn =:= none orelse ec_semver:gt(VsnVal, HVsnVal)) of
                  true ->
                      {Vsn, VsnVal};
                  false ->
                      Acc
              end
          end, {none, none}, Vsns),
      Highest.
  
  highest_matching(Dep, Vsn, Repo, HexRegistry, State) ->
      find_highest_matching_(Dep, Vsn, #{name => Repo}, HexRegistry, State).
  
negative.code:         ,resolve_version/6]).
  
  -ifdef(TEST).
  -export([new_package_table/0, find_highest_matching_/5, cmp_/4, cmpl_/4, valid_vsn/1, is_valid_vsn/1]).
  -endif.
  
  -export_type([package/0]).
  