+-- | Create a 'SrcSpan' corresponding to a single point
+srcLocSpan :: SrcLoc -> SrcSpan
+srcLocSpan (UnhelpfulLoc str) = UnhelpfulSpan str
+srcLocSpan (SrcLoc file line col) = SrcSpanPoint file line col
+
+-- | Create a 'SrcSpan' between two points in a file
+mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan
+mkSrcSpan (UnhelpfulLoc str) _ = UnhelpfulSpan str
+mkSrcSpan _ (UnhelpfulLoc str) = UnhelpfulSpan str
+mkSrcSpan loc1 loc2
+ | line1 == line2 = if col1 == col2
+ then SrcSpanPoint file line1 col1
+ else SrcSpanOneLine file line1 col1 col2
+ | otherwise = SrcSpanMultiLine file line1 col1 line2 col2
+ where
+ line1 = srcLocLine loc1
+ line2 = srcLocLine loc2
+ col1 = srcLocCol loc1
+ col2 = srcLocCol loc2
+ file = srcLocFile loc1
+
+-- | Combines two 'SrcSpan' into one that spans at least all the characters
+-- within both spans. Assumes the "file" part is the same in both inputs
+combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
+combineSrcSpans (UnhelpfulSpan _) r = r -- this seems more useful
+combineSrcSpans l (UnhelpfulSpan _) = l
+combineSrcSpans start end
+ = case line1 `compare` line2 of
+ EQ -> case col1 `compare` col2 of
+ EQ -> SrcSpanPoint file line1 col1
+ LT -> SrcSpanOneLine file line1 col1 col2
+ GT -> SrcSpanOneLine file line1 col2 col1
+ LT -> SrcSpanMultiLine file line1 col1 line2 col2
+ GT -> SrcSpanMultiLine file line2 col2 line1 col1
+ where
+ line1 = srcSpanStartLine start
+ col1 = srcSpanStartCol start
+ line2 = srcSpanEndLine end
+ col2 = srcSpanEndCol end
+ file = srcSpanFile start
+\end{code}
+
+%************************************************************************
+%* *
+\subsection[SrcSpan-predicates]{Predicates}
+%* *
+%************************************************************************
+
+\begin{code}
+-- | Test if a 'SrcSpan' is "good", i.e. has precise location information