aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Jesus Gallego Arias2020-03-13 07:21:27 -0400
committerEmilio Jesus Gallego Arias2020-03-25 23:45:57 -0400
commit5c9f318f5f1b6e85b03bba9450ac059377be54fc (patch)
tree3b2b09da33a12feb5c2eede8b35da277caa58438
parentf759aaf9de94a11aa34a31c869829d60243d273d (diff)
[gramlib] Don't expose unsafe interfaces to clients
I'd say this is more of a temporary measure than a long-term plan; IMO we should make the interfaces safe so `Gramlib.Grammar` does provide only one signature.
-rw-r--r--gramlib/grammar.ml20
-rw-r--r--gramlib/grammar.mli25
2 files changed, 30 insertions, 15 deletions
diff --git a/gramlib/grammar.ml b/gramlib/grammar.ml
index 41669b77c9..d6951fff6d 100644
--- a/gramlib/grammar.ml
+++ b/gramlib/grammar.ml
@@ -77,10 +77,6 @@ module type S = sig
val make : ('a, _, 'f, Loc.t -> 'a) Rule.t -> 'f -> 'a t
end
- module Unsafe : sig
- val clear_entry : 'a Entry.t -> unit
- end
-
type 'a single_extend_statement =
string option * Gramext.g_assoc option * 'a Production.t list
@@ -89,9 +85,6 @@ module type S = sig
; data : 'a single_extend_statement list
}
- val safe_extend : 'a Entry.t -> 'a extend_statement -> unit
- val safe_delete_rule : 'a Entry.t -> 'a Production.t -> unit
-
val generalize_symbol : ('a, 'tr, 'c) Symbol.t -> ('a, norec, 'c) Symbol.t option
val mk_rule : 'a pattern list -> string Rules.t
@@ -101,6 +94,19 @@ module type S = sig
end
+module type ExtS = sig
+
+ include S
+
+ val safe_extend : 'a Entry.t -> 'a extend_statement -> unit
+ val safe_delete_rule : 'a Entry.t -> 'a Production.t -> unit
+
+ module Unsafe : sig
+ val clear_entry : 'a Entry.t -> unit
+ end
+
+end
+
(* Implementation *)
module GMake (L : Plexing.S) = struct
diff --git a/gramlib/grammar.mli b/gramlib/grammar.mli
index 6f998f7b80..33006f6f65 100644
--- a/gramlib/grammar.mli
+++ b/gramlib/grammar.mli
@@ -87,10 +87,6 @@ module type S = sig
val make : ('a, _, 'f, Loc.t -> 'a) Rule.t -> 'f -> 'a t
end
- module Unsafe : sig
- val clear_entry : 'a Entry.t -> unit
- end
-
type 'a single_extend_statement =
string option * Gramext.g_assoc option * 'a Production.t list
@@ -99,16 +95,29 @@ module type S = sig
; data : 'a single_extend_statement list
}
- val safe_extend : 'a Entry.t -> 'a extend_statement -> unit
- val safe_delete_rule : 'a Entry.t -> 'a Production.t -> unit
-
val generalize_symbol : ('a, 'tr, 'c) Symbol.t -> ('a, norec, 'c) Symbol.t option
val mk_rule : 'a pattern list -> string Rules.t
(* Used in custom entries, should tweak? *)
val level_of_nonterm : ('a, norec, 'c) Symbol.t -> string option
+
+end
+
+(* Interface private to clients *)
+module type ExtS = sig
+
+ include S
+
+ val safe_extend : 'a Entry.t -> 'a extend_statement -> unit
+ val safe_delete_rule : 'a Entry.t -> 'a Production.t -> unit
+
+ module Unsafe : sig
+ val clear_entry : 'a Entry.t -> unit
+ end
+
end
+
(** Signature type of the functor [Grammar.GMake]. The types and
functions are almost the same than in generic interface, but:
- Grammars are not values. Functions holding a grammar as parameter
@@ -119,4 +128,4 @@ end
type (instead of (string * string)); the module parameter
must specify a way to show them as (string * string) *)
-module GMake (L : Plexing.S) : S with type te = L.te and type 'c pattern = 'c L.pattern
+module GMake (L : Plexing.S) : ExtS with type te = L.te and type 'c pattern = 'c L.pattern