package MlFront_Thunk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ThunkSemver64Rep.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(** Representations of semantic versions, without parsing. Use {!ThunkSemver64}
    if you need parsing. *)

type nobuild = {
  nobuild_major : int64;
  nobuild_minor : int64;
  nobuild_patch : int64;
  nobuild_prerelease : string list;
}
(** A semver with 64-bit components but without build metadata. *)

type t = {
  major : int64;
  minor : int64;
  patch : int64;
  prerelease : string list;
  build : string list;
}

let hash : t -> int = Hashtbl.hash

let to_string : t -> string =
  let print_series mark identifiers =
    match identifiers with
    | [] -> ""
    | _ -> mark ^ String.concat "." identifiers
  in
  fun { major; minor; patch; prerelease; build } ->
    Int64.to_string major ^ "." ^ Int64.to_string minor ^ "."
    ^ Int64.to_string patch
    ^ print_series "-" prerelease
    ^ print_series "+" build

let build : t -> string list = fun { build; _ } -> build
let with_build : t -> string list -> t = fun v build -> { v with build }

let to_nobuild : t -> nobuild =
 fun { major; minor; patch; prerelease; _ } ->
  {
    nobuild_major = major;
    nobuild_minor = minor;
    nobuild_patch = patch;
    nobuild_prerelease = prerelease;
  }

let with_dropped_bn_build_metadata version =
  let build' = build version in
  let build' =
    List.filter (fun s -> not (String.starts_with ~prefix:"bn-" s)) build'
  in
  with_build version build'