From b8484cada9ac1fadf9a1eaebf87bf035262a3276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Gilbert?= Date: Wed, 25 Oct 2023 13:46:45 +0200 Subject: [PATCH] Fix support for ocaml < 4.13 (avoid String.for_all) --- src/tac2compile.ml | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/tac2compile.ml b/src/tac2compile.ml index 3f4fff2..0d4fe37 100644 --- a/src/tac2compile.ml +++ b/src/tac2compile.ml @@ -139,19 +139,16 @@ let ensure_valid_ocaml_id id = let s = Id.to_string id in let ok_start = match s.[0] with '_'|'a'..'z' -> true | _ -> false in let ok_rest = function '_'|'\''|'a'..'z'|'A'..'Z'|'0'..'9' -> true | _ -> false in - if ok_start && String.for_all ok_rest s - then id - else - let s = Bytes.of_string s in - Bytes.iteri (fun i c -> - let ok = if Int.equal i 0 then ok_start else ok_rest c in - if not ok then match c with - | 'A'..'Z' -> (* special case for the first character *) - Bytes.set s i (Char.lowercase_ascii c) - | _ -> Bytes.set s i 'x') - s; - let s = Bytes.unsafe_to_string s in - Id.of_string s + let s = Bytes.of_string s in + Bytes.iteri (fun i c -> + let ok = if Int.equal i 0 then ok_start else ok_rest c in + if not ok then match c with + | 'A'..'Z' -> (* special case for the first character *) + Bytes.set s i (Char.lowercase_ascii c) + | _ -> Bytes.set s i 'x') + s; + let s = Bytes.unsafe_to_string s in + Id.of_string s let push_user_id na info env = let na' = match Id.Map.find_opt na env.user_bindings with