123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384openPpxlibmoduleAp=Attribute_parsertypeeval_type=Cmds|Termleteval_type_of_name=function|"subliner.cmds"->SomeCmds|"subliner.term"->SomeTerm|_->Noneletunsupported_error~loc=Location.raise_errorf~loc"extension payload is not supported. please ensure it is in the format of \
[%%subliner.[cmds|term] <eval>.<params type> <- <function expression>]"letcmd_expr_of_func_expr~loc~attrstlidfunc_expr:expression=matchtwith|Cmds->(* Cmd.info *)letcmd_info_expr=(* exe name will be the default cmd name *)letdefault_name_expr=[%exprFilename.basenameSys.argv.(0)]inGroup_cmds.Info.expr_of_attrs~locdefault_name_exprattrsanddefault_term_expr=Ap.Default_term.parseattrs|>Ap.to_expr_opt"default"|>Option.value~default:[%exprCmdliner.Term.(ret(const(`Help(`Auto,None))))]andgroup_cmd_fun_expr=lid|>Utils.map_lid_nameGroup_cmds.gen_name_str|>Ast_helper.Exp.identin[%exprletinfo:Cmdliner.Cmd.info=[%ecmd_info_expr]anddefault=[%edefault_term_expr]andgroup_cmd=[%egroup_cmd_fun_expr][%efunc_expr]inCmdliner.Cmd.group~defaultinfogroup_cmd]|Term->(* Cmd.info *)letcmd_info_expr=(* exe name will be the default cmd name *)letdefault_name_expr=[%exprFilename.basenameSys.argv.(0)]inGroup_cmds.Info.expr_of_attrs~locdefault_name_exprattrsandparams_term_expr=lid|>Utils.map_lid_nameTerm.gen_name_str|>Ast_helper.Exp.identin[%exprletinfo:Cmdliner.Cmd.info=[%ecmd_info_expr]inCmdliner.(Cmd.vinfoTerm.(const[%efunc_expr]$[%eparams_term_expr]()))]leteval_fun_of_expr~loc~attrst(expr:expression):structure_item=matchexpr.pexp_descwith|Pexp_setfield(eval_expr,type_lid,func_expr)->Ast_helper.with_default_locexpr.pexp_loc(fun()->letcmd_expr=cmd_expr_of_func_expr~loc~attrsttype_lidfunc_exprin[%strilet()=letcmd=[%ecmd_expr]inexit(Cmdliner.Cmd.([%eeval_expr])cmd)])|_->unsupported_error~locleteval_fun_of_payload~loc~attrst:payload->structure_item=function|PStr[{pstr_desc=Pstr_eval(expr,_attrs);_}]->eval_fun_of_expr~loc~attrstexpr|_->unsupported_error~locletimpl(strs:structure_itemlist):structure_itemlist=List.filter_map(funstr->letloc=str.pstr_locinmatchstr.pstr_descwith|Pstr_extension(({txt;loc=_},payload),attrs)whenUtils.string_starts_with~prefix:"subliner"txt->(matcheval_type_of_nametxtwith|Somet->Some(eval_fun_of_payload~loc~attrstpayload)|None->Location.raise_errorf"unknown subliner rewriter name")|_->Somestr)strslet()=Driver.register_transformation~impl"subliner"