Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file parse_info.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2013 Hugo Heuzard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*)open!Stdlibtypet={src:stringoption;name:stringoption;col:int;line:int;idx:int;fol:booloption}letzero={src=None;name=None;col=0;line=0;idx=0;fol=None}moduleLine_info=structtypet_above=ttypet={mutableacc_pos:int;mutableacc_line:int;offset:t_aboveoption;lines:intarray;name:stringoption;src:stringoption}letreccomputelinesacclinepos=ifline>=Array.lengthlinesthenifpos=0thenacc,line,0elseassertfalseelseiflines.(line)>=posthenacc,line,poselsecomputelines(acc+lines.(line)+1)(succline)(pos-lines.(line)-1)letgettpos=letacc,line,pos=ift.acc_pos<=posthencomputet.linest.acc_post.acc_line(pos-t.acc_pos)elsecomputet.lines00posint.acc_pos<-acc;t.acc_line<-line;line,posletfrom_filefile=letic=open_infileinletlines=ref[]in(trywhiletruedolines:=String.length(input_lineic)::!linesdonewithEnd_of_file->());letlines=Array.of_list(List.rev!lines)inlett={acc_pos=0;acc_line=0;offset=None;lines;name=Somefile;src=Somefile}inclose_inic;tletfrom_string?offsetstr=letpos=ref0andlines=ref[]in(trywhiletruedoletidx=String.index_fromstr!pos'\n'inlines:=(idx-!pos)::!lines;pos:=idx+1donewithNot_found->lines:=(String.lengthstr-!pos)::!lines);letlines=Array.of_list(List.rev!lines)in{acc_pos=0;acc_line=0;offset;lines;name=None;src=None}letfrom_channelic=letbuf=Buffer.create1024inletlines=ref[]in(trywhiletruedoletl=input_lineicinBuffer.add_stringbufl;Buffer.add_charbuf'\n';lines:=String.lengthl::!linesdonewithEnd_of_file->());letlines=Array.of_list(List.rev!lines)inlett={acc_pos=0;acc_line=0;offset=None;lines;name=None;src=None}int,Buffer.contentsbufendtypelineinfo=Line_info.tletrelative_path{Line_info.src;_}file=matchsrcwith|None->None|Somesrc->SomeFilename.(concat(dirnamesrc)file)letmake_lineinfo_from_filefile=Line_info.from_filefileletmake_lineinfo_from_string?offsetstr=Line_info.from_string?offsetstrletmake_lineinfo_from_channelc=Line_info.from_channelclett_of_lexbufline_infolexbuf:t=letidx=lexbuf.Lexing.lex_start_p.Lexing.pos_cnuminletline,col=Line_info.getline_infoidxinletline,col=matchline_info.Line_info.offsetwith|None->line,col|Some{line=line_offset;col=col_offset;_}->line+line_offset,col+col_offsetinletname=matchline_info.Line_info.offsetwith|Some{name=Some_asname;_}->name|_->line_info.Line_info.nameinletsrc=matchline_info.Line_info.offsetwith|Some{src=Some_assrc;_}->src|_->line_info.Line_info.srcin{fol=None;idx;line;col;name;src}