upstream: https://github.com/stedolan/crowbar
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update dune-project with external dependencies

+24 -23
+1 -1
examples/pprint/dune
··· 1 1 (test 2 2 (name test_pprint) 3 - (libraries crowbar pprint)) 3 + (libraries crowbar pprint re))
+5 -9
examples/pprint/test_pprint.ml
··· 23 23 let w = 40 in 24 24 ToBuffer.pretty 1.0 w b d; 25 25 let text = Bytes.to_string (Buffer.to_bytes b) in 26 - let ws = Str.regexp "[ \t\n\r]*" in 27 - (* Printf.printf "doc2{\n%s\n}%!" text; *) 28 - let del_ws = Str.global_replace ws "" in 29 - (* Printf.printf "[%s] = [%s]\n%!" (del_ws s) (del_ws text);*) 30 - Str.split (Str.regexp "\n") text |> List.iter (fun s -> 31 - let mspace = Str.regexp "[^ ] " in 26 + let ws = Re.(compile (rep (set " \t\n\r"))) in 27 + let del_ws s = Re.replace_string ws ~by:"" s in 28 + let mspace = Re.(compile (seq [compl [char ' ']; char ' '])) in 29 + String.split_on_char '\n' text |> List.iter (fun s -> 32 30 if String.length s > w then 33 - match Str.search_forward mspace s w with 34 - | _ -> assert false 35 - | exception Not_found -> ()); 31 + if Re.execp ~pos:w mspace s then assert false); 36 32 check_eq (del_ws s) (del_ws text) 37 33 38 34 let () =
+1 -1
examples/serializer/dune
··· 1 1 (test 2 2 (name test_serializer) 3 - (libraries crowbar)) 3 + (libraries crowbar fmt))
+17 -12
examples/serializer/serializer.ml
··· 10 10 | List : 'a ty -> 'a list ty 11 11 12 12 let rec pp_ty : type a . _ -> a ty -> unit = fun ppf -> 13 - let printf fmt = Format.fprintf ppf fmt in 14 13 function 15 - | Int -> printf "Int" 16 - | Bool -> printf "Bool" 17 - | Prod(ta, tb) -> printf "Prod(%a,%a)" pp_ty ta pp_ty tb 18 - | List t -> printf "List(%a)" pp_ty t 14 + | Int -> Fmt.pf ppf "Int" 15 + | Bool -> Fmt.pf ppf "Bool" 16 + | Prod(ta, tb) -> Fmt.pf ppf "Prod(%a,%a)" pp_ty ta pp_ty tb 17 + | List t -> Fmt.pf ppf "List(%a)" pp_ty t 19 18 20 19 let rec serialize : type a . a ty -> a -> data = function 21 20 | Int -> fun n -> Datum (string_of_int n) ··· 25 24 | List t -> fun vs -> 26 25 Block("list", List.map (serialize t) vs) 27 26 28 - let rec deserialize : type a . a ty -> data -> a = function[@warning "-8"] 29 - | Int -> fun (Datum s) -> int_of_string s 30 - | Bool -> fun (Datum s) -> bool_of_string s 31 - | Prod (ta, tb) -> fun (Block("pair", [sa; sb])) -> 32 - (deserialize ta sa, deserialize tb sb) 33 - | List t -> fun (Block("list", ss)) -> 34 - List.map (deserialize t) ss 27 + let rec deserialize : type a . a ty -> data -> a = function 28 + | Int -> (function 29 + | Datum s -> int_of_string s 30 + | Block _ -> failwith "expected Datum for Int") 31 + | Bool -> (function 32 + | Datum s -> bool_of_string s 33 + | Block _ -> failwith "expected Datum for Bool") 34 + | Prod (ta, tb) -> (function 35 + | Block ("pair", [sa; sb]) -> (deserialize ta sa, deserialize tb sb) 36 + | _ -> failwith "expected Block(pair, [_;_]) for Prod") 37 + | List t -> (function 38 + | Block ("list", ss) -> List.map (deserialize t) ss 39 + | _ -> failwith "expected Block(list, _) for List")