Skip to content

Commit 0cd909b

Browse files
authored
Merge pull request #555 from ocaml/push-rvrmzpsonvoq
Fix handling in Re.{Emacs,Str}
2 parents 74b72bb + cfbfbe7 commit 0cd909b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/emacs.ml

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ module Re = Core
2525
exception Parse_error
2626
exception Not_supported
2727

28+
let by_code f c c' =
29+
let c = Char.code c in
30+
let c' = Char.code c' in
31+
Char.chr (f c c')
32+
;;
33+
2834
let parse s =
2935
let buf = Parse_buffer.create s in
3036
let accept = Parse_buffer.accept buf in
@@ -105,6 +111,7 @@ let parse s =
105111
then Re.char c :: Re.char '-' :: s
106112
else (
107113
let c' = char () in
114+
let c' = by_code Int.max c c' in
108115
bracket (Re.rg c c' :: s))
109116
else bracket (Re.char c :: s))
110117
and char () =

lib_test/str/test_str.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ let _ =
198198
(* Character set *)
199199
expect_pass "rg" (fun () ->
200200
eq_match "[0-9]+" "0123456789";
201-
eq_match "[0-9]+" "a");
201+
eq_match "[0-9]+" "a";
202+
eq_match "[9-0]+" "2";
203+
eq_match "[5-5]" "5";
204+
eq_match "[5-4]" "1");
202205
expect_pass "compl" (fun () ->
203206
eq_match "[^0-9a-z]+" "A:Z+";
204207
eq_match "[^0-9a-z]+" "0";

0 commit comments

Comments
 (0)