Skip to content

Commit a3843b2

Browse files
committed
add atd wrapper for hash tables
1 parent c656828 commit a3843b2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/common.atd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
type 'v map_as_object =
22
(string * 'v) list <json repr="object">
33
wrap <ocaml module="Common.StringMap" t="'v Common.StringMap.t">
4+
5+
type 'v table_as_object =
6+
(string * 'v) list <json repr="object">
7+
wrap <ocaml module="Common.Stringtbl" t="'v Common.Stringtbl.t">

lib/common.ml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
open Base
2-
open Devkit
32

43
module StringMap = struct
54
type 'a t = 'a Map.M(String).t
@@ -15,6 +14,22 @@ module StringMap = struct
1514
let unwrap = to_list
1615
end
1716

17+
module Stringtbl = struct
18+
include Hashtbl
19+
20+
type 'a t = 'a Hashtbl.M(String).t
21+
22+
let empty () = Hashtbl.create (module String)
23+
24+
let to_list (l : 'a t) : (string * 'a) list = Hashtbl.to_alist l
25+
26+
let of_list (m : (string * 'a) list) : 'a t = Hashtbl.of_alist_exn (module String) m
27+
28+
let wrap = of_list
29+
30+
let unwrap = to_list
31+
end
32+
1833
module Re2 = struct
1934
include Re2
2035

@@ -23,6 +38,8 @@ module Re2 = struct
2338
let unwrap = Re2.to_string
2439
end
2540

41+
open Devkit
42+
2643
let fmt_error fmt = Printf.ksprintf (fun s -> Error s) fmt
2744

2845
let first_line s =

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(library
22
(name lib)
33
(libraries atdgen atdgen-runtime base base64 base.caml biniou cstruct curl curl.lwt
4-
devkit devkit.core extlib hex lwt lwt.unix nocrypto omd re2 stdio uri
4+
devkit devkit.core extlib hex lwt lwt.unix nocrypto omd re2 sexplib0 stdio uri
55
yojson)
66
(preprocess
77
(pps lwt_ppx)))

0 commit comments

Comments
 (0)