123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203open!Baseopen!PpxlibmoduleTo_lift=structtype'at={to_lift:'a}[@@unboxed]endopenTo_liftletdefault=Attribute.declare"sexp.default"Attribute.Context.label_declarationAst_pattern.(pstr(pstr_eval__nil^::nil))(funx->{to_lift=x});;letdrop_default=Attribute.declare"sexp.sexp_drop_default"Attribute.Context.label_declarationAst_pattern.(pstr(alt_option(pstr_eval__nil^::nil)nil))(function|None->None|Somex->Some{to_lift=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->{to_lift=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)();;lettag_attribute_for_contextcontext=letopenAst_patterninletkey_equals_value=Ast_pattern.(pexp_apply(pexp_ident(lident(string"=")))(no_label__^::no_label__^::nil)|>pack2)inletget_captured_valuesast_patterncontextexpression=Ast_pattern.to_funcast_patterncontextexpression.pexp_locexpression(funx->x)inletreccollect_sequenceexpression=matchexpression.pexp_descwith|Pexp_sequence(l,r)->l::collect_sequencer|_->[expression]inletesequenceast_pattern=Ast_pattern.of_func(funcontext_locexpressionk->collect_sequenceexpression|>List.map~f:(get_captured_valuesast_patterncontext)|>k)inAttribute.declare"sexp_grammar.tag"context(pstr(pstr_eval(esequencekey_equals_value)nil^::nil))(funx->x);;lettag_type=tag_attribute_for_contextCore_typelettag_ld=tag_attribute_for_contextLabel_declarationlettag_cd=tag_attribute_for_contextConstructor_declarationlettag_poly=tag_attribute_for_contextRtagletinvalid_attribute~locattrdescription=Location.raise_errorf~loc"ppx_sexp_conv: [@%s] is only allowed on type [%s]."(Attribute.nameattr)description;;letfail_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)then(matchx.ptype_kindwith|Ptype_variantcdswhenList.existscds~f:(funcd->matchcd.pcd_argswith|Pcstr_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.");;