location.ml 633 B

12345678910111213141516171819202122
  1. open Printf
  2. (** wiersz x kolumna *)
  3. type position = int * int
  4. type location = | Single of position | Range of position * position
  5. let create_position row col : position = row , col
  6. let back_one_char (row, col) = if col = 0 then (row - 1, col) else (row, col -1)
  7. let start_position = function
  8. | Single pos -> pos
  9. | Range (p1, _) -> p1
  10. let end_position = function
  11. | Single pos -> pos
  12. | Range (_, p2) -> p2
  13. let sprintf_position (row, col) = sprintf "(%d, %d)" row col
  14. let sprintf_location = function
  15. |Single pos -> sprintf_position pos
  16. |Range (p1, p2) -> sprintf "%s-%s" (sprintf_position p1) (sprintf_position p2)