Skip to content

Commit 18bd86b

Browse files
committed
Better Show instance for SourcePos/SourceSpan
Use the derived Show instance and define separate functions for displaying SourcePos/SourceSpan values.
1 parent 062b5a5 commit 18bd86b

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/Language/PureScript/AST/SourcePos.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ data SourcePos = SourcePos
3030
-- Column number
3131
--
3232
, sourcePosColumn :: Int
33-
} deriving (Eq, D.Data, D.Typeable)
33+
} deriving (Eq, Show, D.Data, D.Typeable)
3434

35-
instance Show SourcePos where
36-
show sp = "line " ++ show (sourcePosLine sp) ++ ", column " ++ show (sourcePosColumn sp)
35+
displaySourcePos :: SourcePos -> String
36+
displaySourcePos sp =
37+
"line " ++ show (sourcePosLine sp) ++
38+
", column " ++ show (sourcePosColumn sp)
3739

3840
data SourceSpan = SourceSpan
3941
{ -- |
@@ -47,7 +49,10 @@ data SourceSpan = SourceSpan
4749
-- End of the span
4850
--
4951
, spanEnd :: SourcePos
50-
} deriving (Eq, D.Data, D.Typeable)
52+
} deriving (Eq, Show, D.Data, D.Typeable)
5153

52-
instance Show SourceSpan where
53-
show sp = spanName sp ++ " " ++ show (spanStart sp) ++ " - " ++ show (spanEnd sp)
54+
displaySourceSpan :: SourceSpan -> String
55+
displaySourceSpan sp =
56+
spanName sp ++ " " ++
57+
displaySourcePos (spanStart sp) ++ " - " ++
58+
displaySourcePos (spanEnd sp)

src/Language/PureScript/Errors.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage (if full then e else sim
439439
go (ErrorInForeignImport nm err) = paras [ line $ "Error in foreign import " ++ show nm ++ ":"
440440
, go err
441441
]
442-
go (PositionedError pos err) = paras [ line $ "Error at " ++ show pos ++ ":"
442+
go (PositionedError span err) = paras [ line $ "Error at " ++ displaySourceSpan span ++ ":"
443443
, indent $ go err
444444
]
445445

0 commit comments

Comments
 (0)