From 171a2977852b926d4aeb8cd2e0189335ccd4e1ce Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 4 Nov 2019 23:19:47 +0900 Subject: [PATCH] Implement sscanf in terms of ksscanf Signed-off-by: Rudi Grinberg --- src/stdune/scanf.ml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/stdune/scanf.ml b/src/stdune/scanf.ml index df8dc40362b6..08485d93f94b 100644 --- a/src/stdune/scanf.ml +++ b/src/stdune/scanf.ml @@ -1,12 +1,14 @@ module Scanf = Dune_caml.Scanf -let try_ f = - match f () with - | exception End_of_file -> Error () +let unescaped x = + match Scanf.unescaped x with | exception Scanf.Scan_failure _ -> Error () - | exception (Failure _) -> Error () | x -> Ok x -let unescaped x = try_ (fun () -> Scanf.unescaped x) - -let sscanf x fmt f = try_ (fun () -> Scanf.sscanf x fmt f) +let sscanf x fmt f = + let module M = struct + exception E + end in + match Scanf.ksscanf x (fun _ _ -> raise_notrace M.E) fmt f with + | exception M.E -> Error () + | x -> Ok x