|
1 |
| -(* Copyright (C) 2017--2021 Petter A. Urkedal <[email protected]> |
| 1 | +(* Copyright (C) 2017--2022 Petter A. Urkedal <[email protected]> |
2 | 2 | *
|
3 | 3 | * This library is free software; you can redistribute it and/or modify it
|
4 | 4 | * 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
|
140 | 140 | let transform_cases ~loc cases =
|
141 | 141 | let aux case =
|
142 | 142 | 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; _}} -> |
147 | 147 | 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 |
149 | 150 | let pos = {loc_start with pos_cnum = loc_start.pos_cnum + re_offset} in
|
150 | 151 | let re, bs, nG = extract_bindings ~pos re_src in
|
151 | 152 | (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 |
167 | 154 | in
|
168 | 155 | let cases, default_rhs =
|
169 | 156 | (match List.rev (*_map rewrite_case*) cases with
|
|
0 commit comments