Skip to content

Commit

Permalink
Fix support for ocaml < 4.13 (avoid String.for_all) (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer authored Oct 25, 2023
2 parents 3994b4b + b8484ca commit 76559d6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/tac2compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76559d6

Please sign in to comment.