Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_compose.ml
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879(* Copyright (C) 2017 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)openMigrate_parsetreeopenAst_404letocaml_version=Versions.ocaml_404openAst_mapperopenAst_helperopenAsttypesopenParsetreeopenLongident(* Is there an existing function? *)letfresh_var_fore=Printf.sprintf"_ppx_compose_%d"e.pexp_loc.Location.loc_start.Lexing.pos_cnumletapply~locfxs=(matchf.pexp_descwith|Pexp_apply(f',xs')->Exp.apply~locf'(List.appendxs'xs)|_->Exp.apply~locfxs)letrecreduce_composehx=(matchh.pexp_descwith|Pexp_apply({pexp_desc=Pexp_ident{txt=Lident"%";_};_},[(Nolabel,g);(Nolabel,f)])|Pexp_apply({pexp_desc=Pexp_ident{txt=Lident"%>";_};_},[(Nolabel,f);(Nolabel,g)])->letfx=reduce_composefxinreduce_composegfx|_->(apply~loc:h.pexp_loch[Nolabel,x]))letclassifye=(matche.pexp_descwith|Pexp_apply({pexp_desc=Pexp_ident{txt=Lident"%";_};_},[(Nolabel,_);(Nolabel,_)])->`Compose|Pexp_apply({pexp_desc=Pexp_ident{txt=Lident"%>";_};_},[(Nolabel,_);(Nolabel,_)])->`Compose_fw|_->`Other)leteta_expand_composition~is_fwmappere=letname=fresh_var_foreinletvar_loc=ifis_fwthen{e.pexp_locwithloc_end=e.pexp_loc.loc_start}else{e.pexp_locwithloc_start=e.pexp_loc.loc_end}inletpat=Pat.var~loc:var_loc{txt=name;loc=var_loc}inletarg=Exp.ident~loc:var_loc{txt=Lidentname;loc=var_loc}inletbody=mapper.exprmapper(reduce_composeearg)inExp.fun_~loc:e.pexp_locNolabelNonepatbodyletrewrite_exprmappere=(matche.pexp_descwith|Pexp_apply(h,((Nolabel,x)::xs))whenclassifyh<>`Other->mapper.exprmapper(apply~loc:e.pexp_loc(reduce_composehx)xs)|_->(matchclassifyewith|`Compose->eta_expand_composition~is_fw:falsemappere|`Compose_fw->eta_expand_composition~is_fw:truemappere|`Other->default_mapper.exprmappere))letcompose_mapper_config_cookies={default_mapperwithexpr=rewrite_expr}let()=Driver.register~name:"ppx_compose"ocaml_versioncompose_mapper