Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/soup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading