module CC.Types where import CC.Pretty -- | Names of variables in the program type Name = String -- | Position in a source file; `SourcePos line column`, both zero-based data SourcePos = SourcePos Int Int deriving (Show, Read, Eq, Ord) instance Pretty SourcePos where pretty (SourcePos line col) = show (line + 1) ++ ":" ++ show (col + 1) -- | A range in the original source code (for diagnostics and debug -- information); [from, to). data SourceRange = SourceRange SourcePos SourcePos deriving (Show, Read) instance Pretty SourceRange where pretty (SourceRange from@(SourcePos fromLine fromCol) to@(SourcePos toLine toCol)) | fromLine == toLine = show (fromLine + 1) ++ ":" ++ show (fromCol + 1) ++ "-" ++ show toCol | otherwise = show from ++ "-" ++ show to class HasRange a where range :: a -> SourceRange mergeRange :: SourceRange -> SourceRange -> SourceRange mergeRange (SourceRange p1 p2) (SourceRange q1 q2) = SourceRange (min p1 q1) (max p2 q2) -- | A newtype with no-op Read and Show instances newtype RawString = RawString String instance Read RawString where readsPrec _ s = [(RawString s, "")] instance Show RawString where show (RawString s) = s