package toffee
Source file repetition_count.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 47type t = | Count of int (* The specified tracks should be repeated exactly N times *) | Auto_fill (* Auto-repeating tracks should be generated to fill the container *) | Auto_fit (* Auto-repeating tracks should be generated to fit the container *) let count n = if n <= 0 then invalid_arg "Repetition_count.count: repetition count must be positive" else Count n let auto_fill = Auto_fill let auto_fit = Auto_fit let to_string = function | Count n -> string_of_int n | Auto_fill -> "auto-fill" | Auto_fit -> "auto-fit" let equal a b = match (a, b) with | Count n1, Count n2 -> n1 = n2 | Auto_fill, Auto_fill -> true | Auto_fit, Auto_fit -> true | _ -> false let compare a b = match (a, b) with | Count n1, Count n2 -> Int.compare n1 n2 | Count _, _ -> -1 | _, Count _ -> 1 | Auto_fill, Auto_fill -> 0 | Auto_fill, _ -> -1 | _, Auto_fill -> 1 | Auto_fit, Auto_fit -> 0 let pp fmt t = Format.pp_print_string fmt (to_string t) let is_auto = function Auto_fill | Auto_fit -> true | Count _ -> false let of_string = function | "auto-fit" -> Ok Auto_fit | "auto-fill" -> Ok Auto_fill | s -> ( match int_of_string_opt s with | Some n when n > 0 -> Ok (Count n) | _ -> Error "Invalid repetition count")