package ocaml-protoc
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Pure OCaml compiler for .proto files
Install
dune-project
Dependency
Authors
Maintainers
Sources
ocaml-protoc-4.0.tbz
sha256=88533848ee8ad662bfb063f34932286405977fa3810515b997119b06f05105e4
sha512=df12c71f7181eafc94cd0fc400edf7f258cdd3740a5badafce097f771b7828fed9a9a9c0a457e7e118848a8b1ddd87fe3134a5bdf88d4adcb0d0e04ba6808c5f
doc/src/ocaml-protoc.compiler-lib/pb_util.ml.html
Source file pb_util.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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169(* The MIT License (MIT) Copyright (c) 2016 Maxime Ransan <maxime.ransan@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *) let rev_split_by_char c s = let rec loop i l = try let i' = String.index_from s i c in let s' = String.sub s i (i' - i) in loop (i' + 1) (if s' = "" then l else s' :: l) with Not_found -> String.sub s i (String.length s - i) :: l in loop 0 [] let string_of_string_list l = Printf.sprintf "[%s]" (String.concat "," l) let string_fold_lefti f e0 s = let len = String.length s in let rec loop acc = function | i when i = len -> acc | i -> loop (f acc i (String.unsafe_get s i)) (i + 1) in loop e0 0 module String = struct include String let starts_with ~prefix s = let len_s = length s and len_pre = length prefix in let rec aux i = if i = len_pre then true else if unsafe_get s i <> unsafe_get prefix i then false else aux (i + 1) in len_s >= len_pre && aux 0 end module Option = struct let default x = function | Some y -> y | None -> x let some v = Some v let min_value x y = match x, y with | None, None | Some _, None | None, Some _ -> invalid_arg "Util.Option.min_value" | Some x, Some y -> some @@ min x y let eq_value x y = match x, y with | None, None | Some _, None | None, Some _ -> invalid_arg "Util.Option.eq_value" | Some x, Some y -> x = y let string_of_option f = function | None -> "None" | Some x -> Printf.sprintf "Some(%s)" (f x) end let indentation_prefix = let h = Hashtbl.create 16 in fun level -> match Hashtbl.find h level with | s -> s | exception Not_found -> let s = String.make (2 * level) ' ' in Hashtbl.add h level s; s let read_file file_name = let ic = open_in file_name in let len = in_channel_length ic in let b = Bytes.create len in let offset = ref 0 in let remaining = ref len in while !remaining > 0 do let i = input ic b !offset !remaining in offset := !offset + i; remaining := if i > 0 then !remaining - i else 0 done; close_in ic; Bytes.sub_string b 0 !offset let protect ~finally f = try let x = f () in finally (); x with e -> finally (); raise e module List = struct let rec pop_last = function | [] -> failwith "Invalid argument [] for pop_last" | _ :: [] -> [] | hd :: tl -> hd :: pop_last tl let rec apply_until f = function | [] -> None | hd :: tl -> (match f hd with | None -> apply_until f tl | x -> x) let rec filter_map f = function | [] -> [] | hd :: tl -> (match f hd with | None -> filter_map f tl | Some x -> x :: filter_map f tl) let find_opt f l = try Some (List.find f l) with Not_found -> None let rec find_map f = function | [] -> None | x :: tl -> (match f x with | Some _ as r -> r | None -> find_map f tl) let rec equal eq l1 l2 = match l1, l2 with | [], [] -> true | [], _ :: _ | _ :: _, [] -> false | a1 :: l1, a2 :: l2 -> eq a1 a2 && equal eq l1 l2 end module Int_map = Map.Make (struct type t = int let compare (x : int) (y : int) = Stdlib.compare x y end) module Str_map = Map.Make (String)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>