add_line_col_offset_to_position(Span,0,C,R) :- !, add_col_offset_to_position(Span,C,R).
add_line_col_offset_to_position(p3(Line,Scol,Ecol),LineOffset,ColOffset,p3(L2,S2,E2)) :- !,
L2 is Line+LineOffset, S2 is ColOffset+1, % column numbers start at 1
E2 is Ecol-Scol+ColOffset.
add_line_col_offset_to_position(p4(File,Line,Scol,Ecol),LineOffset,ColOffset,p4(File,L2,S2,E2)) :- !,
L2 is Line+LineOffset, S2 is ColOffset+1, E2 is Ecol-Scol+ColOffset+1.
add_line_col_offset_to_position(p5(FN,Srow,Scol,Srow,Ecol),LineOffset,ColOffset,p4(FN,L2,S2,E2)) :- !,
L2 is Srow+LineOffset, S2 is ColOffset+1, E2 is Ecol-Scol+ColOffset+1.
add_line_col_offset_to_position(p5(FN,Srow,_Scol,Erow,Ecol),LineOffset,ColOffset,p5(FN,SL2,S2,EL2,Ecol)) :- !,
SL2 is Srow+LineOffset, EL2 is Erow+LineOffset, S2 is ColOffset+1.
add_line_col_offset_to_position(pos(BC,FN,Srow,Scol,Srow,Ecol),LineOffset,ColOffset,pos(BC,FN,L2,S2,L2,E2)) :- !,
L2 is Srow+LineOffset, S2 is ColOffset+1, E2 is Ecol-Scol+ColOffset+1.
add_line_col_offset_to_position(pos(BC,FN,Srow,_Scol,Erow,Ecol),LineOffset,ColOffset,pos(BC,FN,SL2,S2,EL2,Ecol)) :- !,
SL2 is Srow+LineOffset, EL2 is Erow+LineOffset, S2 is ColOffset+1.
add_line_col_offset_to_position(pos_context(Span,C,S2),LineOffset,ColOffset,pos_context(Res,C,S2)) :- !,
add_line_col_offset_to_position(Span,LineOffset,ColOffset,Res).
add_line_col_offset_to_position(Span,_,_,Res) :- is_position(Span),!,Res=Span.
add_line_col_offset_to_position(Span,LineOffset,ColOffset,Span) :-
write(cannot_add_offset_to_unknown_span(LineOffset,ColOffset,Span)),nl.