-pprUserSpan :: SrcSpan -> SDoc
-pprUserSpan (SrcSpanOneLine src_path line start_col end_col)
- = hcat [ pprFastFilePath src_path, char ':',
- int line,
- char ':', int start_col
- ]
- <> if end_col - start_col <= 1
- then empty
- -- for single-character or point spans, we just output the starting
- -- column number
- else char '-' <> int (end_col-1)
-
-pprUserSpan (SrcSpanMultiLine src_path sline scol eline ecol)
- = hcat [ pprFastFilePath src_path, char ':',
- parens (int sline <> char ',' <> int scol),
- char '-',
- parens (int eline <> char ',' <>
- if ecol == 0 then int ecol else int (ecol-1))
- ]
-
-pprUserSpan (SrcSpanPoint src_path line col)
- = hcat [ pprFastFilePath src_path, char ':',
- int line,
- char ':', int col
+instance Outputable SrcSpan where
+ ppr span
+ = getPprStyle $ \ sty ->
+ if userStyle sty || debugStyle sty then
+ pprUserSpan True span
+ else
+ case span of
+ UnhelpfulSpan _ -> panic "Outputable UnhelpfulSpan"
+ RealSrcSpan s -> ppr s
+
+pprUserSpan :: Bool -> SrcSpan -> SDoc
+pprUserSpan _ (UnhelpfulSpan s) = ftext s
+pprUserSpan show_path (RealSrcSpan s) = pprUserRealSpan show_path s
+
+pprUserRealSpan :: Bool -> RealSrcSpan -> SDoc
+pprUserRealSpan show_path (SrcSpanOneLine src_path line start_col end_col)
+ = hcat [ ppWhen show_path (pprFastFilePath src_path <> colon)
+ , int line, char ':', int start_col
+ , ppUnless (end_col - start_col <= 1)
+ (char '-' <> int (end_col-1))
+ -- For single-character or point spans, we just
+ -- output the starting column number
+ ]
+
+
+pprUserRealSpan show_path (SrcSpanMultiLine src_path sline scol eline ecol)
+ = hcat [ ppWhen show_path (pprFastFilePath src_path <> colon)
+ , parens (int sline <> char ',' <> int scol)
+ , char '-'
+ , parens (int eline <> char ',' <>
+ if ecol == 0 then int ecol else int (ecol-1))