{-# OPTIONS_GHC -Wall #-} {-# LANGUAGE StandaloneDeriving #-} {-| Description: Locations. * Locations * Writing locations -} module Parser.Line_and_char ( L (..), Line_and_char, init_line_and_char, next_char, next_line, write_file_name_and_line_and_char, write_line_and_char) where -- | Add a location to any type. data L t = L Line_and_char t -- | Locations. 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 1 1 -- | Move one character to the right. next_char :: Line_and_char -> Line_and_char next_char (Line_and_char line char) = Line_and_char line (1 + char) -- | Move to the beginning of the next line. next_line :: Line_and_char -> Line_and_char next_line (Line_and_char line _) = Line_and_char (1 + line) 1 -- | Write the location with the file name. write_file_name_and_line_and_char :: String -> Line_and_char -> String write_file_name_and_line_and_char file_name (Line_and_char line char) = file_name ++ ":" ++ show line ++ ":" ++ show char -- | Write the location without a file name. write_line_and_char :: Line_and_char -> String write_line_and_char (Line_and_char line char) = show line ++ ":" ++ show char