123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338moduleStable0=structopen!Core.Core_stablemoduleEncoding=structmoduleV1=structtypet=|Latin1|Utf8[@@derivingbin_io,compare,hash,sexp,stable_witness]let%expect_test_=print_endline[%bin_digest:t];[%expect{| bf67b13f243e7b82146959041854651d |}];;endend(* This [Serialization.t] is the serialization of [t] and it's slightly
different from [t]:
- Serialization.t has [case_insensitive] instead of [case_sensitive], since
Re2.Options.default has [case_sensitive] as the only field that is [true].
By using [case_insensitive] we have the nice property where default representation
has all bool as false (and an empty sexp).
- [max_mem] is stripped (and populated with default) during
serialisation, since I don't think it makes sense to serialise this
- it seems that some parameters in Re2.Options.t have implied values,
so there might be room for improvement of this [t] (at the cost of
more complex code here); for example posix_syntax=false implies that
some of the other parameters are actually ignored
*)moduleV2=structmoduleSerialization=structtypet={case_insensitive:bool[@sexp.bool];dot_nl:bool[@sexp.bool];encoding:Encoding.V1.t[@sexp.defaultEncoding.V1.Utf8][@sexp_drop_default.compare];literal:bool[@sexp.bool];log_errors:bool[@sexp.bool];longest_match:bool[@sexp.bool];never_capture:bool[@sexp.bool];never_nl:bool[@sexp.bool];one_line:bool[@sexp.bool];perl_classes:bool[@sexp.bool];posix_syntax:bool[@sexp.bool];word_boundary:bool[@sexp.bool]}[@@derivingbin_io,compare,hash,sexp,stable_witness]let%expect_test_=print_endline[%bin_digest:t];[%expect{| 7e4458318a614214b63cb4b98577c10a |}];;endendendopen!CoremoduleEncoding=structtypet=Stable0.Encoding.V1.t=|Latin1|Utf8[@@derivingcompare,equal,sexp_of]moduleC_repr=structtypet=int[@@derivingcompare,sexp_of]letequal=Int.(=)(* would use [@@deriving equal], but equal_int is not in scope *)externalget_latin1:unit->int="mlre2__options__encoding__get_latin1"[@@noalloc]externalget_utf8:unit->int="mlre2__options__encoding__get_utf8"[@@noalloc]letutf8=get_utf8()letlatin1=get_latin1()endletto_c_repr=function|Latin1->C_repr.latin1|Utf8->C_repr.utf8;;letof_c_reprc_repr=ifC_repr.equalc_reprC_repr.utf8thenUtf8elseifC_repr.equalc_reprC_repr.latin1thenLatin1elseraise_s[%message"Unexpected Encoding.C_repr"~_:(c_repr:C_repr.t)];;endtypet={case_sensitive:bool;dot_nl:bool;encoding:Encoding.t;literal:bool;log_errors:bool;longest_match:bool;max_mem:int;never_capture:bool;never_nl:bool;one_line:bool;perl_classes:bool;posix_syntax:bool;word_boundary:bool}[@@derivingcompare,fields~getters~iterators:make_creator~direct_iterators:iter,sexp_of]moduleC_repr=structtypet(*$ Re2_options_cinaps.print_c_repr_external_bindings () *)externalcase_sensitive:t->bool="mlre2__options__case_sensitive"[@@noalloc]externalset_case_sensitive:t->bool->unit="mlre2__options__set_case_sensitive"[@@noalloc]externaldot_nl:t->bool="mlre2__options__dot_nl"[@@noalloc]externalset_dot_nl:t->bool->unit="mlre2__options__set_dot_nl"[@@noalloc]externalencoding:t->Encoding.C_repr.t="mlre2__options__encoding"[@@noalloc]externalset_encoding:t->Encoding.C_repr.t->unit="mlre2__options__set_encoding"[@@noalloc]externalliteral:t->bool="mlre2__options__literal"[@@noalloc]externalset_literal:t->bool->unit="mlre2__options__set_literal"[@@noalloc]externallog_errors:t->bool="mlre2__options__log_errors"[@@noalloc]externalset_log_errors:t->bool->unit="mlre2__options__set_log_errors"[@@noalloc]externallongest_match:t->bool="mlre2__options__longest_match"[@@noalloc]externalset_longest_match:t->bool->unit="mlre2__options__set_longest_match"[@@noalloc]externalmax_mem:t->int="mlre2__options__max_mem"[@@noalloc]externalset_max_mem:t->int->unit="mlre2__options__set_max_mem"[@@noalloc]externalnever_capture:t->bool="mlre2__options__never_capture"[@@noalloc]externalset_never_capture:t->bool->unit="mlre2__options__set_never_capture"[@@noalloc]externalnever_nl:t->bool="mlre2__options__never_nl"[@@noalloc]externalset_never_nl:t->bool->unit="mlre2__options__set_never_nl"[@@noalloc]externalone_line:t->bool="mlre2__options__one_line"[@@noalloc]externalset_one_line:t->bool->unit="mlre2__options__set_one_line"[@@noalloc]externalperl_classes:t->bool="mlre2__options__perl_classes"[@@noalloc]externalset_perl_classes:t->bool->unit="mlre2__options__set_perl_classes"[@@noalloc]externalposix_syntax:t->bool="mlre2__options__posix_syntax"[@@noalloc]externalset_posix_syntax:t->bool->unit="mlre2__options__set_posix_syntax"[@@noalloc]externalword_boundary:t->bool="mlre2__options__word_boundary"[@@noalloc]externalset_word_boundary:t->bool->unit="mlre2__options__set_word_boundary"[@@noalloc](*$*)externalcreate_quiet:unit->t="mlre2__options__create_quiet"endletto_c_reprt=letc_repr=C_repr.create_quiet()inletfset_field_tvalue=setc_reprvalueinFields.Direct.itert(*$ Re2_options_cinaps.print_to_c_repr_fields () *)~case_sensitive:(fC_repr.set_case_sensitive)~dot_nl:(fC_repr.set_dot_nl)~encoding:(f(func_reprvalue->C_repr.set_encodingc_repr(Encoding.to_c_reprvalue)))~literal:(fC_repr.set_literal)~log_errors:(fC_repr.set_log_errors)~longest_match:(fC_repr.set_longest_match)~max_mem:(fC_repr.set_max_mem)~never_capture:(fC_repr.set_never_capture)~never_nl:(fC_repr.set_never_nl)~one_line:(fC_repr.set_one_line)~perl_classes:(fC_repr.set_perl_classes)~posix_syntax:(fC_repr.set_posix_syntax)~word_boundary:(fC_repr.set_word_boundary)(*$*);c_repr;;letof_c_repr=letfget_field()=get,()inFields.make_creator(*$ Re2_options_cinaps.print_of_c_repr_fields () *)~case_sensitive:(fC_repr.case_sensitive)~dot_nl:(fC_repr.dot_nl)~encoding:(f(func_repr->Encoding.of_c_repr(C_repr.encodingc_repr)))~literal:(fC_repr.literal)~log_errors:(fC_repr.log_errors)~longest_match:(fC_repr.longest_match)~max_mem:(fC_repr.max_mem)~never_capture:(fC_repr.never_capture)~never_nl:(fC_repr.never_nl)~one_line:(fC_repr.one_line)~perl_classes:(fC_repr.perl_classes)~posix_syntax:(fC_repr.posix_syntax)~word_boundary:(fC_repr.word_boundary)(*$*)()|>fst;;letdefault=C_repr.create_quiet()|>of_c_reprletlatin1={defaultwithencoding=Latin1}letnoisy={defaultwithlog_errors=true}letposix={defaultwithlongest_match=true;posix_syntax=true}letdefault_max_mem=max_memdefaultmodulePrivate=structmoduleC_repr=C_reprletof_c_repr=of_c_reprletto_c_repr=to_c_reprendmoduleStable=structopen!Stable_witness.ExportincludeStable0moduleV2=structmoduleSerialization=V2.Serializationtypenonrect=t={case_sensitive:bool;dot_nl:bool;encoding:Encoding.V1.t;literal:bool;log_errors:bool;longest_match:bool;max_mem:int;never_capture:bool;never_nl:bool;one_line:bool;perl_classes:bool;posix_syntax:bool;word_boundary:bool}[@@derivingcompare,hash,stable_witness]letto_serialization{case_sensitive;dot_nl;encoding;literal;log_errors;longest_match;max_mem=_;never_capture;never_nl;one_line;perl_classes;posix_syntax;word_boundary}:Serialization.t={case_insensitive=notcase_sensitive;dot_nl;encoding;literal;log_errors;longest_match;never_capture;never_nl;one_line;perl_classes;posix_syntax;word_boundary};;letof_serialization({case_insensitive;dot_nl;encoding;literal;log_errors;longest_match;never_capture;never_nl;one_line;perl_classes;posix_syntax;word_boundary}:Serialization.t)={case_sensitive=notcase_insensitive;dot_nl;encoding;literal;log_errors;longest_match;max_mem=default_max_mem;never_capture;never_nl;one_line;perl_classes;posix_syntax;word_boundary};;letsexp_of_tt=Serialization.sexp_of_t(to_serializationt)lett_of_sexpsexp=of_serialization(Serialization.t_of_sexpsexp)letdefault()=to_serializationdefaultletis_defaultt=[%compare.equal:Serialization.t](to_serializationt)(default())includeCore.Binable.Of_binable_without_uuid[@alert"-legacy"](Serialization)(structtypenonrect=tletto_binable=to_serializationletof_binable=of_serializationend)(* This check verifies the default value produces '()',
acknowledging that the fields that we believe are default in C code, are
coded as default in the sexp as well. If this changes, a new stable type
should be created *)let%expect_test_=[%sexp_of:Serialization.t](default())|>print_s;[%expect{| () |}];;endend