% $Id: Position.oz,v 1.5 2012/01/11 22:19:10 leavens Exp $ % AUTHOR: Gary T. Leavens declare % In a long position, the first 3 are the starting spot, last 3 are the ending % ::= pos( ) % | pos( ) % Position helpers fun {MakeLongPos Pos1 Pos2} pos(Pos1.1 Pos1.2 Pos1.3 Pos2.1 Pos2.2 Pos2.3) end fun {PositionMsg POS} %% ENSURES: Result is a virtual string describing an error position case POS of pos(FileName Line Column) then case FileName of '' then '' else 'File "'#FileName#'", ' end #'line '#{Value.toVirtualString Line 2 2} #', column '#{Value.toVirtualString Column 2 2} [] pos(FN1 L1 C1 FN2 L2 C2) then case FN1 of '' then '' else 'File "'#FN1#'", ' end #'line '#{Value.toVirtualString L1 2 2} #', column '#{Value.toVirtualString C1 2 2} #' to '#if FN1 == FN2 then '' else 'File "'#FN2#'", 'end #'line '#{Value.toVirtualString L2 2 2} #', column '#{Value.toVirtualString C2 2 2} end end % The position of a token, all tokens from parser should have a pos field fun {GetPos Tok} Tok.pos end % The position at the start of position (first triple in a long pos) fun {StartingPos C} case C of pos(F L C ...) then pos(F L C) end end % Add the given increment to the column fun {AddToPosColumn C N} case C of pos(F L C) then pos(F L C+N) [] pos(F1 L1 C1 F2 L2 C2) then pos(F1 L1 C1+N F2 L2 C2+N) end end % The position at the end of a position (the second triple in a long pos) fun {EndingPos C} case C of pos(_ _ _ F L Col) then pos(F L Col) [] pos(_ _ _) then C end end % Return the position of a pattern fun {GetPatPos Pat} Pat.pos end % Return the starting position of a pattern fun {GetPatStartPos Pat} {StartingPos {GetPatPos Pat}} end % Return the ending position of a pattern fun {GetPatEndPos Pat} {EndingPos {GetPatPos Pat}} end % Return the position of a statement fun {GetStmtPos Stmt} Stmt.pos end % Return the starting position of a statement fun {GetStmtStartPos Stmt} {StartingPos {GetStmtPos Stmt}} end % Return the ending position of a statement fun {GetStmtEndPos Stmt} {EndingPos {GetStmtPos Stmt}} end % Get the position of an expression fun {GetExpPos Exp} Exp.pos end % Return the starting position of an expression fun {GetExpStartPos Exp} {StartingPos {GetExpPos Exp}} end % Return the ending position of an expression fun {GetExpEndPos Exp} {EndingPos {GetExpPos Exp}} end