Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file nstream.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198(**************************************************************************)(* *)(* Copyright 2011 Jun Furuse *)(* Copyright 2012-2015 OCamlPro *)(* *)(* All rights reserved.This file is distributed under the terms of the *)(* GNU Lesser General Public License version 3.0 with linking *)(* exception. *)(* *)(* TypeRex 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 *)(* Lesser GNU General Public License for more details. *)(* *)(**************************************************************************)modulePosition=structtypet=Lexing.position={pos_fname:string;pos_lnum:int;pos_bol:int;pos_cnum:int;}letto_stringt=Printf.sprintf"%s%d:%d"(ift.pos_fname=""then""elset.pos_fname^":")t.pos_lnum(t.pos_cnum-t.pos_bol)letzero={pos_fname="";pos_lnum=1;pos_bol=0;pos_cnum=0}letcolumnp=p.pos_cnum-p.pos_bolendmoduleRegion=structopenPositiontypet=Position.t*Position.tletfst=fstletsnd=sndletcreatep1p2=(p1,p2)letstart_column(p,_)=columnpletend_column(_,p)=columnpletstart_line(p,_)=p.pos_lnumletend_line(_,p)=p.pos_lnumletchar_offset(p,_)=p.pos_cnumletlength(p1,p2)=p2.Position.pos_cnum-p1.Position.pos_cnumletzero=(Position.zero,Position.zero)lettranslate(p,p')diff={pwithpos_cnum=p.pos_cnum+diff},{p'withpos_cnum=p'.pos_cnum+diff}endtypetoken={token:Approx_lexer.token;between:string;substr:string;region:Region.t;offset:int;}typesnapshot=Approx_lexer.context*Region.ttypecons=|Consoftoken*snapshot*t|Nullandt=conslazy_tletfind_first_non_spaces=letrecloopsi=ifi<String.lengthsthenifs.[i]<>' '&&s.[i]<>'\t'&&s.[i]<>'\012'(* form feed *)thenielseloops(succi)elseiinloops0letrecprocessstlexbufbetweenlast=lazybeginmatchApprox_lexer.tokenstlexbufwith|st,Approx_lexer.SPACES->assert(between="");Lazy.force(processstlexbuf(Lexing.lexemelexbuf)last)|st,token->letsubstr=Lexing.lexemelexbufin(* STRING_CONTENT and COMMENT_CONTENT might start with spaces *)leti=find_first_non_spacesubstrinassert(i=0||token=Approx_lexer.ESCAPED_EOL||token=Approx_lexer.STRING_CONTENT||token=Approx_lexer.STRING_CLOSE||token=Approx_lexer.COMMENT_CONTENT||token=Approx_lexer.COMMENT_CLOSE||token=Approx_lexer.COMMENT_VERB_CLOSE||token=Approx_lexer.P4_QUOTATION_CONTENT||token=Approx_lexer.PPX_QUOTATION_CONTENT);letbetween,substr=ifi=0thenbetween,substrelse(assert(between="");String.subsubstr0i,String.subsubstri(String.lengthsubstr-i))inletregion=Region.createlexbuf.Lexing.lex_start_plexbuf.Lexing.lex_curr_pinletoffset=Region.start_columnregion-Region.start_columnlastinletlocated_token={token;between;substr;region;offset;}inmatchtokenwith|Approx_lexer.EOF->Cons(located_token,(st,region),lazyNull)|_->Cons(located_token,(st,region),processstlexbuf""region)endletof_channel?st:((st,last)=(Approx_lexer.initial_state,Region.zero))ic=letlb=Lexing.from_channelicinlb.Lexing.lex_start_p<-Region.sndlast;lb.Lexing.lex_curr_p<-Region.sndlast;lb.Lexing.lex_abs_pos<-lb.Lexing.lex_curr_p.Lexing.pos_cnum;processstlb""lastletof_string?st:((st,last)=(Approx_lexer.initial_state,Region.zero))ic=letlb=Lexing.from_stringicinlb.Lexing.lex_start_p<-Region.sndlast;lb.Lexing.lex_curr_p<-Region.sndlast;lb.Lexing.lex_abs_pos<-lb.Lexing.lex_curr_p.Lexing.pos_cnum;processstlb""lastletdisplayppftok=Format.fprintfppf"STREAM (%s, %s)\n\
\ - tok: %s\n\
\ - between: %S\n\
\ - substr: %S\n\
\ - offset: %d\n%!"(Position.to_string(Region.fsttok.region))(Position.to_string(Region.sndtok.region))(Approx_tokens.string_of_toktok.token)tok.betweentok.substrtok.offsetletnext=function|lazyNull->None|lazy(Cons(tok,_,st))->Some(tok,st)letnext_full=function|lazyNull->None|lazy(Cons(tok,snap,st))->Some(tok,snap,st)moduleSimple=structtypetoken=Approx_lexer.Simple.t={token:Approx_lexer.Simple.token;substr:string;region:Region.t;}typestream=|Null|Consoftoken*streamLazy.ttypet=streamLazy.tletrecprocessstlb:streamLazy.t=lazybeginmatchApprox_lexer.Simple.tokenstlbwith|None->Null|Some({token=Approx_lexer.Simple.EOF;_}astoken,_)->Cons(token,lazyNull)|Some(token,st)->Cons(token,processstlb)endletof_channelic=letlb=Lexing.from_channelicinprocessApprox_lexer.initial_statelbletof_strings=letlb=Lexing.from_stringsinprocessApprox_lexer.initial_statelbletnext:t->_=function|lazyNull->None|lazy(Cons(tok,stream))->Some(tok,stream)end