123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778(* Result of a successful match. *)typet={s:string;marks:Automata.mark_infos;pmarks:Pmark.Set.t;gpos:intarray;gcount:int}letoffsetti=if2*i+1>=Array.lengtht.marksthenraiseNot_found;letm1=t.marks.(2*i)inifm1=-1thenraiseNot_found;letp1=t.gpos.(m1)inletp2=t.gpos.(t.marks.(2*i+1))in(p1,p2)letgetti=let(p1,p2)=offsettiinString.subt.sp1(p2-p1)letstartsubsi=fst(offsetsubsi)letstopsubsi=snd(offsetsubsi)lettestti=if2*i>=Array.lengtht.marksthenfalseelseletidx=t.marks.(2*i)inidx<>-1letget_optti=iftesttithenSome(getti)elseNoneletdummy_offset=(-1,-1)letall_offsett=letres=Array.maket.gcountdummy_offsetinfori=0toArray.lengtht.marks/2-1doletm1=t.marks.(2*i)inifm1<>-1thenbeginletp1=t.gpos.(m1)inletp2=t.gpos.(t.marks.(2*i+1))inres.(i)<-(p1,p2)enddone;resletdummy_string=""letallt=letres=Array.maket.gcountdummy_stringinfori=0toArray.lengtht.marks/2-1doletm1=t.marks.(2*i)inifm1<>-1thenbeginletp1=t.gpos.(m1)inletp2=t.gpos.(t.marks.(2*i+1))inres.(i)<-String.subt.sp1(p2-p1)enddone;resletppfmtt=letmatches=letoffsets=all_offsettinletstrs=alltinArray.to_list(Array.init(Array.lengthstrs)(funi->strs.(i),offsets.(i)))inletopenFmtinletpp_matchfmt(str,(start,stop))=fprintffmt"@[(%s (%d %d))@]"strstartstopinsexpfmt"Group"(listpp_match)matchesletnb_groupst=t.gcount