Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities to work with .cabal
like file structure.
Synopsis
- data Field ann
- data Name ann = Name !ann !FieldName
- data FieldLine ann = FieldLine !ann !ByteString
- data SectionArg ann
- = SecArgName !ann !ByteString
- | SecArgStr !ann !ByteString
- | SecArgOther !ann !ByteString
- type FieldName = ByteString
- readFields :: ByteString -> Either ParseError [Field Position]
- readFields' :: ByteString -> Either ParseError ([Field Position], [LexWarning])
- data ParseResult a
- runParseResult :: ParseResult a -> ([PWarning], Either (Maybe Version, NonEmpty PError) a)
- parseWarning :: Position -> PWarnType -> String -> ParseResult ()
- parseWarnings :: [PWarning] -> ParseResult ()
- parseFailure :: Position -> String -> ParseResult ()
- parseFatalFailure :: Position -> String -> ParseResult a
- data PWarnType
- = PWTOther
- | PWTUTF
- | PWTBoolCase
- | PWTVersionTag
- | PWTNewSyntax
- | PWTOldSyntax
- | PWTDeprecatedField
- | PWTInvalidSubsection
- | PWTUnknownField
- | PWTUnknownSection
- | PWTTrailingFields
- | PWTExtraMainIs
- | PWTExtraTestModule
- | PWTExtraBenchmarkModule
- | PWTLexNBSP
- | PWTLexBOM
- | PWTLexTab
- | PWTQuirkyCabalFile
- | PWTDoubleDash
- | PWTMultipleSingularField
- | PWTBuildTypeDefault
- | PWTVersionOperator
- | PWTVersionWildcard
- | PWTSpecVersion
- | PWTEmptyFilePath
- | PWTExperimental
- data PWarning = PWarning !PWarnType !Position String
- showPWarning :: FilePath -> PWarning -> String
- data PError = PError Position String
- showPError :: FilePath -> PError -> String
- data CommentPosition
- = CommentBefore [String]
- | CommentAfter [String]
- | NoComment
- data PrettyField ann
- = PrettyField ann FieldName Doc
- | PrettySection ann FieldName [Doc] [PrettyField ann]
- | PrettyEmpty
- showFields :: (ann -> CommentPosition) -> [PrettyField ann] -> String
- genericFromParsecFields :: Applicative f => (FieldName -> [FieldLine ann] -> f Doc) -> (FieldName -> [SectionArg ann] -> f [Doc]) -> [Field ann] -> f [PrettyField ann]
- fromParsecFields :: [Field ann] -> [PrettyField ann]
Types
A Cabal-like file consists of a series of fields (foo: bar
) and sections (library ...
).
Instances
Foldable Field Source # | |
Defined in Distribution.Fields.Field fold :: Monoid m => Field m -> m Source # foldMap :: Monoid m => (a -> m) -> Field a -> m Source # foldMap' :: Monoid m => (a -> m) -> Field a -> m Source # foldr :: (a -> b -> b) -> b -> Field a -> b Source # foldr' :: (a -> b -> b) -> b -> Field a -> b Source # foldl :: (b -> a -> b) -> b -> Field a -> b Source # foldl' :: (b -> a -> b) -> b -> Field a -> b Source # foldr1 :: (a -> a -> a) -> Field a -> a Source # foldl1 :: (a -> a -> a) -> Field a -> a Source # toList :: Field a -> [a] Source # null :: Field a -> Bool Source # length :: Field a -> Int Source # elem :: Eq a => a -> Field a -> Bool Source # maximum :: Ord a => Field a -> a Source # minimum :: Ord a => Field a -> a Source # | |
Traversable Field Source # | |
Functor Field Source # | |
Show ann => Show (Field ann) Source # | |
Eq ann => Eq (Field ann) Source # | |
A field name.
Invariant: ByteString
is lower-case ASCII.
Instances
Foldable Name Source # | |
Defined in Distribution.Fields.Field fold :: Monoid m => Name m -> m Source # foldMap :: Monoid m => (a -> m) -> Name a -> m Source # foldMap' :: Monoid m => (a -> m) -> Name a -> m Source # foldr :: (a -> b -> b) -> b -> Name a -> b Source # foldr' :: (a -> b -> b) -> b -> Name a -> b Source # foldl :: (b -> a -> b) -> b -> Name a -> b Source # foldl' :: (b -> a -> b) -> b -> Name a -> b Source # foldr1 :: (a -> a -> a) -> Name a -> a Source # foldl1 :: (a -> a -> a) -> Name a -> a Source # toList :: Name a -> [a] Source # null :: Name a -> Bool Source # length :: Name a -> Int Source # elem :: Eq a => a -> Name a -> Bool Source # maximum :: Ord a => Name a -> a Source # minimum :: Ord a => Name a -> a Source # | |
Traversable Name Source # | |
Functor Name Source # | |
Show ann => Show (Name ann) Source # | |
Eq ann => Eq (Name ann) Source # | |
A line of text representing the value of a field from a Cabal file. A field may contain multiple lines.
Invariant: ByteString
has no newlines.
FieldLine !ann !ByteString |
Instances
Foldable FieldLine Source # | |
Defined in Distribution.Fields.Field fold :: Monoid m => FieldLine m -> m Source # foldMap :: Monoid m => (a -> m) -> FieldLine a -> m Source # foldMap' :: Monoid m => (a -> m) -> FieldLine a -> m Source # foldr :: (a -> b -> b) -> b -> FieldLine a -> b Source # foldr' :: (a -> b -> b) -> b -> FieldLine a -> b Source # foldl :: (b -> a -> b) -> b -> FieldLine a -> b Source # foldl' :: (b -> a -> b) -> b -> FieldLine a -> b Source # foldr1 :: (a -> a -> a) -> FieldLine a -> a Source # foldl1 :: (a -> a -> a) -> FieldLine a -> a Source # toList :: FieldLine a -> [a] Source # null :: FieldLine a -> Bool Source # length :: FieldLine a -> Int Source # elem :: Eq a => a -> FieldLine a -> Bool Source # maximum :: Ord a => FieldLine a -> a Source # minimum :: Ord a => FieldLine a -> a Source # | |
Traversable FieldLine Source # | |
Defined in Distribution.Fields.Field | |
Functor FieldLine Source # | |
Show ann => Show (FieldLine ann) Source # | |
Eq ann => Eq (FieldLine ann) Source # | |
data SectionArg ann Source #
Section arguments, e.g. name of the library
SecArgName !ann !ByteString | identifier, or something which looks like number. Also many dot numbers, i.e. "7.6.3" |
SecArgStr !ann !ByteString | quoted string |
SecArgOther !ann !ByteString | everything else, mm. operators (e.g. in if-section conditionals) |
Instances
type FieldName = ByteString Source #
Grammar and parsing
readFields :: ByteString -> Either ParseError [Field Position] Source #
Parse cabal style ByteString
into list of Field
s, i.e. the cabal AST.
readFields' :: ByteString -> Either ParseError ([Field Position], [LexWarning]) Source #
Like readFields
but also return lexer warnings
ParseResult
data ParseResult a Source #
A monad with failure and accumulating errors and warnings.
Instances
Applicative ParseResult Source # | |
Defined in Distribution.Fields.ParseResult pure :: a -> ParseResult a Source # (<*>) :: ParseResult (a -> b) -> ParseResult a -> ParseResult b Source # liftA2 :: (a -> b -> c) -> ParseResult a -> ParseResult b -> ParseResult c Source # (*>) :: ParseResult a -> ParseResult b -> ParseResult b Source # (<*) :: ParseResult a -> ParseResult b -> ParseResult a Source # | |
Functor ParseResult Source # | |
Defined in Distribution.Fields.ParseResult fmap :: (a -> b) -> ParseResult a -> ParseResult b Source # (<$) :: a -> ParseResult b -> ParseResult a Source # | |
Monad ParseResult Source # | |
Defined in Distribution.Fields.ParseResult (>>=) :: ParseResult a -> (a -> ParseResult b) -> ParseResult b Source # (>>) :: ParseResult a -> ParseResult b -> ParseResult b Source # return :: a -> ParseResult a Source # |
runParseResult :: ParseResult a -> ([PWarning], Either (Maybe Version, NonEmpty PError) a) Source #
Destruct a ParseResult
into the emitted warnings and either
a successful value or
list of errors and possibly recovered a spec-version declaration.
parseWarning :: Position -> PWarnType -> String -> ParseResult () Source #
Add a warning. This doesn't fail the parsing process.
parseWarnings :: [PWarning] -> ParseResult () Source #
Add multiple warnings at once.
parseFailure :: Position -> String -> ParseResult () Source #
Add an error, but not fail the parser yet.
For fatal failure use parseFatalFailure
parseFatalFailure :: Position -> String -> ParseResult a Source #
Add an fatal error.
Warnings
Type of parser warning. We do classify warnings.
Different application may decide not to show some, or have fatal behaviour on others
PWTOther | Unclassified warning |
PWTUTF | Invalid UTF encoding |
PWTBoolCase |
|
PWTVersionTag | there are version with tags |
PWTNewSyntax | New syntax used, but no |
PWTOldSyntax | Old syntax used, and |
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. |
PWTVersionOperator | Version operators used (without cabal-version: 1.8) |
PWTVersionWildcard | Version wildcard used (without cabal-version: 1.6) |
PWTSpecVersion | Warnings about cabal-version format. |
PWTEmptyFilePath | Empty filepath, i.e. literally "" |
PWTExperimental | Experimental feature |
Instances
Bounded PWarnType Source # | |||||
Enum PWarnType Source # | |||||
Defined in Distribution.Parsec.Warning 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 # | |||||
Generic PWarnType Source # | |||||
Defined in Distribution.Parsec.Warning
| |||||
Show PWarnType Source # | |||||
Binary PWarnType Source # | |||||
NFData PWarnType Source # | |||||
Defined in Distribution.Parsec.Warning | |||||
Eq PWarnType Source # | |||||
Ord PWarnType Source # | |||||
Defined in Distribution.Parsec.Warning | |||||
type Rep PWarnType Source # | |||||
Defined in Distribution.Parsec.Warning type Rep PWarnType = D1 ('MetaData "PWarnType" "Distribution.Parsec.Warning" "Cabal-syntax-3.11.0.0-12ab" 'False) ((((C1 ('MetaCons "PWTOther" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTUTF" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTBoolCase" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "PWTVersionTag" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTNewSyntax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTOldSyntax" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "PWTDeprecatedField" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTInvalidSubsection" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTUnknownField" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "PWTUnknownSection" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTTrailingFields" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PWTExtraMainIs" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTExtraTestModule" 'PrefixI 'False) (U1 :: Type -> Type))))) :+: (((C1 ('MetaCons "PWTExtraBenchmarkModule" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTLexNBSP" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTLexBOM" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "PWTLexTab" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTQuirkyCabalFile" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTDoubleDash" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "PWTMultipleSingularField" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PWTBuildTypeDefault" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTVersionOperator" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "PWTVersionWildcard" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTSpecVersion" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PWTEmptyFilePath" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PWTExperimental" 'PrefixI 'False) (U1 :: Type -> Type)))))) |
Parser warning.
Instances
Errors
Parser error.
Instances
Generic PError Source # | |||||
Defined in Distribution.Parsec.Error
| |||||
Show PError Source # | |||||
Binary PError Source # | |||||
NFData PError Source # | |||||
Defined in Distribution.Parsec.Error | |||||
type Rep PError Source # | |||||
Defined in Distribution.Parsec.Error type Rep PError = D1 ('MetaData "PError" "Distribution.Parsec.Error" "Cabal-syntax-3.11.0.0-12ab" 'False) (C1 ('MetaCons "PError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Position) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))) |
Pretty printing
data CommentPosition Source #
This type is used to discern when a comment block should go
before or after a cabal-like file field, otherwise it would
be hardcoded to a single position. It is often used in
conjunction with PrettyField
.
data PrettyField ann Source #
PrettyField ann FieldName Doc | |
PrettySection ann FieldName [Doc] [PrettyField ann] | |
PrettyEmpty |
Instances
Foldable PrettyField Source # | |
Defined in Distribution.Fields.Pretty fold :: Monoid m => PrettyField m -> m Source # foldMap :: Monoid m => (a -> m) -> PrettyField a -> m Source # foldMap' :: Monoid m => (a -> m) -> PrettyField a -> m Source # foldr :: (a -> b -> b) -> b -> PrettyField a -> b Source # foldr' :: (a -> b -> b) -> b -> PrettyField a -> b Source # foldl :: (b -> a -> b) -> b -> PrettyField a -> b Source # foldl' :: (b -> a -> b) -> b -> PrettyField a -> b Source # foldr1 :: (a -> a -> a) -> PrettyField a -> a Source # foldl1 :: (a -> a -> a) -> PrettyField a -> a Source # toList :: PrettyField a -> [a] Source # null :: PrettyField a -> Bool Source # length :: PrettyField a -> Int Source # elem :: Eq a => a -> PrettyField a -> Bool Source # maximum :: Ord a => PrettyField a -> a Source # minimum :: Ord a => PrettyField a -> a Source # sum :: Num a => PrettyField a -> a Source # product :: Num a => PrettyField a -> a Source # | |
Traversable PrettyField Source # | |
Defined in Distribution.Fields.Pretty traverse :: Applicative f => (a -> f b) -> PrettyField a -> f (PrettyField b) Source # sequenceA :: Applicative f => PrettyField (f a) -> f (PrettyField a) Source # mapM :: Monad m => (a -> m b) -> PrettyField a -> m (PrettyField b) Source # sequence :: Monad m => PrettyField (m a) -> m (PrettyField a) Source # | |
Functor PrettyField Source # | |
Defined in Distribution.Fields.Pretty fmap :: (a -> b) -> PrettyField a -> PrettyField b Source # (<$) :: a -> PrettyField b -> PrettyField a Source # |
showFields :: (ann -> CommentPosition) -> [PrettyField ann] -> String Source #
Prettyprint a list of fields.
Note: the first argument should return String
s without newlines
and properly prefixes (with --
) to count as comments.
This unsafety is left in place so one could generate empty lines
between comment lines.
Transformation from Field
genericFromParsecFields Source #
:: Applicative f | |
=> (FieldName -> [FieldLine ann] -> f Doc) | transform field contents |
-> (FieldName -> [SectionArg ann] -> f [Doc]) | transform section arguments |
-> [Field ann] | |
-> f [PrettyField ann] |
fromParsecFields :: [Field ann] -> [PrettyField ann] Source #
Simple variant of genericFromParsecField