package parsexp

  1. Overview
  2. Docs

Source file conv_intf.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
open! Import

module type S = sig
  type 'a res
  type chunk_to_conv
  type parsed_sexp

  val parse_string : string -> (chunk_to_conv -> 'a) -> ('a res, Conv_error.t) result
  val parse_string_exn : string -> (chunk_to_conv -> 'a) -> 'a res

  val conv
    :  parsed_sexp * Positions.t
    -> (chunk_to_conv -> 'a)
    -> ('a res, Of_sexp_error.t) result

  val conv_exn : parsed_sexp * Positions.t -> (chunk_to_conv -> 'a) -> 'a res

  (** Convenience function for merging parsing and conversion errors.

      For instance if you have a [load] function as follow:

      {[
        val load : string -> (Sexp.t list * Positions.t, Parse_error.t) result
      ]}

      then you can create a [load_conv] function as follow:

      {[
        let load_conv : string -> (Sexp.t -> 'a) -> ('a list, Conv_error.t) result
          = fun filename f -> conv_combine (load filename) f
      ]}
  *)
  val conv_combine
    :  (parsed_sexp * Positions.t, Parse_error.t) result
    -> (chunk_to_conv -> 'a)
    -> ('a res, Conv_error.t) result
end

module type Mode = sig
  type parsed_sexp
  type 'a res
  type chunk_to_conv

  val apply_f : parsed_sexp -> f:(chunk_to_conv -> 'r) -> 'r res
  val find : Positions.t -> parsed_sexp -> sub:Sexp.t -> Positions.range option
end

module type Conv = sig
  module type Mode = Mode
  module type S = S

  module Make
      (Mode : Mode)
      (Sexp_parser : Parser.S with type parsed_value = Mode.parsed_sexp)
      (Positions_parser : Parser.S with type parsed_value = Positions.t) :
    S
    with type parsed_sexp := Mode.parsed_sexp
    with type chunk_to_conv := Mode.chunk_to_conv
    with type 'a res := 'a Mode.res
end
OCaml

Innovation. Community. Security.