1234567891011121314151617181920212223242526272829303132333435363738394041424344454647(* for lexing positions:
- lnum starts from 1
- cnum starts from 0
- pos_bol is the position of the first character of the line
for absolute pos:
- row starts from 1
- col starts from 1
for relative pos, obviously 0 means same position
*)(* operations that make sense for both absolute and relative positions *)modulePos=structtypet={row:int;col:int}letsexp_of_t{row;col}=Type.Atom(Printf.sprintf"%d:%d"rowcol)letaddt1t2={row=t1.row+t2.row;col=t1.col+t2.col}letsubt1t2={row=t1.row-t2.row;col=t1.col-t2.col}letcompare{row=r1;col=c1}{row=r2;col=c2}=ifr1=r2thenc1-c2elser1-r2;;letgeqt1t2=comparet1t2>=0endmoduleRelative=structincludePosletzero={row=0;col=0}endmoduleAbsolute=structincludePosletorigin={row=1;col=1}letof_lexing{Lexing.pos_lnum;pos_cnum;pos_bol;pos_fname=_}={row=pos_lnum;col=pos_cnum-pos_bol+1};;letdiff=subend