summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJon French2018-04-25 09:30:38 +0100
committerJon French2018-05-01 16:57:35 +0100
commit6056295b2b7c829fe4e8843dbd7f52b5bba9facf (patch)
tree7c6bd7ea0b3e55e49f1317d5817967f2f8cc9c99 /src
parent7ae7f56127e6cc96e7715e052fa4a69e793cafe4 (diff)
utils mapping over mpats/mpexps
Diffstat (limited to 'src')
-rw-r--r--src/ast_util.ml19
-rw-r--r--src/ast_util.mli2
2 files changed, 21 insertions, 0 deletions
diff --git a/src/ast_util.ml b/src/ast_util.ml
index 8b51edd3..955c147f 100644
--- a/src/ast_util.ml
+++ b/src/ast_util.ml
@@ -439,6 +439,25 @@ and map_pat_annot_aux f = function
| P_vector pats -> P_vector (List.map (map_pat_annot f) pats)
| P_cons (pat1, pat2) -> P_cons (map_pat_annot f pat1, map_pat_annot f pat2)
| P_string_append (pat1, pat2) -> P_string_append (map_pat_annot f pat1, map_pat_annot f pat2)
+
+and map_mpexp_annot f (MPat_aux (mpexp, annot)) = MPat_aux (map_mpexp_annot_aux f mpexp, f annot)
+and map_mpexp_annot_aux f = function
+ | MPat_pat mpat -> MPat_pat (map_mpat_annot f mpat)
+ | MPat_when (mpat, guard) -> MPat_when (map_mpat_annot f mpat, map_exp_annot f guard)
+
+and map_mpat_annot f (MP_aux (mpat, annot)) = MP_aux (map_mpat_annot_aux f mpat, f annot)
+and map_mpat_annot_aux f = function
+ | MP_lit lit -> MP_lit lit
+ | MP_id id -> MP_id id
+ | MP_app (id, mpats) -> MP_app (id, List.map (map_mpat_annot f) mpats)
+ | MP_record (fmpats, b) -> MP_record (List.map (map_fpat_annot f) fmpats, b)
+ | MP_tup mpats -> MP_tup (List.map (map_mpat_annot f) mpats)
+ | MP_list mpats -> MP_list (List.map (map_mpat_annot f) mpats)
+ | MP_vector_concat mpats -> MP_vector_concat (List.map (map_mpat_annot f) mpats)
+ | MP_vector mpats -> MP_vector (List.map (map_mpat_annot f) mpats)
+ | MP_cons (mpat1, mpat2) -> MP_cons (map_mpat_annot f mpat1, map_mpat_annot f mpat2)
+ | MP_string_append (mpat1, mpat2) -> MP_string_append (map_mpat_annot f mpat1, map_mpat_annot f mpat2)
+
and map_fpat_annot f (FP_aux (FP_Fpat (id, pat), annot)) = FP_aux (FP_Fpat (id, map_pat_annot f pat), f annot)
and map_letbind_annot f (LB_aux (lb, annot)) = LB_aux (map_letbind_annot_aux f lb, f annot)
and map_letbind_annot_aux f = function
diff --git a/src/ast_util.mli b/src/ast_util.mli
index c07732bf..f9f42e10 100644
--- a/src/ast_util.mli
+++ b/src/ast_util.mli
@@ -174,6 +174,8 @@ val map_pat_annot : ('a annot -> 'b annot) -> 'a pat -> 'b pat
val map_pexp_annot : ('a annot -> 'b annot) -> 'a pexp -> 'b pexp
val map_lexp_annot : ('a annot -> 'b annot) -> 'a lexp -> 'b lexp
val map_letbind_annot : ('a annot -> 'b annot) -> 'a letbind -> 'b letbind
+val map_mpat_annot : ('a annot -> 'b annot) -> 'a mpat -> 'b mpat
+val map_mpexp_annot : ('a annot -> 'b annot) -> 'a mpexp -> 'b mpexp
(* Extract locations from identifiers *)
val id_loc : id -> Parse_ast.l