Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file sertop_util.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2018 MINES ParisTech *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)(************************************************************************)(* Based on Sexplib, (c) Jane Street, released under Apache License 2.0 *)(* Custom sexp printer *)(* *)(* Current sexplib escaping is not the most convenient for some clients *)(* so we provide a different, experimental one *)(************************************************************************)openFormatopenSexplibopenSexpletmust_escapestr=letlen=String.lengthstrinlen=0||letrecloopix=matchstr.[ix]with|'"'|'('|')'|'['|']'|';'|'\\'|'\''->true(* Avoid unquoted comma at the beggining of the string *)|','->ix=0||loop(ix-1)|'|'->ix>0&&letnext=ix-1instr.[next]='#'||loopnext|'#'->ix>0&&letnext=ix-1instr.[next]='|'||loopnext|'\000'..'\032'->true|'\248'..'\255'->true|_->ix>0&&loop(ix-1)inloop(len-1)(* XXX: Be faithful to UTF-8 *)letst_escaped(s:string)=letsget=String.unsafe_getinletopenBytesinletn=ref0infori=0toString.lengths-1don:=!n+(matchsgetsiwith|'\"'|'\\'|'\n'|'\t'|'\r'|'\b'->2|' '..'~'->1(* UTF-8 are valid between \033 -- \247 *)|'\000'..'\032'->4|'\248'..'\255'->4|_->1)done;if!n=String.lengthsthenBytes.of_stringselsebeginlets'=create!ninn:=0;fori=0toString.lengths-1dobeginmatchsgetsiwith|('\"'|'\\')asc->unsafe_sets'!n'\\';incrn;unsafe_sets'!nc|'\n'->unsafe_sets'!n'\\';incrn;unsafe_sets'!n'n'|'\t'->unsafe_sets'!n'\\';incrn;unsafe_sets'!n't'|'\r'->unsafe_sets'!n'\\';incrn;unsafe_sets'!n'r'|'\b'->unsafe_sets'!n'\\';incrn;unsafe_sets'!n'b'|(' '..'~')asc->unsafe_sets'!nc(* Valid UTF-8 are valid between \033 -- \247 *)|'\000'..'\032'|'\248'..'\255'asc->leta=Char.codecinunsafe_sets'!n'\\';incrn;unsafe_sets'!n(Char.chr(48+a/100));incrn;unsafe_sets'!n(Char.chr(48+(a/10)mod10));incrn;unsafe_sets'!n(Char.chr(48+amod10));|c->unsafe_sets'!ncend;incrndone;s'endletesc_str(str:string)=letopenBytesinletestr=st_escapedstrinletelen=lengthestrinletres=create(elen+2)inblitestr0res1elen;setres0'"';setres(elen+1)'"';to_stringresletsertop_maybe_esc_strstr=ifmust_escapestrthenesc_strstrelsestrletrecpp_sertop_internalmay_need_spaceppf=function|Atomstr->letstr'=sertop_maybe_esc_strstrinletnew_may_need_space=str'==strinifmay_need_space&&new_may_need_spacethenpp_print_stringppf" ";pp_print_stringppfstr';new_may_need_space|List(h::t)->pp_print_stringppf"(";letmay_need_space=pp_sertop_internalfalseppfhinpp_sertop_restmay_need_spaceppft;false|List[]->pp_print_stringppf"()";falseandpp_sertop_restmay_need_spaceppf=function|h::t->letmay_need_space=pp_sertop_internalmay_need_spaceppfhinpp_sertop_restmay_need_spaceppft|[]->pp_print_stringppf")"letpp_sertopppfsexp=ignore(pp_sertop_internalfalseppfsexp)(* XXX: This is terrible and doesn't work yet *)letreccoq_pp_opt(d:Pp.t)=letopenPpinletrecflatten_gluel=matchlwith|[]->[]|(Ppcmd_glueg::l)->flatten_glue(List.mapreprg@flatten_gluel)|(Ppcmd_strings1::Ppcmd_strings2::l)->flatten_glue(Ppcmd_string(s1^s2)::flatten_gluel)|(x::l)->x::flatten_gluelin(* let rec flatten_glue l = match l with *)(* | (Ppcmd_string s1 :: Ppcmd_string s2 :: l) -> Ppcmd_string (s1 ^ s2) :: flatten_glue l *)unrepr(matchreprdwith|Ppcmd_glue[]->Ppcmd_empty|Ppcmd_glue[x]->repr(coq_pp_optx)|Ppcmd_gluel->Ppcmd_glueList.(mapcoq_pp_opt(mapunrepr(flatten_glue(mapreprl))))|Ppcmd_box(bt,d)->Ppcmd_box(bt,coq_pp_optd)|Ppcmd_tag(t,d)->Ppcmd_tag(t,coq_pp_optd)|d->d)(* Adjust positions from byte to UTF-8 chars *)(* XXX: Move to serapi/ *)(* We only do adjustement for messages for now. *)moduleF=Feedbackletfeedback_content_pos_filtertxt(fbc:F.feedback_content):F.feedback_content=letadjust_txtloc=locinmatch(fbc:F.feedback_content)with|F.Message(lvl,loc,msg)->F.Message(lvl,adjusttxtloc,msg)|_->fbcletfeedback_pos_filtertext(fb:F.feedback):F.feedback={fbwithF.contents=feedback_content_pos_filtertextfb.F.contents;}(* Optimizes and filters feedback *)typefb_filter_opts={pp_opt:bool;}letdefault_fb_filter_opts={pp_opt=true;}letfeedback_content_tr(fb:F.feedback_content):Serapi.Serapi_protocol.feedback_content=matchfbwith|F.Message(level,loc,pp)->letstr=Pp.string_of_ppcmdsppinMessage{level;loc;pp;str}|F.Processed->Processed|F.Incomplete->Incomplete|F.Complete->Complete|F.ProcessingIns->ProcessingIns|F.InProgressi->InProgressi|F.WorkerStatus(s1,s2)->WorkerStatus(s1,s2)|F.AddedAxiom->AddedAxiom|F.GlobRef(_,_,_,_,_)->assertfalse|F.GlobDef(_,_,_,_)->assertfalse|F.FileDependency(o,p)->FileDependency(o,p)|F.FileLoaded(o,p)->FileLoaded(o,p)|F.Custom(_,_,_)->assertfalseletfeedback_tr(fb:Feedback.feedback):Serapi.Serapi_protocol.feedback=matchfbwith|{doc_id;span_id;route;contents}->letcontents=feedback_content_trcontentsin{doc_id;span_id;route;contents}letfeedback_opt_filter?(opts=default_fb_filter_opts)=letopenFeedbackinfunction|{F.contents=Message(lvl,loc,msg);_}asfb->Some(ifopts.pp_optthen{fbwithcontents=Message(lvl,loc,coq_pp_optmsg)}elsefb)|{F.contents=FileDependency_;_}->None|fb->Somefb