Distribution.Parsec.Class

Cabal-2.2.0.0: A framework for packaging Haskell software

Safe Haskell | None
Language | Haskell2010

Distribution.Parsec.Class

Contents

- CabalParsing & warnings
- Utilities

Synopsis

- class Parsec a where
- newtype ParsecParser a = PP {
  - unPP :: CabalSpecVersion -> Parsec FieldLineStream [PWarning] a
  }
- runParsecParser :: ParsecParser a -> FilePath -> FieldLineStream -> Either ParseError a
- simpleParsec :: Parsec a => String -> Maybe a
- lexemeParsec :: (CabalParsing m, Parsec a) => m a
- eitherParsec :: Parsec a => String -> Either String a
- explicitEitherParsec :: ParsecParser a -> String -> Either String a
- class (CharParsing m, MonadPlus m) => CabalParsing m where
- data PWarnType
  - = PWTOther
  - | PWTUTF
  - | PWTBoolCase
  - | PWTVersionTag
  - | PWTNewSyntax
  - | PWTOldSyntax
  - | PWTDeprecatedField
  - | PWTInvalidSubsection
  - | PWTUnknownField
  - | PWTUnknownSection
  - | PWTTrailingFields
  - | PWTExtraMainIs
  - | PWTExtraTestModule
  - | PWTExtraBenchmarkModule
  - | PWTLexNBSP
  - | PWTLexBOM
  - | PWTLexTab
  - | PWTQuirkyCabalFile
  - | PWTDoubleDash
  - | PWTMultipleSingularField
  - | PWTBuildTypeDefault
  - | PWTVersionLeadingZeros
- parsecToken :: CabalParsing m => m String
- parsecToken' :: CabalParsing m => m String
- parsecFilePath :: CabalParsing m => m FilePath
- parsecQuoted :: CabalParsing m => m a -> m a
- parsecMaybeQuoted :: CabalParsing m => m a -> m a
- parsecCommaList :: CabalParsing m => m a -> m [a]
- parsecLeadingCommaList :: CabalParsing m => m a -> m [a]
- parsecOptCommaList :: CabalParsing m => m a -> m [a]
- parsecStandard :: (CabalParsing m, Parsec ver) => (ver -> String -> a) -> m a
- parsecUnqualComponentName :: CabalParsing m => m String

# Documentation

class Parsec a where Source #

Class for parsing with `parsec`. Mainly used for `.cabal` file fields.

Minimal complete definition

parsec

Methods

parsec :: CabalParsing m => m a Source #

Instances

Parsec Bool Source # |
Instance details Methods parsec :: CabalParsing m => m Bool Source #
Parsec Version Source # |
Instance details Methods parsec :: CabalParsing m => m Version Source #
Parsec VersionRange Source # |
Instance details Methods parsec :: CabalParsing m => m VersionRange Source #
Parsec RepoType Source # |
Instance details Methods parsec :: CabalParsing m => m RepoType Source #
Parsec RepoKind Source # |
Instance details Methods parsec :: CabalParsing m => m RepoKind Source #
Parsec PkgconfigName Source # |
Instance details Methods parsec :: CabalParsing m => m PkgconfigName Source #
Parsec ForeignLibType Source # |
Instance details Methods parsec :: CabalParsing m => m ForeignLibType Source #
Parsec ForeignLibOption Source # |
Instance details Methods parsec :: CabalParsing m => m ForeignLibOption Source #
Parsec ExecutableScope Source # |
Instance details Methods parsec :: CabalParsing m => m ExecutableScope Source #
Parsec ComponentId Source # |
Instance details Methods parsec :: CabalParsing m => m ComponentId Source #
Parsec BuildType Source # |
Instance details Methods parsec :: CabalParsing m => m BuildType Source #
Parsec AbiHash Source # |
Instance details Methods parsec :: CabalParsing m => m AbiHash Source #
Parsec Platform Source # |
Instance details Methods parsec :: CabalParsing m => m Platform Source #
Parsec Arch Source # |
Instance details Methods parsec :: CabalParsing m => m Arch Source #
Parsec OS Source # |
Instance details Methods parsec :: CabalParsing m => m OS Source #
Parsec LicenseRef Source # |
Instance details Methods parsec :: CabalParsing m => m LicenseRef Source #
Parsec LicenseId Source # |
    >>> eitherParsec "BSD-3-Clause" :: Either String LicenseId
    Right BSD_3_Clause
    >>> eitherParsec "BSD3" :: Either String LicenseId
    Left "...Unknown SPDX license identifier: 'BSD3' Do you mean BSD-3-Clause?"
Instance details Methods parsec :: CabalParsing m => m LicenseId Source #
Parsec LicenseExceptionId Source # |
Instance details Methods parsec :: CabalParsing m => m LicenseExceptionId Source #
Parsec SimpleLicenseExpression Source # |
Instance details Methods parsec :: CabalParsing m => m SimpleLicenseExpression Source #
Parsec LicenseExpression Source # |
Instance details Methods parsec :: CabalParsing m => m LicenseExpression Source #
Parsec License Source # |
    >>> eitherParsec "BSD-3-Clause AND MIT" :: Either String License
    Right (License (EAnd (ELicense (ELicenseId BSD_3_Clause) Nothing) (ELicense (ELicenseId MIT) Nothing)))
    >>> eitherParsec "NONE" :: Either String License
    Right NONE
Instance details Methods parsec :: CabalParsing m => m License Source #
Parsec ModuleName Source # |
Instance details Methods parsec :: CabalParsing m => m ModuleName Source #
Parsec ModuleRenaming Source # |
Instance details Methods parsec :: CabalParsing m => m ModuleRenaming Source #
Parsec IncludeRenaming Source # |
Instance details Methods parsec :: CabalParsing m => m IncludeRenaming Source #
Parsec TestType Source # |
Instance details Methods parsec :: CabalParsing m => m TestType Source #
Parsec PkgconfigDependency Source # |
Instance details Methods parsec :: CabalParsing m => m PkgconfigDependency Source #
Parsec BenchmarkType Source # |
Instance details Methods parsec :: CabalParsing m => m BenchmarkType Source #
Parsec License Source # |
Instance details Methods parsec :: CabalParsing m => m License Source #
Parsec Extension Source # |
Instance details Methods parsec :: CabalParsing m => m Extension Source #
Parsec Language Source # |
Instance details Methods parsec :: CabalParsing m => m Language Source #
Parsec CompilerFlavor Source # |
Instance details Methods parsec :: CabalParsing m => m CompilerFlavor Source #
Parsec FilePathNT Source # |
Instance details Methods parsec :: CabalParsing m => m FilePathNT Source #
Parsec FreeText Source # |
Instance details Methods parsec :: CabalParsing m => m FreeText Source #
Parsec TestedWith Source # |
Instance details Methods parsec :: CabalParsing m => m TestedWith Source #
Parsec SpecLicense Source # |
Instance details Methods parsec :: CabalParsing m => m SpecLicense Source #
Parsec SpecVersion Source # |
Instance details Methods parsec :: CabalParsing m => m SpecVersion Source #
Parsec Token' Source # |
Instance details Methods parsec :: CabalParsing m => m Token' Source #
Parsec Token Source # |
Instance details Methods parsec :: CabalParsing m => m Token Source #
Parsec PackageName Source # |
Instance details Methods parsec :: CabalParsing m => m PackageName Source #
Parsec UnqualComponentName Source # |
Instance details Methods parsec :: CabalParsing m => m UnqualComponentName Source #
Parsec DefUnitId Source # |
Instance details Methods parsec :: CabalParsing m => m DefUnitId Source #
Parsec UnitId Source # | The textual format for `UnitId` coincides with the format GHC accepts for `-package-id`.
Instance details Methods parsec :: CabalParsing m => m UnitId Source #
Parsec Module Source # |
Instance details Methods parsec :: CabalParsing m => m Module Source #
Parsec OpenModule Source # |
    >>> eitherParsec "Includes2-0.1.0.0-inplace-mysql:Database.MySQL" :: Either String OpenModule
    Right (OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "Includes2-0.1.0.0-inplace-mysql"})) (ModuleName ["Database","MySQL"]))
Instance details Methods parsec :: CabalParsing m => m OpenModule Source #
Parsec OpenUnitId Source # |
    >>> eitherParsec "foobar" :: Either String OpenUnitId
    Right (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "foobar"}))
    >>> eitherParsec "foo[Str=text-1.2.3:Data.Text.Text]" :: Either String OpenUnitId
    Right (IndefFullUnitId (ComponentId "foo") (fromList [(ModuleName ["Str"],OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "text-1.2.3"})) (ModuleName ["Data","Text","Text"]))]))
Instance details Methods parsec :: CabalParsing m => m OpenUnitId Source #
Parsec ModuleReexport Source # |
Instance details Methods parsec :: CabalParsing m => m ModuleReexport Source #
Parsec Mixin Source # |
Instance details Methods parsec :: CabalParsing m => m Mixin Source #
Parsec ExeDependency Source # |
Instance details Methods parsec :: CabalParsing m => m ExeDependency Source #
Parsec Dependency Source # |
Instance details Methods parsec :: CabalParsing m => m Dependency Source #
Parsec MungedPackageName Source # |
Instance details Methods parsec :: CabalParsing m => m MungedPackageName Source #
Parsec AbiDependency Source # |
Instance details Methods parsec :: CabalParsing m => m AbiDependency Source #
Parsec LegacyExeDependency Source # |
Instance details Methods parsec :: CabalParsing m => m LegacyExeDependency Source #
Parsec LibVersionInfo Source # |
Instance details Methods parsec :: CabalParsing m => m LibVersionInfo Source #
Parsec FlagName Source # |
Instance details Methods parsec :: CabalParsing m => m FlagName Source #
Parsec ExposedModule Source # |
Instance details Methods parsec :: CabalParsing m => m ExposedModule Source #
Parsec TestShowDetails Source # |
Instance details Methods parsec :: CabalParsing m => m TestShowDetails Source #
Parsec a => Parsec (Identity a) Source # |
Instance details Methods parsec :: CabalParsing m => m (Identity a) Source #
Parsec a => Parsec (MQuoted a) Source # |
Instance details Methods parsec :: CabalParsing m => m (MQuoted a) Source #
(Newtype b a, Sep sep, Parsec b) => Parsec (List sep b a) Source # |
Instance details Methods parsec :: CabalParsing m => m (List sep b a) Source #

newtype ParsecParser a Source #

Constructors

PP |
Fields unPP :: CabalSpecVersion -> Parsec FieldLineStream [PWarning] a

Instances

Monad ParsecParser Source # |
Instance details Methods (>>=) :: ParsecParser a -> (a -> ParsecParser b) -> ParsecParser b Source # (>>) :: ParsecParser a -> ParsecParser b -> ParsecParser b Source # return :: a -> ParsecParser a Source # fail :: String -> ParsecParser a Source #
Functor ParsecParser Source # |
Instance details Methods fmap :: (a -> b) -> ParsecParser a -> ParsecParser b Source # (<$) :: a -> ParsecParser b -> ParsecParser a Source #
MonadFail ParsecParser Source # |
Instance details Methods fail :: String -> ParsecParser a Source #
Applicative ParsecParser Source # |
Instance details Methods pure :: a -> ParsecParser a Source # (<*>) :: ParsecParser (a -> b) -> ParsecParser a -> ParsecParser b Source # liftA2 :: (a -> b -> c) -> ParsecParser a -> ParsecParser b -> ParsecParser c Source # (*>) :: ParsecParser a -> ParsecParser b -> ParsecParser b Source # (<*) :: ParsecParser a -> ParsecParser b -> ParsecParser a Source #
Alternative ParsecParser Source # |
Instance details Methods empty :: ParsecParser a Source # (<|>) :: ParsecParser a -> ParsecParser a -> ParsecParser a Source # some :: ParsecParser a -> ParsecParser [a] Source # many :: ParsecParser a -> ParsecParser [a] Source #
MonadPlus ParsecParser Source # |
Instance details Methods mzero :: ParsecParser a Source # mplus :: ParsecParser a -> ParsecParser a -> ParsecParser a Source #
Parsing ParsecParser Source # |
Instance details Methods try :: ParsecParser a -> ParsecParser a Source # (<?>) :: ParsecParser a -> String -> ParsecParser a Source # skipMany :: ParsecParser a -> ParsecParser () Source # skipSome :: ParsecParser a -> ParsecParser () Source # unexpected :: String -> ParsecParser a Source # eof :: ParsecParser () Source # notFollowedBy :: Show a => ParsecParser a -> ParsecParser () Source #
CharParsing ParsecParser Source # |
Instance details Methods satisfy :: (Char -> Bool) -> ParsecParser Char Source # char :: Char -> ParsecParser Char Source # notChar :: Char -> ParsecParser Char Source # anyChar :: ParsecParser Char Source # string :: String -> ParsecParser String Source # text :: Text -> ParsecParser Text Source #
CabalParsing ParsecParser Source # |
Instance details Methods parsecWarning :: PWarnType -> String -> ParsecParser () Source # parsecHaskellString :: ParsecParser String Source # askCabalSpecVersion :: ParsecParser CabalSpecVersion Source #

runParsecParser :: ParsecParser a -> FilePath -> FieldLineStream -> Either ParseError a Source #

Run `ParsecParser` with `cabalSpecLatest`.

simpleParsec :: Parsec a => String -> Maybe a Source #

Parse a `String` with `lexemeParsec`.

lexemeParsec :: (CabalParsing m, Parsec a) => m a Source #

`parsec` could consume trailing spaces, this function will consume.

eitherParsec :: Parsec a => String -> Either String a Source #

Parse a `String` with `lexemeParsec`.

explicitEitherParsec :: ParsecParser a -> String -> Either String a Source #

Parse a `String` with given `ParsecParser`. Trailing whitespace is accepted.

# CabalParsing & warnings

class (CharParsing m, MonadPlus m) => CabalParsing m where Source #

Parsing class which

- can report Cabal parser warnings.
- knows `cabal-version` we work with

Minimal complete definition

parsecWarning, askCabalSpecVersion

Methods

parsecWarning :: PWarnType -> String -> m () Source #

parsecHaskellString :: m String Source #

askCabalSpecVersion :: m CabalSpecVersion Source #

Instances

CabalParsing ParsecParser Source # |
Instance details Methods parsecWarning :: PWarnType -> String -> ParsecParser () Source # parsecHaskellString :: ParsecParser String Source # askCabalSpecVersion :: ParsecParser CabalSpecVersion Source #
t ~ Char => CabalParsing (Parser r t) Source # |
Instance details Methods parsecWarning :: PWarnType -> String -> Parser r t () Source # parsecHaskellString :: Parser r t String Source # askCabalSpecVersion :: Parser r t CabalSpecVersion Source #

data PWarnType Source #

Type of parser warning. We do classify warnings.

Different application may decide not to show some, or have fatal behaviour on others

Constructors

PWTOther | Unclassified warning
PWTUTF | Invalid UTF encoding
PWTBoolCase | `true` or `false`, not `True` or `False`
PWTVersionTag | there are version with tags
PWTNewSyntax | New syntax used, but no `cabal-version: >= 1.2` specified
PWTOldSyntax | Old syntax used, and `cabal-version >= 1.2` specified
PWTDeprecatedField |
PWTInvalidSubsection |
PWTUnknownField |
PWTUnknownSection |
PWTTrailingFields |
PWTExtraMainIs | extra main-is field
PWTExtraTestModule | extra test-module field
PWTExtraBenchmarkModule | extra benchmark-module field
PWTLexNBSP |
PWTLexBOM |
PWTLexTab |
PWTQuirkyCabalFile | legacy cabal file that we know how to patch
PWTDoubleDash | Double dash token, most likely it's a mistake - it's not a comment
PWTMultipleSingularField | e.g. name or version should be specified only once.
PWTBuildTypeDefault | Workaround for derive-package having build-type: Default. See https://github.com/haskell/cabal/issues/5020.
PWTVersionLeadingZeros | See https://github.com/haskell-infra/hackage-trustees/issues/128

Instances

Bounded PWarnType Source # |
Instance details Methods minBound :: PWarnType Source # maxBound :: PWarnType Source #
Enum PWarnType Source # |
Instance details Methods succ :: PWarnType -> PWarnType Source # pred :: PWarnType -> PWarnType Source # toEnum :: Int -> PWarnType Source # fromEnum :: PWarnType -> Int Source # enumFrom :: PWarnType -> [PWarnType] Source # enumFromThen :: PWarnType -> PWarnType -> [PWarnType] Source # enumFromTo :: PWarnType -> PWarnType -> [PWarnType] Source # enumFromThenTo :: PWarnType -> PWarnType -> PWarnType -> [PWarnType] Source #
Eq PWarnType Source # |
Instance details Methods (==) :: PWarnType -> PWarnType -> Bool # (/=) :: PWarnType -> PWarnType -> Bool #
Ord PWarnType Source # |
Instance details Methods compare :: PWarnType -> PWarnType -> Ordering # (<) :: PWarnType -> PWarnType -> Bool # (<=) :: PWarnType -> PWarnType -> Bool # (>) :: PWarnType -> PWarnType -> Bool # (>=) :: PWarnType -> PWarnType -> Bool # max :: PWarnType -> PWarnType -> PWarnType # min :: PWarnType -> PWarnType -> PWarnType #
Show PWarnType Source # |
Instance details Methods showsPrec :: Int -> PWarnType -> ShowS Source # show :: PWarnType -> String Source # showList :: [PWarnType] -> ShowS Source #
Generic PWarnType Source # |
Instance details Associated Types type Rep PWarnType :: * -> * Source # Methods from :: PWarnType -> Rep PWarnType x Source # to :: Rep PWarnType x -> PWarnType Source #
NFData PWarnType Source # |
Instance details Methods rnf :: PWarnType -> () Source #
Binary PWarnType Source # |
Instance details Methods put :: PWarnType -> Put Source # get :: Get PWarnType Source # putList :: [PWarnType] -> Put Source #
type Rep PWarnType Source # |
Instance details type Rep PWarnType = D1 (MetaData "PWarnType" "Distribution.Parsec.Common" "Cabal-2.2.0.0" False) ((((C1 (MetaCons "PWTOther" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTUTF" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "PWTBoolCase" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTVersionTag" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTNewSyntax" PrefixI False) (U1 :: * -> *)))) :+: ((C1 (MetaCons "PWTOldSyntax" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTDeprecatedField" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTInvalidSubsection" PrefixI False) (U1 :: * -> *))) :+: (C1 (MetaCons "PWTUnknownField" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTUnknownSection" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTTrailingFields" PrefixI False) (U1 :: * -> *))))) :+: (((C1 (MetaCons "PWTExtraMainIs" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTExtraTestModule" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "PWTExtraBenchmarkModule" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTLexNBSP" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTLexBOM" PrefixI False) (U1 :: * -> *)))) :+: ((C1 (MetaCons "PWTLexTab" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTQuirkyCabalFile" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTDoubleDash" PrefixI False) (U1 :: * -> *))) :+: (C1 (MetaCons "PWTMultipleSingularField" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "PWTBuildTypeDefault" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "PWTVersionLeadingZeros" PrefixI False) (U1 :: * -> *))))))

# Utilities

parsecToken :: CabalParsing m => m String Source #

    [^ ,]

parsecToken' :: CabalParsing m => m String Source #

    [^ ]

parsecFilePath :: CabalParsing m => m FilePath Source #

parsecQuoted :: CabalParsing m => m a -> m a Source #

Content isn't unquoted

parsecMaybeQuoted :: CabalParsing m => m a -> m a Source #

`parsecMaybeQuoted p = `parsecQuoted` p | p`.

parsecCommaList :: CabalParsing m => m a -> m [a] Source #

parsecLeadingCommaList :: CabalParsing m => m a -> m [a] Source #

Like `parsecCommaList` but accept leading or trailing comma.

    p (comma p)*  -- p sepBy comma
    (comma p)*    -- leading comma
    (p comma)*    -- trailing comma

parsecOptCommaList :: CabalParsing m => m a -> m [a] Source #

parsecStandard :: (CabalParsing m, Parsec ver) => (ver -> String -> a) -> m a Source #

Parse a benchmark/test-suite types.

parsecUnqualComponentName :: CabalParsing m => m String Source #