mirror of
https://github.com/comby-tools/comby.git
synced 2024-10-26 13:19:23 +03:00
Allow substituting fresh IDs in rewrite (#168)
This commit is contained in:
parent
37de5e0c4e
commit
d5d8a5cce4
@ -6,6 +6,15 @@ let debug =
|
||||
Sys.getenv "DEBUG_COMBY"
|
||||
|> Option.is_some
|
||||
|
||||
let substitute_fresh template =
|
||||
let pattern = ":[id()]" in
|
||||
let template_ref = ref template in
|
||||
while Option.is_some (String.substr_index !template_ref ~pattern) do
|
||||
let uuid = Uuid_unix.(Fn.compose Uuid.to_string create ()) in
|
||||
let id = String.suffix uuid 12 in
|
||||
template_ref := String.substr_replace_first !template_ref ~pattern ~with_:id
|
||||
done;
|
||||
!template_ref
|
||||
|
||||
let substitute template env =
|
||||
let substitution_formats =
|
||||
@ -23,6 +32,7 @@ let substitute template env =
|
||||
; ":[?", "]"
|
||||
]
|
||||
in
|
||||
let template = substitute_fresh template in
|
||||
Environment.vars env
|
||||
|> List.fold ~init:(template, []) ~f:(fun (acc, vars) variable ->
|
||||
match Environment.lookup env variable with
|
||||
|
@ -1,5 +1,9 @@
|
||||
open Match
|
||||
|
||||
(** substitute the pattern :[id()] with a fresh hex string based on the last
|
||||
48-bit part of a UUID v3 identifier *)
|
||||
val substitute_fresh : string -> string
|
||||
|
||||
(** substitute returns the result and variables substituted for *)
|
||||
val substitute : string -> Environment.t -> (string * string list)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user