diff --git a/src/soup.ml b/src/soup.ml index bc03577..2f9bc4d 100644 --- a/src/soup.ml +++ b/src/soup.ml @@ -158,25 +158,10 @@ let element node = type 'a stop = {throw : 'b. 'a -> 'b} -exception Stop of int64 - -let generate_id = - let next = ref 0L in - fun () -> - let current = !next in - next := Int64.succ current; - current - -let with_stop f = - let result = ref None in - let id = generate_id () in - let stop = {throw = fun v -> result := Some v; raise_notrace (Stop id)} in - try f stop - with Stop id' when id' = id -> - match !result with - | None -> - failwith "Soup.with_stop: internal error: !result = None" [@coverage off] - | Some v -> v +let with_stop (type a) (f : a stop -> a) : a = + let exception Stop of a in + let stop = {throw = fun v -> raise_notrace (Stop v)} in + try f stop with Stop v -> v let name = function | {values = `Element {name; _}; _} -> String.lowercase_ascii name