module Distribution.Parsec.Common (
PError (..),
showPError,
PWarning (..),
PWarnType (..),
showPWarning,
FieldParser,
Position (..),
incPos,
retPos,
showPos,
zeroPos,
) where
import Prelude ()
import Distribution.Compat.Prelude
import System.FilePath (normalise)
import qualified Text.Parsec as Parsec
data PError = PError Position String
deriving (Show)
data PWarnType
= PWTOther
| PWTUTF
| PWTBoolCase
| PWTVersionTag
| PWTNewSyntax
| PWTOldSyntax
| PWTDeprecatedField
| PWTInvalidSubsection
| PWTUnknownField
| PWTUnknownSection
| PWTTrailingFields
| PWTExtraMainIs
| PWTExtraTestModule
| PWTExtraBenchmarkModule
| PWTLexNBSP
| PWTLexBOM
| PWTQuirkyCabalFile
deriving (Eq, Ord, Show, Enum, Bounded)
data PWarning = PWarning !PWarnType !Position String
deriving (Show)
showPWarning :: FilePath -> PWarning -> String
showPWarning fpath (PWarning _ pos msg) =
normalise fpath ++ ":" ++ showPos pos ++ ": " ++ msg
showPError :: FilePath -> PError -> String
showPError fpath (PError pos msg) =
normalise fpath ++ ":" ++ showPos pos ++ ": " ++ msg
type FieldParser = Parsec.Parsec String [PWarning]
data Position = Position
!Int
!Int
deriving (Eq, Ord, Show)
incPos :: Int -> Position -> Position
incPos n (Position row col) = Position row (col + n)
retPos :: Position -> Position
retPos (Position row _col) = Position (row + 1) 1
showPos :: Position -> String
showPos (Position row col) = show row ++ ":" ++ show col
zeroPos :: Position
zeroPos = Position 0 0