Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file attrs.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222open!Baseopen!Ppxlibletdefault=Attribute.declare"sexp.default"Attribute.Context.label_declarationAst_pattern.(pstr(pstr_eval__nil^::nil))(funx->x)letdrop_default=Attribute.declare"sexp.sexp_drop_default"Attribute.Context.label_declarationAst_pattern.(pstr(alt_option(pstr_eval__nil^::nil)nil))(funx->x)letdrop_default_equal=Attribute.declare"sexp.@sexp_drop_default.equal"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letdrop_default_compare=Attribute.declare"sexp.@sexp_drop_default.compare"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letdrop_default_sexp=Attribute.declare"sexp.@sexp_drop_default.sexp"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letdrop_if=Attribute.declare"sexp.sexp_drop_if"Attribute.Context.label_declarationAst_pattern.(pstr(pstr_eval__nil^::nil))(funx->x)letopaque=Attribute.declare"sexp.opaque"Attribute.Context.core_typeAst_pattern.(pstrnil)()letomit_nil=Attribute.declare"sexp.omit_nil"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letoption=Attribute.declare"sexp.option"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letlist=Attribute.declare"sexp.list"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letarray=Attribute.declare"sexp.array"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letbool=Attribute.declare"sexp.bool"Attribute.Context.label_declarationAst_pattern.(pstrnil)()letlist_variant=Attribute.declare"sexp.list"Attribute.Context.constructor_declarationAst_pattern.(pstrnil)()letlist_exception=Attribute.declare"sexp.list"Attribute.Context.type_exceptionAst_pattern.(pstrnil)()letlist_poly=Attribute.declare"sexp.list"Attribute.Context.rtagAst_pattern.(pstrnil)()letallow_extra_fields_td=Attribute.declare"sexp.allow_extra_fields"Attribute.Context.type_declarationAst_pattern.(pstrnil)()letallow_extra_fields_cd=Attribute.declare"sexp.allow_extra_fields"Attribute.Context.constructor_declarationAst_pattern.(pstrnil)()letinvalid_attribute~locattrdescription=Location.raise_errorf~loc"ppx_sexp_conv: [@%s] is only allowed on type [%s]."(Attribute.nameattr)descriptionletfail_if_allow_extra_field_cd~locx=ifOption.is_some(Attribute.getallow_extra_fields_cdx)thenLocation.raise_errorf~loc"ppx_sexp_conv: [@@allow_extra_fields] is only allowed on \
inline records."letfail_if_allow_extra_field_td~locx=ifOption.is_some(Attribute.getallow_extra_fields_tdx)thenmatchx.ptype_kindwith|Ptype_variantcdswhenList.existscds~f:(funcd->matchcd.pcd_argswithPcstr_record_->true|_->false)->Location.raise_errorf~loc"ppx_sexp_conv: [@@@@allow_extra_fields] only works on records. \
For inline records, do: type t = A of { a : int } [@@allow_extra_fields] | B \
[@@@@deriving sexp]"|_->Location.raise_errorf~loc"ppx_sexp_conv: [@@@@allow_extra_fields] is only allowed on \
records."moduleRecord_field_handler=structtypecommon=[`omit_nil|`sexp_arrayofcore_type|`sexp_bool|`sexp_listofcore_type|`sexp_optionofcore_type]letget_attributeattrld~f=Option.map(Attribute.getattrld)~f:(funx->fx,Attribute.nameattr);;letcreate~locgettersld=letcommon_getters=[get_attributeomit_nil~f:(fun()->`omit_nil);(funld->matchld.pld_typewith|[%type:sexp_bool]->Some(`sexp_bool,"sexp_bool")|[%type:[%t?ty]sexp_option]->Some(`sexp_optionty,"sexp_option")|[%type:[%t?ty]sexp_list]->Some(`sexp_listty,"sexp_list")|[%type:[%t?ty]sexp_array]->Some(`sexp_arrayty,"sexp_array")|tywhenOption.is_some(Attribute.getboolld)->(matchtywith|[%type:bool]->Some(`sexp_bool,"[@sexp.bool]")|_->invalid_attribute~locbool"bool")|tywhenOption.is_some(Attribute.getoptionld)->(matchtywith|[%type:[%t?ty]option]->Some(`sexp_optionty,"[@sexp.option]")|_->invalid_attribute~locoption"_ option")|tywhenOption.is_some(Attribute.getlistld)->(matchtywith|[%type:[%t?ty]list]->Some(`sexp_listty,"[@sexp.list]")|_->invalid_attribute~loclist"_ list")|tywhenOption.is_some(Attribute.getarrayld)->(matchtywith|[%type:[%t?ty]array]->Some(`sexp_arrayty,"[@sexp.array]")|_->invalid_attribute~locarray"_ array")|_->None)]inmatchList.filter_map(getters@common_getters)~f:(funf->fld)with|[]->None|[(v,_)]->Somev|_::_::_asattributes->Location.raise_errorf~loc"The following elements are mutually exclusive: %s"(String.concat~sep:" "(List.mapattributes~f:snd));;moduleOf_sexp=structtypet=[common|`defaultofexpression]letcreate~locld=create~loc[get_attributedefault~f:(fundefault->`defaultdefault)]ldendmoduleSexp_of=structtypet=[common|`drop_defaultof[`no_arg|`compare|`equal|`sexp|`funcofexpression]|`drop_ifofexpression|`keep]letcreate~locld=create~loc[get_attributedrop_default~f:(function|None->`drop_default`no_arg|Somee->`drop_default(`funce));get_attributedrop_default_equal~f:(fun()->`drop_default`equal);get_attributedrop_default_compare~f:(fun()->`drop_default`compare);get_attributedrop_default_sexp~f:(fun()->`drop_default`sexp);get_attributedrop_if~f:(funx->`drop_ifx)]ld|>Option.value~default:`keependend