package lrgrep

  1. Overview
  2. Docs
Detailed error messages for Menhir-generated parsers

Install

dune-project
 Dependency

Authors

Maintainers

Sources

lrgrep-0.9.tbz
sha256=e53de12e4c5cbe6bca00643593266b4f9fa2e3f6a138195eeff7a4329f5c1c75
sha512=7fd7c4d11506fea7cc11c9bbf5aea9142d905643553c0c90e1bb16b794106b0c14a266acf89ae91b6929008dc0ba6515f788642873e2e4ba6c3d49bd45d25127

doc/src/fix/Tabulate.ml.html

Source file Tabulate.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
(******************************************************************************)
(*                                                                            *)
(*                                    Fix                                     *)
(*                                                                            *)
(*                       François Pottier, Inria Paris                        *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU Library General Public License version 2, with a         *)
(*  special exception on linking, as described in the file LICENSE.           *)
(*                                                                            *)
(******************************************************************************)

open Sigs

module Make
  (F : FINITE_TYPE)
  (M : MINIMAL_IMPERATIVE_MAPS with type key = F.t)
= struct

  type key = M.key

  let tabulate (f : key -> 'a) : key -> 'a =
    let table = M.create() in
    F.foreach (fun x -> M.add x (f x) table);
    fun x ->
      try
        M.find x table
      with Not_found ->
        (* This cannot happen if [foreach] is exhaustive. *)
        let msg = Printf.sprintf "\n  Fix.Tabulate says: \
          please check that your \"foreach\" function is \
          exhaustive.\n  %s\n" __LOC__ in
        raise (Invalid_argument msg)

end

module ForOrderedType
  (F : FINITE_TYPE)
  (T : OrderedType with type t = F.t)
=
  Make(F)(Glue.PersistentMapsToImperativeMaps(Map.Make(T)))

module ForHashedType
  (F : FINITE_TYPE)
  (T : HashedType with type t = F.t)
=
  Make(F)(Glue.HashTablesAsImperativeMaps(T))

module ForType (F : FINITE_TYPE) =
  ForHashedType(F)(Glue.TrivialHashedType(F))

module ForIntSegment (K : sig val n: int end) = struct

  type key = int

  let tabulate (f : key -> 'a) : key -> 'a =
    let table = Array.init K.n f in
    fun x ->
      table.(x)

end