Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_compose.ml
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576(* Copyright (C) 2017--2021 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 LGPL-3.0 Linking 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
* and the LGPL-3.0 Linking Exception along with this library. If not, see
* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
*)openPpxlibopenAst_builder.Default(* 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')->pexp_apply~locf'(List.appendxs'xs)|_->pexp_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_fwe=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=ppat_var~loc:var_loc{txt=name;loc=var_loc}inletarg=pexp_ident~loc:var_loc{txt=Lidentname;loc=var_loc}inletbody=reduce_composeearginpexp_fun~loc:e.pexp_locNolabelNonepatbodyletrewrite_composee=(matche.pexp_descwith|Pexp_apply(h,((Nolabel,x)::xs))whenclassifyh<>`Other->Some(apply~loc:e.pexp_loc(reduce_composehx)xs)|_->(matchclassifyewith|`Compose->Some(eta_expand_composition~is_fw:falsee)|`Compose_fw->Some(eta_expand_composition~is_fw:truee)|`Other->None))letrules=[Context_free.Rule.special_function"%"rewrite_compose;Context_free.Rule.special_function"%>"rewrite_compose;]let()=Driver.register_transformation~rules"ppx_compose"