123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140(* 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: this constructor does not take arguments")sexp;;letstag_incorrect_n_argsloctagsexp=letmsg=sprintf"%s_of_sexp: sum tag %S has incorrect number of arguments"loctaginof_sexp_errormsgsexp;;letstag_takes_argslocsexp=of_sexp_error(loc^"_of_sexp: this constructor requires arguments")sexp;;letnested_list_invalid_sumlocsexp=of_sexp_error(loc^"_of_sexp: expected a variant type, saw a nested list")sexp;;letempty_list_invalid_sumlocsexp=of_sexp_error(loc^"_of_sexp: expected a variant type, saw an empty list")sexp;;letunexpected_staglocsexp=of_sexp_error(loc^"_of_sexp: unexpected variant constructor")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_errormsgsexp;;letrecord_only_pairs_expectedlocsexp=letmsg=loc^"_of_sexp: record conversion: only pairs expected, their first element must be an \
atom"inof_sexp_errormsgsexp;;letrecord_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_errormsgsexp;;letrecord_duplicate_fieldslocrev_fld_namessexp=record_superfluous_fields~what:"duplicate fields"~locrev_fld_namessexp;;letrecord_extra_fieldslocrev_fld_namessexp=record_superfluous_fields~what:"extra fields"~locrev_fld_namessexp;;letrecrecord_get_undefined_loopfields=function|[]->String.concat(List.revfields)~sep:" "|(true,field)::rest->record_get_undefined_loop(field::fields)rest|_::rest->record_get_undefined_loopfieldsrest;;letrecord_undefined_elementslocsexplst=letundefined=record_get_undefined_loop[]lstinletmsg=sprintf"%s_of_sexp: the following record elements were undefined: %s"locundefinedinof_sexp_errormsgsexp;;letrecord_list_instead_atomlocsexp=letmsg=loc^"_of_sexp: list instead of atom for record expected"inof_sexp_errormsgsexp;;letrecord_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")sexp;;letptag_no_argslocsexp=of_sexp_error(loc^"_of_sexp: polymorphic variant does not take arguments")sexp;;letptag_incorrect_n_argsloccnstrsexp=letmsg=sprintf"%s_of_sexp: polymorphic variant tag %S has incorrect number of arguments"loccnstrinof_sexp_errormsgsexp;;letptag_takes_argslocsexp=of_sexp_error(loc^"_of_sexp: polymorphic variant tag takes an argument")sexp;;letnested_list_invalid_poly_varlocsexp=of_sexp_error(loc^"_of_sexp: a nested list is an invalid polymorphic variant")sexp;;letempty_list_invalid_poly_varlocsexp=of_sexp_error(loc^"_of_sexp: the empty list is an invalid polymorphic variant")sexp;;letempty_typelocsexp=of_sexp_error(loc^"_of_sexp: trying to convert an empty type")sexp;;