{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE StandaloneDeriving #-}
{-|
Description: Locations of elements in a text file

* Locations of elements in a text file
* Writing locations
-}
module Parser.Line_and_char (L (..), Line_and_char, init_line_and_char, next_char, next_line, write_line_and_char) where
  -- | Add a location to any type.

  data L t = L Line_and_char t
  -- | The location of an element in a text file.

  data Line_and_char = Line_and_char Integer Integer
  deriving instance Eq Line_and_char
  deriving instance Ord Line_and_char
  deriving instance Show t => Show (L t)
  deriving instance Show Line_and_char
  -- | First line, first character.

  init_line_and_char :: Line_and_char
  init_line_and_char :: Line_and_char
init_line_and_char = Integer -> Integer -> Line_and_char
Line_and_char Integer
1 Integer
1
  -- | Move one character to the right.

  next_char :: Line_and_char -> Line_and_char
  next_char :: Line_and_char -> Line_and_char
next_char (Line_and_char Integer
line Integer
char) = Integer -> Integer -> Line_and_char
Line_and_char Integer
line (Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
char)
  -- | Move to the beginning of the next line.

  next_line :: Line_and_char -> Line_and_char
  next_line :: Line_and_char -> Line_and_char
next_line (Line_and_char Integer
line Integer
_) = Integer -> Integer -> Line_and_char
Line_and_char (Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
line) Integer
1
  -- | Write the location with a colon between line and character number.

  write_line_and_char :: Line_and_char -> String
  write_line_and_char :: Line_and_char -> String
write_line_and_char (Line_and_char Integer
line Integer
char) = Integer -> String
forall a. Show a => a -> String
show Integer
line String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
char