@@ -40,59 +40,51 @@ let rec expToPat (exp : Parsetree.expression) =
40
40
| _ -> None
41
41
42
42
let mkMapper ~pos ~changed =
43
- let value_binding (mapper : Ast_mapper.mapper ) (vb : Parsetree.value_binding )
44
- =
43
+ let expr (mapper : Ast_mapper.mapper ) (e : Parsetree.expression ) =
45
44
let newExp =
46
- match vb.pvb_pat.ppat_desc with
47
- | Ppat_var {txt; loc} when posInLoc ~pos ~loc -> (
48
- match vb.pvb_expr.pexp_desc with
49
- | Pexp_ifthenelse
50
- ( {
51
- pexp_desc =
52
- Pexp_apply
53
- ( {
54
- pexp_desc =
55
- Pexp_ident {txt = Lident ((" =" | " <>" ) as op)};
56
- },
57
- [(Nolabel , arg1); (Nolabel , arg2)] );
58
- },
59
- e1,
60
- Some e2 ) -> (
61
- let e1, e2 = if op = " =" then (e1, e2) else (e2, e1) in
62
- let mkMatch ~arg ~pat =
63
- let cases =
64
- [
65
- Ast_helper.Exp. case pat e1;
66
- Ast_helper.Exp. case (Ast_helper.Pat. any () ) e2;
67
- ]
68
- in
69
- Ast_helper.Exp. match_ ~loc: vb.pvb_expr.pexp_loc
70
- ~attrs: vb.pvb_expr.pexp_attributes arg cases
45
+ match e.pexp_desc with
46
+ | Pexp_ifthenelse
47
+ ( {
48
+ pexp_desc =
49
+ Pexp_apply
50
+ ( {pexp_desc = Pexp_ident {txt = Lident ((" =" | " <>" ) as op)}},
51
+ [(Nolabel , arg1); (Nolabel , arg2)] );
52
+ },
53
+ e1,
54
+ Some e2 )
55
+ when posInLoc ~pos ~loc: e.pexp_loc -> (
56
+ let e1, e2 = if op = " =" then (e1, e2) else (e2, e1) in
57
+ let mkMatch ~arg ~pat =
58
+ let cases =
59
+ [
60
+ Ast_helper.Exp. case pat e1;
61
+ Ast_helper.Exp. case (Ast_helper.Pat. any () ) e2;
62
+ ]
71
63
in
64
+ Ast_helper.Exp. match_ ~loc: e.pexp_loc ~attrs: e.pexp_attributes arg
65
+ cases
66
+ in
72
67
73
- match expToPat arg2 with
74
- | None -> (
75
- match expToPat arg1 with
76
- | None -> None
77
- | Some pat1 ->
78
- let newExp = mkMatch ~arg: arg2 ~pat: pat1 in
79
- Printf. printf " Hit %s\n " txt;
80
- Some newExp)
81
- | Some pat2 ->
82
- let newExp = mkMatch ~arg: arg1 ~pat: pat2 in
83
- Printf. printf " Hit %s\n " txt;
68
+ match expToPat arg2 with
69
+ | None -> (
70
+ match expToPat arg1 with
71
+ | None -> None
72
+ | Some pat1 ->
73
+ let newExp = mkMatch ~arg: arg2 ~pat: pat1 in
84
74
Some newExp)
85
- | _ -> None )
75
+ | Some pat2 ->
76
+ let newExp = mkMatch ~arg: arg1 ~pat: pat2 in
77
+ Some newExp)
86
78
| _ -> None
87
79
in
88
80
match newExp with
89
81
| Some newExp ->
90
82
changed := true ;
91
- {vb with pvb_expr = newExp}
92
- | None -> Ast_mapper. default_mapper.value_binding mapper vb
83
+ newExp
84
+ | None -> Ast_mapper. default_mapper.expr mapper e
93
85
in
94
86
95
- {Ast_mapper. default_mapper with value_binding }
87
+ {Ast_mapper. default_mapper with expr }
96
88
97
89
let command ~path ~pos =
98
90
if Filename. check_suffix path " .res" then
0 commit comments