123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293open!ImportincludeParse_error_intftypet={position:Positions.pos;message:string;old_parser_exn:[`Parse_error|`Failure]}letsexp_of_t{position;message;old_parser_exn=_}:Sexp.t=List[List[Atom"position";Positions.sexp_of_posposition];List[Atom"message";sexp_of_stringmessage]];;letpositiont=t.positionletmessaget=t.messageletold_parser_exnt=t.old_parser_exnletreportppf~filenamet=letpos=positiontinletmsg=messagetinFormat.fprintfppf"File \"%s\", line %d, character %d:\nError: s-expression parsing error;\n%s\n"filenamepos.linepos.colmsg;;exceptionParse_erroroft[@@deriving_inlinesexp]let()=Ppx_sexp_conv_lib.Conv.Exn_converter.add[%extension_constructorParse_error](function|Parse_errorv0->letv0=sexp_of_tv0inPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"parse_error.ml.Parse_error";v0]|_->assertfalse);;[@@@end]letraise(reason:Reason.t)position~at_eof~atom_buffer=letmessage=(* These messages where choosen such that we can build the various Sexplib parsing
functions on top of Parsexp and keep the same exceptions.
At the time of writing this, a simple layer on top of parsexp to implement the
sexplib API is passing all the sexplib tests.
Note that parsexp matches the semantic of Sexp.parse which is slightly
different from the ocamllex/ocamlyacc based parser of Sexplib. The latter one
is less tested and assumed to be less used. *)matchreasonwith|Unexpected_char_parsing_hex_escape->"unterminated hexadecimal escape sequence"|Unexpected_char_parsing_dec_escape->"unterminated decimal escape sequence"|Unterminated_quoted_string->"unterminated quoted string"|Unterminated_block_comment->"unterminated block comment"|Escape_sequence_out_of_range->"escape sequence in quoted string out of range"|Unclosed_paren->"unclosed parentheses at end of input"|Too_many_sexps->"s-expression followed by data"|Closed_paren_without_opened->"unexpected character: ')'"|Comment_token_in_unquoted_atom->ifString.equal(Buffer.contentsatom_buffer)"|"then"illegal end of comment"else"comment tokens in unquoted atom"|Sexp_comment_without_sexp->"unterminated sexp comment"|Unexpected_character_after_cr->ifat_eofthen"unexpected end of input after carriage return"else"unexpected character after carriage return"|No_sexp_found_in_input->"no s-expression found in input"|Automaton_in_error_state->failwith"Parsexp.Parser_automaton: parser is dead"inletold_parser_exn=matchreason,at_eofwith|Too_many_sexps,_|_,true->`Failure|Comment_token_in_unquoted_atom,_whenString.equal(Buffer.contentsatom_buffer)"|"->`Failure|_->`Parse_errorinraise(Parse_error{position;message;old_parser_exn});;modulePrivate=structmoduleReason=Reasonletold_parser_exn=old_parser_exnletraise=raiseend