Source file prefix.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
module Stable = struct
  open! Core.Core_stable

  module V1 = struct
    type t =
      | Hole
      | In_list of Sexp.V1.t list * t
    [@@deriving bin_io, compare, sexp]

    let%expect_test _ =
      print_endline [%bin_digest: t];
      [%expect {| 74309a8fba149c43b1e1c0a1310b5723 |}]
    ;;

    include Comparator.V1.Make (struct
        type nonrec t = t [@@deriving compare, sexp_of]
      end)
  end

  module Model = V1
end

open! Core
open! Import

include (
  Stable.Model :
    Comparator.S
    with type t = Stable.Model.t
    with type comparator_witness = Stable.Model.comparator_witness)

type t = Stable.Model.t =
  | Hole
  | In_list of Sexp.t list * t
[@@deriving compare, sexp_of]

let of_sexp_prefix (_, in_sexp) =
  let rec of_in_sexp : Parsexp_prefix.Sexp_prefix.in_sexp -> _ = function
    | Hole atom_prefix -> Hole, atom_prefix
    | In_list (sexps, in_sexp) ->
      let t, atom_prefix = of_in_sexp in_sexp in
      In_list (sexps, t), atom_prefix
  in
  of_in_sexp in_sexp
;;

let of_substring s ~pos ~len =
  Parsexp_prefix.Sexp_prefix.of_substring s ~pos ~len |> Option.map ~f:of_sexp_prefix
;;

module Unstable = Stable.Model