123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(* Conv_error: Module for Handling Errors during Automated S-expression
Conversions *)openStdLabelsopenPrintfopenSexp_convexceptionOf_sexp_error=Of_sexp_errorleterror~loc~sexpmsg=of_sexp_error(sprintf"%s_of_sexp: %s"locmsg)sexpletsimple_errormsglocsexp=error~loc~sexpmsg(* Errors concerning tuples *)lettuple_of_size_n_expectedlocnsexp=error~loc~sexp(sprintf"tuple of size %d expected"n);;lettuple_pair_expectedlocnamesexp=letmsg=sprintf"%s_of_sexp: expected a pair beginning with label %s"locnameinof_sexp_errormsgsexp;;lettuple_incorrect_labellocnamepossexp=letmsg=sprintf"%s_of_sexp: incorrect label for element %s at position %i"locnameposinof_sexp_errormsgsexp;;(* Errors concerning sum types *)letstag_no_args=simple_error"this constructor does not take arguments"letstag_incorrect_n_argsloctagsexp=error~loc~sexp(sprintf"sum tag %S has incorrect number of arguments"tag);;letstag_takes_args=simple_error"this constructor requires arguments"letnested_list_invalid_sum=simple_error"expected a variant type, saw a nested list"letempty_list_invalid_sum=simple_error"expected a variant type, saw an empty list"letunexpected_stag=simple_error"unexpected variant constructor"(* Errors concerning records *)letrecord_sexp_bool_with_payload=simple_error"record conversion: a [sexp.bool] field was given a payload.";;letrecord_only_pairs_expected=simple_error"record conversion: only pairs expected, their first element must be an atom";;letrecord_invalid_fields~what~locfld_namessexp=letfld_names_str=String.concatfld_names~sep:" "inerror~loc~sexp(sprintf"%s: %s"whatfld_names_str);;letrecord_duplicate_fieldslocfld_namessexp=record_invalid_fields~what:"duplicate fields"~locfld_namessexp;;letrecord_extra_fieldslocfld_namessexp=record_invalid_fields~what:"extra fields"~locfld_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"the following record elements were undefined: %s"undefinedinerror~loc~sexpmsg;;letrecord_list_instead_atom=simple_error"list instead of atom for record expected"letrecord_poly_field_value=simple_error"cannot convert values of types resulting from polymorphic record fields";;(* Errors concerning polymorphic variants *)exceptionNo_variant_matchletno_variant_match()=raiseNo_variant_matchletno_matching_variant_found=simple_error"no matching variant found"letptag_no_args=simple_error"polymorphic variant does not take arguments"letptag_incorrect_n_argsloccnstrsexp=error~loc~sexp(sprintf"polymorphic variant tag %S has incorrect number of arguments"cnstr);;letptag_takes_args=simple_error"polymorphic variant tag takes an argument"letnested_list_invalid_poly_var=simple_error"a nested list is an invalid polymorphic variant";;letempty_list_invalid_poly_var=simple_error"the empty list is an invalid polymorphic variant";;letempty_type=simple_error"trying to convert an empty type"