123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153open!ImportopenStd_internalincludeString_id_intfmoduleMake_with_validate_without_pretty_printer(M:sigvalmodule_name:stringvalvalidate:string->unitOr_error.tvalinclude_default_validation:boolend)()=structmoduleStable=structmoduleV1=structmoduleT=structtypet=string[@@derivingcompare,equal,hash,sexp,sexp_grammar,typerep]letcheck_for_whitespace=letinvalidsreason=Error(sprintf"'%s' is not a valid %s because %s"sM.module_namereason)infuns->letlen=String.lengthsinifInt.(=)len0theninvalids"it is empty"elseifChar.is_whitespaces.[0]||Char.is_whitespaces.[len-1]theninvalids"it has whitespace on the edge"elseOk();;letvalidates=Result.map_error(M.validates)~f:Error.to_string_machletchecks=ifM.include_default_validationthen(matchcheck_for_whitespaceswith|Ok()->validates|Errorerror->Errorerror)elsevalidates;;letto_string=Fn.idletpp=String.ppletof_strings=matchcheckswith|Ok()->s|Errorerr->invalid_argerr;;lett_of_sexpsexp=lets=String.Stable.V1.t_of_sexpsexpinmatchcheckswith|Ok()->s|Errorerr->of_sexp_errorerrsexp;;includeBinable.Of_binable_without_uuid[@alert"-legacy"](String)(structtypenonrect=tletto_binable=Fn.idletof_binable=of_stringend)endmoduleT_with_comparator=structincludeTincludeComparator.Stable.V1.Make(T)endincludeT_with_comparatorincludeComparable.Stable.V1.Make(T_with_comparator)includeHashable.Stable.V1.Make(T_with_comparator)endendmoduleStable_latest=Stable.V1includeStable_latest.T_with_comparatorincludeComparable.Make_binable_using_comparator(Stable_latest.T_with_comparator)includeHashable.Make_binable(Stable_latest.T_with_comparator)letquickcheck_shrinker=Quickcheck.Shrinker.empty()letquickcheck_observer=String.quickcheck_observerletquickcheck_generator=String.gen_nonempty'Char.gen_print|>Quickcheck.Generator.filter~f:(funstring->checkstring|>Result.is_ok);;letarg_type=Command.Arg_type.createof_stringendmoduleMake_without_pretty_printer(M:sigvalmodule_name:stringend)()=structincludeMake_with_validate_without_pretty_printer(structletmodule_name=M.module_nameletvalidate=Fn.const(Ok())letinclude_default_validation=trueend)()endmoduleMake_with_validate(M:sigvalmodule_name:stringvalvalidate:string->unitOr_error.tvalinclude_default_validation:boolend)()=structincludeMake_with_validate_without_pretty_printer(M)()includePretty_printer.Register(structtypenonrect=tletmodule_name=M.module_nameletto_string=to_stringend)endmoduleMake(M:sigvalmodule_name:stringend)()=structincludeMake_without_pretty_printer(M)()includePretty_printer.Register(structtypenonrect=tletmodule_name=M.module_nameletto_string=to_stringend)endincludeMake(structletmodule_name="Core.String_id"end)()moduleString_without_validation_without_pretty_printer=structincludeStringletarg_type=Command.Arg_type.createFn.idend