Skip to content

Commit d01f478

Browse files
committed
Extend ppxlib backwards compatibility for ppx_regexp.
1 parent add1c9b commit d01f478

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

ppx_regexp.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bug-reports: "https://github.com/paurkedal/ppx_regexp/issues"
1010
depends: [
1111
"ocaml" {>= "4.02.3"}
1212
"dune" {>= "1.11"}
13-
"ppxlib" {>= "0.22.2"}
13+
"ppxlib" {>= "0.9.0"}
1414
"re" {>= "1.7.1"}
1515
"qcheck" {with-test}
1616
]

ppx_regexp/ppx_regexp.ml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* Copyright (C) 2017--2021 Petter A. Urkedal <[email protected]>
1+
(* Copyright (C) 2017--2022 Petter A. Urkedal <[email protected]>
22
*
33
* This library is free software; you can redistribute it and/or modify it
44
* under the terms of the GNU Lesser General Public License as published by
@@ -140,30 +140,17 @@ let rec wrap_group_bindings ~loc rhs offG = function
140140
let transform_cases ~loc cases =
141141
let aux case =
142142
if case.pc_guard <> None then
143-
error ~loc "Guards are not implemented for match%%pcre." else
144-
(match case.pc_lhs with
145-
| { ppat_desc = Ppat_constant (Pconst_string (re_src, _loc, re_delim));
146-
ppat_loc = {loc_start; _}; _ } ->
143+
error ~loc "Guards are not implemented for match%%pcre."
144+
else
145+
Ast_pattern.(parse (pstring __')) loc case.pc_lhs
146+
begin fun {txt = re_src; loc = {loc_start; loc_end; _}} ->
147147
let re_offset =
148-
(match re_delim with Some s -> String.length s + 2 | None -> 1) in
148+
(loc_end.pos_cnum - loc_start.pos_cnum - String.length re_src) / 2
149+
in
149150
let pos = {loc_start with pos_cnum = loc_start.pos_cnum + re_offset} in
150151
let re, bs, nG = extract_bindings ~pos re_src in
151152
(re, nG, bs, case.pc_rhs)
152-
(*
153-
| {ppat_desc = Ppat_alias
154-
({ ppat_desc = Ppat_constant (Pconst_string (re_src,_));
155-
ppat_loc = loc; _ },
156-
var); _} ->
157-
let re, bs, nG = extract_bindings ~loc re_src in
158-
let rhs =
159-
(* TODO: Should this be (_ppx_regexp_v or Re.Group.get _g 0? *)
160-
[%expr let [%p Pat.var var] = _ppx_regexp_v in [%e case.pc_rhs]] in
161-
(re, nG, bs, rhs)
162-
*)
163-
| {ppat_desc = Ppat_any; _} ->
164-
error ~loc "Universal wildcard must be the last pattern."
165-
| {ppat_loc = loc; _} ->
166-
error ~loc "Regular expression pattern should be a string.")
153+
end
167154
in
168155
let cases, default_rhs =
169156
(match List.rev (*_map rewrite_case*) cases with

0 commit comments

Comments
 (0)