Skip to content

Commit 0892a70

Browse files
committed
Fix top-level group elimination in ppx_regexp.
1 parent 1f81e32 commit 0892a70

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ppx_regexp/ppx_regexp.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ module Regexp = struct
9393
| Capture_as (_, e) -> "(" ^ recurse p_alt e ^ ")"
9494
| Call _ -> error ~loc "(&...) is not implemented for %pcre.")
9595
in
96-
recurse 0
96+
(function
97+
| {Location.txt = Capture_as (_, e); _} ->
98+
recurse 0 e
99+
| e ->
100+
recurse 0 e)
97101
end
98102

99103
let dyn_bindings = ref []

tests/test_ppx_regexp.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ let test3 s =
6161
| {|m(o+)re re(gular)? no(is)e, (no )*be(t+)?er|} -> ()
6262
| s' -> assert (s = s'))
6363

64+
let test4 = function%pcre (* Issue 8 *)
65+
| {|(?<x>[-+]?[[:digit:]]+.[[:digit:]]*)|} -> [x]
66+
| {|(?<x>(abc))[[:space:]]*(?<y>(xyz))|} -> [x; y]
67+
| _ -> assert false
68+
6469
let () =
6570
test2 "<>";
6671
test2 "<a>";
@@ -74,7 +79,9 @@ let () =
7479
test2 "one";
7580
test2 "two";
7681
test3 "- + &nbsp; + -";
77-
test3 "catch-all"
82+
test3 "catch-all";
83+
assert (test4 "::123.456::" = ["123.456"]);
84+
assert (test4 "::abc xyz::" = ["abc"; "xyz"])
7885

7986
(* It should work in a functor, and Re_pcre.regxp should be lifted to the
8087
* top-level. *)

0 commit comments

Comments
 (0)