123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687includeThunkSemver64Rep(* ------------- begin [semver] ocaml package ------------------- *)(* Almost verbatim from the OCaml [semver] package which uses Angstrom. *)(* Copyright (c) 2012 Tikhon Jelvis. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)openstruct(** Prerelease precedence rules:
* Identifiers consisting of only digits are compared numerically and
identifiers with letters or hyphens are compared lexically in ASCII sort
order.
* Numeric identifiers always have lower precedence than non-numeric
identifiers.
* A larger set of pre-release fields has a higher precedence than a
smaller set, if all of the preceding identifiers are equal.
<https://semver.org/#spec-item-11> *)letcompare_identifiersiaib=match(ThunkParsers.SemverParsers.NatPL.parse`DirectDecodeia,ThunkParsers.SemverParsers.NatPL.parse`DirectDecodeib)with|Okna,Oknb->comparenanb|Ok_,_->-1|_,Ok_->1|_->compareiaibletreccompare_prereleaseis_firstpraprb=match(pra,prb)with|[],[]->0|[],_->ifis_firstthen1else-1|_,[]->ifis_firstthen-1else1|ia::ta,ib::tb->ifcompareiaib!=0thencompare_identifiersiaibelsecompare_prereleasefalsetatbletmk_versionmajorminorpatchprereleasebuild={major;minor;patch;prerelease;build}letisOk=functionOk_->true|Error_->falseendletfrom_partsmajorminorpatchprereleasebuild=letcheck_prerelease_items=ThunkParsers.SemverParsers.PrereleaseIdentifierPL.parse`DirectDecodes|>isOkinletcheck_build_items=ThunkParsers.SemverParsers.BaseIdentifierPL.parse`DirectDecodes|>isOkinifmajor>=0L&&minor>=0L&&patch>=0L&&List.for_allcheck_prerelease_itemprerelease&&List.for_allcheck_build_itembuildthenSome(mk_versionmajorminorpatchprereleasebuild)elseNoneletcompareab=ifInt64.comparea.majorb.major!=0thenInt64.comparea.majorb.majorelseifInt64.comparea.minorb.minor!=0thenInt64.comparea.minorb.minorelseifInt64.comparea.patchb.patch!=0thenInt64.comparea.patchb.patchelsecompare_prereleasetruea.prereleaseb.prerelease(* ------------- end [semver] ocaml package ------------------- *)letcompare_nobuildab=ifInt64.comparea.nobuild_majorb.nobuild_major!=0thenInt64.comparea.nobuild_majorb.nobuild_majorelseifInt64.comparea.nobuild_minorb.nobuild_minor!=0thenInt64.comparea.nobuild_minorb.nobuild_minorelseifInt64.comparea.nobuild_patchb.nobuild_patch!=0thenInt64.comparea.nobuild_patchb.nobuild_patchelsecompare_prereleasetruea.nobuild_prereleaseb.nobuild_prerelease