123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101(* This file is free software, part of Zipperposition. See file "license" for more details. *)(** {1 Location in a file} *)typet={file:string;start_line:int;start_column:int;stop_line:int;stop_column:int;}letmkfilestart_linestart_columnstop_linestop_column={file;start_line;start_column;stop_line;stop_column;}letmk_pairfile(a,b)(c,d)=mkfileabcdletmk_posstartstop=letopenLexinginmkstart.pos_fnamestart.pos_lnum(start.pos_cnum-start.pos_bol)stop.pos_lnum(stop.pos_cnum-stop.pos_bol)leteqab=a=blethasha=Hashtbl.hashalet_min_pos(l1,c1)(l2,c2)=ifl1=l2thenl1,minc1c2elseifl1<l2thenl1,c1elsel2,c2let_max_pos(l1,c1)(l2,c2)=ifl1=l2thenl1,maxc1c2elseifl1<l2thenl2,c2elsel1,c1letcombinep1p2=letstart_line,start_column=_min_pos(p1.start_line,p1.start_column)(p2.start_line,p2.start_column)inletstop_line,stop_column=_max_pos(p1.stop_line,p1.stop_column)(p2.stop_line,p2.stop_column)in{file=p1.file;start_line;start_column;stop_line;stop_column;}letreccombine_listl=matchlwith|[]->raise(Invalid_argument"location.combine_list: empty list")|[p]->p|p1::((_::_)asl')->letp'=combine_listl'incombinep1p'letsmallerp1p2=(p1.start_line>p2.start_line||(p1.start_line=p2.start_line&&p1.start_column>=p2.start_column))&&(p1.stop_line<p2.stop_line||(p1.stop_line=p2.stop_line&&p1.stop_column<=p2.stop_column))moduleInfix=structlet(<+>)=CCOpt.(<+>)endincludeInfixletppoutpos=ifpos.start_line=pos.stop_linethenFormat.fprintfout"@[file '%s': line %d, col %d to %d@]"pos.filepos.start_linepos.start_columnpos.stop_columnelseFormat.fprintfout"@[file '%s': line %d, col %d to line %d, col %d@]"pos.filepos.start_linepos.start_columnpos.stop_linepos.stop_columnletto_string=CCFormat.to_stringppletpp_optouto=matchowith|None->()|Somepos->Format.fprintfout"@[at %a@]"ppposletset_filebuffilename=letopenLexinginbuf.lex_curr_p<-{buf.lex_curr_pwithpos_fname=filename;};()letof_lexbuflexbuf=letstart=Lexing.lexeme_start_plexbufinletend_=Lexing.lexeme_end_plexbufinlets_l=start.Lexing.pos_lnuminlets_c=start.Lexing.pos_cnum-start.Lexing.pos_bolinlete_l=end_.Lexing.pos_lnuminlete_c=end_.Lexing.pos_cnum-end_.Lexing.pos_bolinletfile=start.Lexing.pos_fnameinmkfiles_ls_ce_le_c