12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061letbp_=ref0letundamage_jfloc=Loc.{locwithbol_pos=loc.bol_pos-!bp_;bp=loc.bp-!bp_;ep=loc.ep-!bp_}let_=Ast.ud:=undamage_jfletundamage_jf_optloc=Option.mapundamage_jflocletundamage_ast{CAst.loc;v}=CAst.make?loc:(undamage_jf_optloc)vmodulePCoqHack=structtypet={pa_tok_strm:Tok.tLStream.t;lexer_state:CLexer.Lexer.State.tref}letloc(p:Pcoq.Parsable.t):Loc.t=letp:t=Obj.magicpinLStream.current_locp.pa_tok_strm|>undamage_jfendmoduleParsable=structincludePcoq.Parsableletloc=PCoqHack.locendletparse~stps=letmode=State.mode~stinletst=State.parsing~stin(* Coq is missing this, so we add it here. Note that this MUST run inside
coq_protect *)Control.check_for_interrupt();Vernacstate.Parser.parsestPvernac.(main_entrymode)ps|>Option.mapundamage_ast|>Option.mapAst.of_coqletparse~stps=Protect.eval~f:(parse~st)ps(* Read the input stream until a dot or a "end of proof" token is encountered *)letparse_to_terminator:unitPcoq.Entry.t=(* type 'a parser_fun = { parser_fun : te LStream.t -> 'a } *)letrecdotst=matchLStream.nextstwith|Tok.KEYWORD("."|"..."|"Qed"|"Defined"|"Admitted")|Tok.BULLET_->()|Tok.EOI->()|_->dotstinPcoq.Entry.of_parser"Coqtoplevel.dot"{parser_fun=dot}(* If an error occurred while parsing, we try to read the input until a dot
token is encountered. We assume that when a lexer error occurs, at least one
char was eaten *)letrecdiscard_to_dotps=tryPcoq.Entry.parseparse_to_terminatorpswith|CLexer.Error.E_->discard_to_dotps|ewhenCErrors.noncriticale->()