never executed always true always false
1 module Reporting.Region where
2
3 import Prelude ()
4 import Relude
5
6 import Text.Show (showParen, showString, showsPrec)
7
8 import qualified Data.String as String
9 import qualified Text.Parsec.Pos as Parsec
10
11
12 data Region = Region
13 { start :: Position
14 , end :: Position
15 }
16 deriving (Eq)
17
18
19 instance Show Region where
20 showsPrec p r = showParen (p > 10) $
21 showString $ String.unwords
22 [ "at"
23 , show (line $ start r)
24 , show (column $ start r)
25 , show (line $ end r)
26 , show (column $ end r)
27 ]
28
29
30 data Position = Position
31 { line :: Int
32 , column :: Int
33 }
34 deriving (Eq, Show)
35
36
37 fromSourcePos :: Parsec.SourcePos -> Position
38 fromSourcePos sourcePos =
39 Position
40 (Parsec.sourceLine sourcePos)
41 (Parsec.sourceColumn sourcePos)
42
43
44 merge :: Region -> Region -> Region
45 merge (Region start _) (Region _ end) =
46 Region start end
47
48
49 -- TO STRING
50
51 toString :: Region -> String
52 toString (Region start end) =
53 case line start == line end of
54 False ->
55 "between lines " ++ show (line start)
56 ++ " and " ++ show (line end)
57
58 True ->
59 "on line " ++ show (line end) ++ ", column "
60 ++ show (column start) ++ " to " ++ show (column end)