Skip to content

Commit

Permalink
Merge pull request #555 from ocaml/push-rvrmzpsonvoq
Browse files Browse the repository at this point in the history
Fix handling in Re.{Emacs,Str}
  • Loading branch information
rgrinberg authored Oct 26, 2024
2 parents 74b72bb + cfbfbe7 commit 0cd909b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/emacs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ module Re = Core
exception Parse_error
exception Not_supported

let by_code f c c' =
let c = Char.code c in
let c' = Char.code c' in
Char.chr (f c c')
;;

let parse s =
let buf = Parse_buffer.create s in
let accept = Parse_buffer.accept buf in
Expand Down Expand Up @@ -105,6 +111,7 @@ let parse s =
then Re.char c :: Re.char '-' :: s
else (
let c' = char () in
let c' = by_code Int.max c c' in
bracket (Re.rg c c' :: s))
else bracket (Re.char c :: s))
and char () =
Expand Down
5 changes: 4 additions & 1 deletion lib_test/str/test_str.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ let _ =
(* Character set *)
expect_pass "rg" (fun () ->
eq_match "[0-9]+" "0123456789";
eq_match "[0-9]+" "a");
eq_match "[0-9]+" "a";
eq_match "[9-0]+" "2";
eq_match "[5-5]" "5";
eq_match "[5-4]" "1");
expect_pass "compl" (fun () ->
eq_match "[^0-9a-z]+" "A:Z+";
eq_match "[^0-9a-z]+" "0";
Expand Down

0 comments on commit 0cd909b

Please sign in to comment.