123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081openImportmoduleL=Astlib.Locationtypet=location={loc_start:Lexing.position;loc_end:Lexing.position;loc_ghost:bool;}letin_filename=letloc={pos_fname=name;pos_lnum=1;pos_bol=0;pos_cnum=-1}in{loc_start=loc;loc_end=loc;loc_ghost=true}letset_filenamelocfn=letloc_start={loc.loc_startwithpos_fname=fn}inletloc_end={loc.loc_endwithpos_fname=fn}in{locwithloc_start;loc_end}letnone=in_file"_none_"letinitlexbuffname=letopenLexinginlexbuf.lex_curr_p<-{pos_fname=fname;pos_lnum=1;pos_bol=0;pos_cnum=0}letraise_errorf?locfmt=L.raise_errorf?locfmtletreport_exception=L.report_exceptionletof_lexbuf(lexbuf:Lexing.lexbuf)={loc_start=lexbuf.lex_start_p;loc_end=lexbuf.lex_curr_p;loc_ghost=false;}letprintppft=Stdlib.Format.fprintfppf"File \"%s\", line %d, characters %d-%d:"t.loc_start.pos_fnamet.loc_start.pos_lnum(t.loc_start.pos_cnum-t.loc_start.pos_bol)(t.loc_end.pos_cnum-t.loc_start.pos_bol)typenonrec'aloc='aloc={txt:'a;loc:t}letcompare_posp1p2=letopenLexinginletcolumnp=(* Manual extract:
The difference between pos_cnum and pos_bol is the character offset
within the line (i.e. the column number, assuming each character is
one column wide). *)p.pos_cnum-p.pos_bolinmatchInt.comparep1.pos_lnump2.pos_lnumwith|0->Int.compare(columnp1)(columnp2)|n->nletmin_posp1p2=ifcompare_posp1p2<=0thenp1elsep2letmax_posp1p2=ifcompare_posp1p2>=0thenp1elsep2letcompareloc1loc2=matchcompare_posloc1.loc_startloc2.loc_startwith|0->compare_posloc1.loc_endloc2.loc_end|n->nmoduleError=structincludePpxlib_ast.Location_errorletcreatef~locfmt=Format.kasprintf(funstr->make~loc~sub:[]str)fmtendleterror_extensionf~locfmt=Format.kasprintf(funstr->Error.to_extension@@Error.make~loc~sub:[]str)fmtexceptionError=L.Errorlet()=Stdlib.Printexc.register_printer(function|Errore->Some(Error.messagee)|_->None)