Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_bistro.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164openBasemoduleL=LocationopenPpxlibletdigestx=Stdlib.Digest.to_hex(Stdlib.Digest.string(Stdlib.Marshal.to_stringx[]))letstring_of_expressione=letbuf=Buffer.create251inletfmt=Stdlib.Format.formatter_of_bufferbufinPprintast.expressionfmte;Stdlib.Format.pp_print_flushfmt();Buffer.contentsbufletnew_id=letc=ref0infun()->Stdlib.incrc;Printf.sprintf"__v%d__"!cmoduleB=structincludeAst_builder.Make(structletloc=Location.noneend)letelidentv=pexp_ident(Located.lidentv)leteconstrsargs=letargs=matchargswith|[]->None|[x]->Somex|l->Some(pexp_tuplel)inpexp_construct(Located.lidents)argsletenil()=econstr"[]"[]leteconshdtl=econstr"::"[hd;tl]letenone()=econstr"None"[]letesomex=econstr"Some"[x]leteoptx=matchxwith|None->enone()|Somex->esomexletelistl=List.fold_right~f:econsl~init:(enil())letpvarv=ppat_var(Located.mkv)endtypeinsert_type=|Value|Path|Paramletinsert_type_of_ext=function|"eval"->Value|"path"->Path|"param"->Param|ext->failwith("Unknown insert "^ext)classpayload_rewriter=objectinherit[(string*expression*insert_type)list]Ast_traverse.fold_mapassupermethod!expressionexpracc=matchexprwith|{pexp_desc=Pexp_extension({txt=("eval"|"path"|"param"asext);loc;_},payload);_}->(matchpayloadwith|PStr[{pstr_desc=Pstr_eval(e,_);_}]->letid=new_id()inletacc'=(id,e,insert_type_of_extext)::accinletexpr'=B.elidentidinexpr',acc'|_->failwith(Location.raise_errorf~loc"expected an expression"))|_->super#expressionexpraccendletadd_renamings~locdepsinit=List.folddeps~init~f:(funacc(tmpvar,expr,ext)->letrhs=matchextwith|Path->[%exprBistro.Workflow.path[%eexpr]]|Param->[%exprBistro.Workflow.data[%eexpr]]|Value->exprin[%exprlet[%pB.pvartmpvar]=[%erhs]in[%eacc]])letbuild_applicative~locdepscode=letid=digest(string_of_expressioncode)inmatchdepswith|[]->[%exprBistro.Workflow.pure~id:[%eB.estringid][%ecode]]|(h_tmpvar,_,_)::t->lettuple_expr=List.fold_rightt~init:(B.elidenth_tmpvar)~f:(fun(tmpvar,_,_)acc->[%exprBistro.Workflow.both[%eB.elidenttmpvar][%eacc]])inlettuple_pat=List.fold_rightt~init:(B.pvarh_tmpvar)~f:(fun(tmpvar,_,_)acc->Ast_builder.Default.ppat_tuple~loc[B.pvartmpvar;acc])in[%exprBistro.Workflow.app(Bistro.Workflow.pure~id:[%eB.estringid](fun[%ptuple_pat]->[%ecode]))[%etuple_expr]]|>add_renamingsdeps~locletexpression_rewriter~loc~path:_expr=letcode,deps=newpayload_rewriter#expressionexpr[]inbuild_applicative~locdepscodeletrecextract_body=function|{pexp_desc=Pexp_fun(_,_,_,body);_}->extract_bodybody|{pexp_desc=Pexp_constraint(expr,ty);_}->expr,Somety|expr->expr,Noneletrecreplace_bodynew_body=function|({pexp_desc=Pexp_fun(lab,e1,p,e2);_}asexpr)->{exprwithpexp_desc=Pexp_fun(lab,e1,p,replace_bodynew_bodye2)}|_->new_bodyletdefault_descrvar=Printf.sprintf"%s.%s"Stdlib.Filename.(remove_extension(basename!L.input_name))varletstr_item_rewriter~loc~path:_descrversionmemnpvarexpr=letdescr=matchdescrwith|Somed->d|None->B.estring(default_descrvar)inletbody,body_type=extract_bodyexprinletrewritten_body,deps=newpayload_rewriter#expressionbody[]inletapplicative_body=build_applicative~locdeps[%exprfun()->[%erewritten_body]]inletworkflow_body=[%exprBistro.Workflow.plugin~descr:[%edescr]?version:[%eB.eoptversion]?np:[%eB.eoptnp]?mem:[%eB.eoptmem][%eapplicative_body]]inletworkflow_body_with_type=matchbody_typewith|None->workflow_body|Somety->[%expr([%eworkflow_body]:[%tty])]in[%strilet[%pB.pvarvar]=[%ereplace_bodyworkflow_body_with_typeexpr]]letscript_ext=letopenExtensionindeclare"script"Context.expressionAst_pattern.(single_expr_payload(estring__'))Bistro_script.rewriterletinclude_script_ext=letopenExtensionindeclare"include_script"Context.expressionAst_pattern.(single_expr_payload(estring__'))Bistro_script.include_rewriterletexpression_ext=letopenExtensionindeclare"workflow"Context.expressionAst_pattern.(single_expr_payload__)expression_rewriterlet()=Driver.register_transformation"bistro"~extensions:[script_ext;include_script_ext;expression_ext;]