2016-12-02 13:54:32 +00:00
|
|
|
(** [Ordered_set_lang.t] is a sexp-based representation for an ordered list of strings,
|
|
|
|
with some set like operations. *)
|
|
|
|
|
|
|
|
open Import
|
|
|
|
|
|
|
|
type t
|
2017-02-25 17:53:39 +00:00
|
|
|
val t : t Sexp.Of_sexp.t
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2018-02-08 10:12:46 +00:00
|
|
|
(** Return the location of the set. [loc standard] returns [None] *)
|
|
|
|
val loc : t -> Loc.t option
|
|
|
|
|
|
|
|
(** Value parsed from elements in the DSL *)
|
|
|
|
module type Value = sig
|
|
|
|
type t
|
2018-03-06 07:12:51 +00:00
|
|
|
type key
|
|
|
|
val key : t -> key
|
2018-02-08 10:12:46 +00:00
|
|
|
end
|
|
|
|
|
2018-03-06 07:12:51 +00:00
|
|
|
module type Key = sig
|
|
|
|
type t
|
|
|
|
val compare : t -> t -> Ordering.t
|
|
|
|
module Map : Map.S with type key = t
|
|
|
|
end
|
|
|
|
|
2018-03-15 06:25:04 +00:00
|
|
|
module type S = sig
|
|
|
|
(** Evaluate an ordered set. [standard] is the interpretation of [:standard]
|
|
|
|
inside the DSL. *)
|
|
|
|
type value
|
|
|
|
type 'a map
|
|
|
|
|
2018-02-08 10:12:46 +00:00
|
|
|
val eval
|
|
|
|
: t
|
2018-03-15 06:25:04 +00:00
|
|
|
-> parse:(loc:Loc.t -> string -> value)
|
|
|
|
-> standard:value list
|
|
|
|
-> value list
|
2018-02-08 10:12:46 +00:00
|
|
|
|
|
|
|
(** Same as [eval] but the result is unordered *)
|
|
|
|
val eval_unordered
|
|
|
|
: t
|
2018-03-15 06:25:04 +00:00
|
|
|
-> parse:(loc:Loc.t -> string -> value)
|
|
|
|
-> standard:value map
|
|
|
|
-> value map
|
2018-02-08 10:12:46 +00:00
|
|
|
end
|
|
|
|
|
2018-03-15 06:25:04 +00:00
|
|
|
module Make(Key : Key)(Value : Value with type key = Key.t)
|
|
|
|
: S with type value = Value.t
|
|
|
|
and type 'a map = 'a Key.Map.t
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
val standard : t
|
|
|
|
val is_standard : t -> bool
|
|
|
|
|
2018-06-20 18:42:53 +00:00
|
|
|
val field : ?default:t -> string -> t Sexp.Of_sexp.fields_parser
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
module Unexpanded : sig
|
|
|
|
type expanded = t
|
|
|
|
type t
|
2018-05-31 06:17:52 +00:00
|
|
|
|
|
|
|
include Sexp.Sexpable with type t := t
|
2016-12-02 13:54:32 +00:00
|
|
|
val standard : t
|
|
|
|
|
2018-06-18 16:58:45 +00:00
|
|
|
val field : ?default:t -> string -> t Sexp.Of_sexp.fields_parser
|
2018-02-27 19:06:12 +00:00
|
|
|
|
2018-05-04 15:49:25 +00:00
|
|
|
val has_special_forms : t -> bool
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
(** List of files needed to expand this set *)
|
2018-06-20 18:42:53 +00:00
|
|
|
val files
|
|
|
|
: t
|
|
|
|
-> f:(String_with_vars.t -> string)
|
|
|
|
-> Sexp.syntax * String.Set.t
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
(** Expand [t] using with the given file contents. [file_contents] is a map from
|
2016-12-23 15:32:23 +00:00
|
|
|
filenames to their parsed contents. Every [(:include fn)] in [t] is replaced by
|
2017-07-05 19:55:17 +00:00
|
|
|
[Map.find files_contents fn]. Every element is converted to a string using [f]. *)
|
2018-02-08 10:12:46 +00:00
|
|
|
val expand
|
|
|
|
: t
|
2018-04-23 05:43:20 +00:00
|
|
|
-> files_contents:Sexp.Ast.t String.Map.t
|
2018-02-08 10:12:46 +00:00
|
|
|
-> f:(String_with_vars.t -> string)
|
|
|
|
-> expanded
|
2018-06-29 23:02:57 +00:00
|
|
|
|
|
|
|
type position = Pos | Neg
|
|
|
|
|
|
|
|
(** Fold a function over all strings in a set. The callback receive
|
|
|
|
whether the string is in position or negative position, i.e. on
|
|
|
|
the left or right of a [\] operator. *)
|
|
|
|
val fold_strings
|
|
|
|
: t
|
|
|
|
-> init:'a
|
|
|
|
-> f:(position -> String_with_vars.t -> 'a -> 'a)
|
|
|
|
-> 'a
|
2016-12-02 13:54:32 +00:00
|
|
|
end with type expanded := t
|
2018-03-15 06:25:04 +00:00
|
|
|
|
2018-04-23 05:43:20 +00:00
|
|
|
module String : S with type value = string and type 'a map = 'a String.Map.t
|