123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(* Conv_error: Module for Handling Errors during Automated S-expression
Conversions *)openStdLabelsopenPrintfopenSexp_convexceptionOf_sexp_error=Of_sexp_error(* Errors concerning tuples *)lettuple_of_size_n_expectedlocnsexp=of_sexp_error(sprintf"%s_of_sexp: tuple of size %d expected"locn)sexp(* Errors concerning sum types *)letstag_no_argslocsexp=of_sexp_error(loc^"_of_sexp: sum tag does not take arguments")sexpletstag_incorrect_n_argsloctagsexp=letmsg=sprintf"%s_of_sexp: sum tag %S has incorrect number of arguments"loctaginof_sexp_errormsgsexpletstag_takes_argslocsexp=of_sexp_error(loc^"_of_sexp: sum tag must be a structured value")sexpletnested_list_invalid_sumlocsexp=of_sexp_error(loc^"_of_sexp: a nested list is an invalid sum")sexpletempty_list_invalid_sumlocsexp=of_sexp_error(loc^"_of_sexp: the empty list is an invalid sum")sexpletunexpected_staglocsexp=of_sexp_error(loc^"_of_sexp: unexpected sum tag")sexp(* Errors concerning records *)letrecord_sexp_bool_with_payloadlocsexp=letmsg=loc^"_of_sexp: record conversion: a [sexp.bool] field was given a payload."inof_sexp_errormsgsexpletrecord_only_pairs_expectedlocsexp=letmsg=loc^"_of_sexp: record conversion: only pairs expected, \
their first element must be an atom"inof_sexp_errormsgsexpletrecord_superfluous_fields~what~locrev_fld_namessexp=letfld_names_str=String.concat(List.revrev_fld_names)~sep:" "inletmsg=sprintf"%s_of_sexp: %s: %s"locwhatfld_names_strinof_sexp_errormsgsexpletrecord_duplicate_fieldslocrev_fld_namessexp=record_superfluous_fields~what:"duplicate fields"~locrev_fld_namessexpletrecord_extra_fieldslocrev_fld_namessexp=record_superfluous_fields~what:"extra fields"~locrev_fld_namessexpletrecrecord_get_undefined_loopfields=function|[]->String.concat(List.revfields)~sep:" "|(true,field)::rest->record_get_undefined_loop(field::fields)rest|_::rest->record_get_undefined_loopfieldsrestletrecord_undefined_elementslocsexplst=letundefined=record_get_undefined_loop[]lstinletmsg=sprintf"%s_of_sexp: the following record elements were undefined: %s"locundefinedinof_sexp_errormsgsexpletrecord_list_instead_atomlocsexp=letmsg=loc^"_of_sexp: list instead of atom for record expected"inof_sexp_errormsgsexpletrecord_poly_field_valuelocsexp=letmsg=loc^"_of_sexp: cannot convert values of types resulting from polymorphic \
record fields"inof_sexp_errormsgsexp(* Errors concerning polymorphic variants *)exceptionNo_variant_matchletno_variant_match()=raiseNo_variant_matchletno_matching_variant_foundlocsexp=of_sexp_error(loc^"_of_sexp: no matching variant found")sexpletptag_no_argslocsexp=of_sexp_error(loc^"_of_sexp: polymorphic variant does not take arguments")sexpletptag_incorrect_n_argsloccnstrsexp=letmsg=sprintf"%s_of_sexp: polymorphic variant tag %S has incorrect number of arguments"loccnstrinof_sexp_errormsgsexpletptag_takes_argslocsexp=of_sexp_error(loc^"_of_sexp: polymorphic variant tag takes an argument")sexpletnested_list_invalid_poly_varlocsexp=of_sexp_error(loc^"_of_sexp: a nested list is an invalid polymorphic variant")sexpletempty_list_invalid_poly_varlocsexp=of_sexp_error(loc^"_of_sexp: the empty list is an invalid polymorphic variant")sexpletempty_typelocsexp=of_sexp_error(loc^"_of_sexp: trying to convert an empty type")sexp