Skip to content

Commit 7b6570b

Browse files
committed
Extract toplevel names in sequences.
1 parent d8973d4 commit 7b6570b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

ppx_tyre/ppx_tyre.ml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ let rec regexp_of_pattern pat =
400400
let re = match pat.ppat_desc with
401401
| Ppat_constant (Pconst_string (s, delim)) ->
402402
let pos = adjust_position ~loc delim in
403-
Regexp.(Capture (parse_exn ~pos s))
403+
(Regexp.parse_exn ~pos s).txt
404404
| Ppat_alias (pat, s) ->
405405
Regexp.(Capture_as (s, regexp_of_pattern pat))
406406
| Ppat_or (pat1, pat2) ->
@@ -417,7 +417,14 @@ let rec regexp_of_pattern pat =
417417

418418
let expr_of_pattern pat =
419419
let re = simplify @@ regexp_of_pattern pat in
420-
capture re, expr_of_regex @@ re
420+
match re.txt with
421+
| Seq l ->
422+
let f_item re = capture re, expr_of_regex re in
423+
let capture_seq, expr = seq_to_expr ~loc:re.loc @@ List.map f_item l in
424+
capture_seq, expr
425+
| _ ->
426+
capture_singleton (capture re), expr_of_regex re
427+
421428

422429
let expr_of_function ~loc l =
423430
let err_on_guard = function
@@ -430,10 +437,12 @@ let expr_of_function ~loc l =
430437
err_on_guard pc_guard;
431438
let loc = pc_lhs.ppat_loc in
432439
let capture, re = expr_of_pattern pc_lhs in
440+
let pvar_of_lid {Loc.loc; txt} = AC.pvar ~loc txt in
433441
let arg = match capture with
434-
| No -> A.Pat.any ~loc ()
435-
| Named {loc; txt} -> AC.pvar ~loc txt
436-
| Unnamed () -> A.Pat.any ~loc ()
442+
| Named [] | Unnamed 0 -> internal_error ~loc
443+
| No | Unnamed _ -> A.Pat.any ~loc ()
444+
| Named [lid] -> pvar_of_lid lid
445+
| Named l -> AC.ptuple ~loc @@ List.map pvar_of_lid l
437446
in
438447
let e = AC.func ~loc [arg, pc_rhs] in
439448
AC.constr ~loc "Tyre.Route" [re; e]

0 commit comments

Comments
 (0)