123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106(*********************************************************************************)(* OCaml-RDF *)(* *)(* Copyright (C) 2012-2024 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public License *)(* along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(** *)(* Print the location in some way or another *)openFormatopenLexingtypeloc={loc_start:Lexing.position;loc_end:Lexing.position;}letdummy_loc={loc_start=Lexing.dummy_pos;loc_end=Lexing.dummy_pos;}letsource_info_stringsstartstop=letbols=List.rev(Utf8.utf8_get_bols)inletrecsearchcnum=function[]->(1,0)|(line,bol)::q->ifcnum>=bolthen(line,bol)elsesearchcnumqinletposp=let(line,bol)=searchpbolsin{pos_cnum=p;pos_fname="";pos_bol=bol;pos_lnum=line;}in{loc_start=posstart;loc_end=posstop};;letsource_info_filefilestartstop=lets=Misc.string_of_filefileinletloc=source_info_stringsstartstopin{loc_start={loc.loc_startwithpos_fname=file};loc_end={loc.loc_endwithpos_fname=file};}let(msg_file,msg_line,msg_char,msg_chars,msg_to,msg_colon,msg_head)=("File ","line ",", character ",", characters ","-",":","")(* return file, line, char from the given position *)letget_pos_infopos=let(filename,linenum,linebeg)=(* if pos.pos_fname = "" then
("", -1, 0)
else
*)(pos.pos_fname,pos.pos_lnum,pos.pos_bol)in(filename,linenum,pos.pos_cnum-linebeg);;letppppfloc=let(file,line,startchar)=get_pos_infoloc.loc_startinletendchar=loc.loc_end.pos_cnum-loc.loc_start.pos_cnum+startcharinlet(startchar,endchar)=ifstartchar<0then(0,1)else(startchar,endchar)iniffile<>""thenfprintfppf"%s \"%s\", "msg_filefile;fprintfppf"%s%i"msg_lineline;ifstartchar<>endcharthenbeginfprintfppf"%s%i"msg_charsstartchar;fprintfppf"%s%i%s@.%s"msg_toendcharmsg_colonmsg_headendelsebeginfprintfppf"%s%i"msg_charstartchar;fprintfppf"%s@.%s"msg_colonmsg_headend;;letstring_of_locloc=ppFormat.str_formatterloc;Format.flush_str_formatter();;