module Parser.Locations (
File_path_and_location (..),
Location,
With_location (..),
init_location,
next_char,
next_line,
write_file_path_and_location,
write_location) where
import Parser.Utilities
deriving instance Eq Location
deriving instance Ord Location
deriving instance Show File_path_and_location
deriving instance Show Location
deriving instance Show t => Show (With_location t)
data File_path_and_location = File_path_and_location File_path Location
data Location = Location Integer Integer
data With_location t = With_location Location t
init_location :: Location
init_location :: Location
init_location = Integer -> Integer -> Location
Location Integer
1 Integer
1
next_char :: Location -> Location
next_char :: Location -> Location
next_char (Location Integer
line Integer
char) = Integer -> Integer -> Location
Location Integer
line (Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
char)
next_line :: Location -> Location
next_line :: Location -> Location
next_line (Location Integer
line Integer
_) = Integer -> Integer -> Location
Location (Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
line) Integer
1
write_file_path_and_location :: File_path -> Location -> String
write_file_path_and_location :: File_path -> Location -> String
write_file_path_and_location File_path
file_path Location
location = File_path -> String
write_file_path File_path
file_path String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
":" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Location -> String
write_location Location
location
write_location :: Location -> String
write_location :: Location -> String
write_location (Location Integer
line Integer
char) = Integer -> String
forall a. Show a => a -> String
show Integer
line String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
":" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
char