Add Ordered_set_lang.Unexpanded.fold_strings
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
parent
8a0d01a4d4
commit
b4dd6565b2
|
@ -271,6 +271,26 @@ module Unexpanded = struct
|
|||
in
|
||||
loop t.ast
|
||||
|
||||
type position = Pos | Neg
|
||||
|
||||
let fold_strings t ~init ~f =
|
||||
let rec loop (t : ast) pos acc =
|
||||
let open Ast in
|
||||
match t with
|
||||
| Standard | Include _ -> acc
|
||||
| Element x -> f pos x acc
|
||||
| Union l -> List.fold_left l ~init:acc ~f:(fun acc x -> loop x pos acc)
|
||||
| Diff (l, r) ->
|
||||
let acc = loop l pos acc in
|
||||
let pos =
|
||||
match pos with
|
||||
| Pos -> Neg
|
||||
| Neg -> Pos
|
||||
in
|
||||
loop r pos acc
|
||||
in
|
||||
loop t.ast Pos init
|
||||
|
||||
let expand t ~files_contents ~f =
|
||||
let context = t.context in
|
||||
let rec expand (t : ast) : ast_expanded =
|
||||
|
|
|
@ -76,6 +76,17 @@ module Unexpanded : sig
|
|||
-> files_contents:Sexp.Ast.t String.Map.t
|
||||
-> f:(String_with_vars.t -> string)
|
||||
-> expanded
|
||||
|
||||
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
|
||||
end with type expanded := t
|
||||
|
||||
module String : S with type value = string and type 'a map = 'a String.Map.t
|
||||
|
|
Loading…
Reference in New Issue