Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file html.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190(*
* Generic transformers: plugins.
* Copyright (C) 2016-2022
* Dmitrii Kosarev aka Kakadu
* St.Petersburg State University, JetBrains Research
*)(** {i Html} module: converts a value to its html represenation (work in progress).
*)(*
For type declaration [type ('a,'b,...) typ = ...] it will create a transformation
function with type
[('a -> HTML.er) -> ('b -> HTML.er) -> ... ->
('a,'b,...) typ -> HTML.er ]
Inherited attributes' type (both default and for type parameters) are absent.
Synthesized attributes' type (both default and for type parameters) is [HTML.er].
*)openPpxlibopenPrintfopenGTCommonopenHelpersBaselettrait_name="html"moduleMake(AstHelpers:GTHELPERS_sig.S)=structlettrait_name=trait_namemoduleP=Plugin.Make(AstHelpers)openAstHelpersletapp_format_sprintf~locarg=Exp.app~loc(Exp.of_longident~loc(Ldot(Lident"Format","sprintf")))arg;;moduleH=structtypeelt=Exp.tletwrap~locs=Exp.of_longident~loc(Ldot(Lident"HTML",s))letpcdata~locs=Exp.(app~loc(wrap~loc"string")(string_const~locs))letdiv~locxs=Exp.app~loc(wrap~loc"list")@@Exp.list~locxsletto_list_e~locxs=List.fold_rightxs~init:(Exp.construct~loc(lident"[]")[])~f:(funxacc->Exp.app_list~loc(Exp.of_longident~loc(Ldot(Lident"List","cons")))[x;acc]);;letli~locxs=Exp.app~loc(wrap~loc"li")@@Exp.app~loc(wrap~loc"seq")@@to_list_e~locxs;;letseq~locxs=Exp.app~loc(wrap~loc"seq")@@to_list_e~locxs(* let ol ~loc xs =
* Exp.app ~loc (wrap ~loc "ol") @@ Exp.app ~loc (wrap ~loc "seq") @@ to_list_e ~loc xs *)letul~locxs=Exp.app~loc(wrap~loc"ul")@@Exp.app~loc(wrap~loc"seq")@@to_list_e~locxs;;letcheckbox~locname=letopenExpinapp~loc(app_lab~loc(wrap~loc"input")"attrs"(string_const~loc@@Printf.sprintf"type=\"checkbox\" id=\"%s\""name))(app~loc(wrap~loc"unit")(unit~loc));;endclassgargstdecls=object(self)inherit[loc,Exp.t,Typ.t,type_arg,Cl.t,Ctf.t,Cf.t,Str.t,Sig.t,Pat.t]Plugin_intf.typ_ginheritP.generatorargstdeclsinheritP.no_inherit_argargstdeclsmethodtrait_name=trait_namemethodinh_of_main~loc_tdecl=Typ.ident~loc"unit"methodsyn_of_main~loc?in_class_tdecl=self#syn_of_param~loc"dummy"methodsyn_of_param~loc_=Typ.constr~loc(Ldot(Lident"HTML","er"))[]methodinh_of_param~loctdecl_name=self#inh_of_main~loctdeclmethodplugin_class_params~loc(typs:Ppxlib.core_typelist)~typname=(* the same as in 'show' plugin *)List.maptyps~f:Typ.from_caml@[Typ.var~loc@@Naming.make_extra_paramtypname]methodon_tuple_constr~loc~is_self_rec~mutual_decls~inhetdeclconstr_infots=letconstr_name=matchconstr_infowith|Some(`Polys)->sprintf"`%s"s|Some(`Normals)->s|None->"tuple"inifList.lengthts=0thenH.(pcdata~locconstr_name)elseH.seq~loc@@[H.pcdata~locconstr_name;H.ul~loc(List.mapts~f:(fun(name,typ)->H.li~loc[self#app_transformation_expr~loc(self#do_typ_gen~loc~is_self_rec~mutual_declstdecltyp)(Exp.unit~loc)(Exp.ident~locname)]))]methodon_record_declaration~loc~is_self_rec~mutual_declstdecllabs=letpat=Pat.record~loc@@List.maplabs~f:(funl->Lidentl.pld_name.txt,Pat.var~locl.pld_name.txt)inletmethname=sprintf"do_%s"tdecl.ptype_name.txtin[(Cf.method_concrete~locmethname@@Exp.fun_~loc(Pat.unit~loc)@@Exp.fun_~locpat@@letds=List.maplabs~f:(fun{pld_name;pld_type}->H.li~loc[H.pcdata~locpld_name.txt;self#app_transformation_expr~loc(self#do_typ_gen~loc~is_self_rec~mutual_declstdeclpld_type)(Exp.unit~loc)(Exp.ident~locpld_name.txt)])inH.ul~loc@@(H.pcdata~loctdecl.ptype_name.txt::ds))]method!on_record_constr:loc:loc->is_self_rec:(core_type->[`Nonrecursive|`Nonregular|`Regular])->mutual_decls:type_declarationlist->inhe:Exp.t->_->[`Normalofstring|`Polyofstring]->(string*_*core_type)list->label_declarationlist->Exp.t=fun~loc~is_self_rec~mutual_decls~inhetdeclinfobindingslabs->letconstr_name=matchinfowith|`Polys->sprintf"`%s"s|`Normals->sinletopenHinul~loc@@[pcdata~locconstr_name]@List.mapbindings~f:(fun(pname,lname,typ)->H.li~loc[H.pcdata~loclname;self#app_transformation_expr~loc(self#do_typ_gen~loc~is_self_rec~mutual_declstdecltyp)(Exp.unit~loc)(Exp.ident~locpname)])method!make_inh~loc=Pat.unit~loc,Exp.unit~locendletcreate=(newg:>P.plugin_constructor)endletregister()=Expander.register_plugintrait_name(moduleMake:Plugin_intf.MAKE)let()=register()