Cabal-3.2.1.0: A framework for packaging Haskell software
Safe Haskell None
Language Haskell2010

Distribution.Fields

Description

Utilitiies to work with .cabal like file structure.

Synopsis

Types

data Field ann Source #

A Cabal-like file consists of a series of fields ( foo: bar ) and sections ( library ... ).

Constructors

Field !( Name ann) [ FieldLine ann]
Section !( Name ann) [ SectionArg ann] [ Field ann]

Instances

Instances details
Functor Field Source #
Instance details

Defined in Distribution.Fields.Field

Foldable Field Source #
Instance details

Defined in Distribution.Fields.Field

Traversable Field Source #
Instance details

Defined in Distribution.Fields.Field

Eq ann => Eq ( Field ann) Source #
Instance details

Defined in Distribution.Fields.Field

Show ann => Show ( Field ann) Source #
Instance details

Defined in Distribution.Fields.Field

data Name ann Source #

A field name.

Invariant : ByteString is lower-case ASCII.

Constructors

Name !ann ! FieldName

Instances

Instances details
Functor Name Source #
Instance details

Defined in Distribution.Fields.Field

Foldable Name Source #
Instance details

Defined in Distribution.Fields.Field

Traversable Name Source #
Instance details

Defined in Distribution.Fields.Field

Eq ann => Eq ( Name ann) Source #
Instance details

Defined in Distribution.Fields.Field

Show ann => Show ( Name ann) Source #
Instance details

Defined in Distribution.Fields.Field

data FieldLine 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.

Constructors

FieldLine !ann ! ByteString

Instances

Instances details
Functor FieldLine Source #
Instance details

Defined in Distribution.Fields.Field

Foldable FieldLine Source #
Instance details

Defined in Distribution.Fields.Field

Traversable FieldLine Source #
Instance details

Defined in Distribution.Fields.Field

Eq ann => Eq ( FieldLine ann) Source #
Instance details

Defined in Distribution.Fields.Field

Show ann => Show ( FieldLine ann) Source #
Instance details

Defined in Distribution.Fields.Field

data SectionArg ann Source #

Section arguments, e.g. name of the library

Constructors

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

Instances details
Functor SectionArg Source #
Instance details

Defined in Distribution.Fields.Field

Foldable SectionArg Source #
Instance details

Defined in Distribution.Fields.Field

Traversable SectionArg Source #
Instance details

Defined in Distribution.Fields.Field

Eq ann => Eq ( SectionArg ann) Source #
Instance details

Defined in Distribution.Fields.Field

Show ann => Show ( SectionArg ann) Source #
Instance details

Defined in Distribution.Fields.Field

Grammar and parsing

ParseResult

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.

parseString Source #

Arguments

:: ( ByteString -> ParseResult a)

File contents to final value parser

-> Verbosity

Verbosity level

-> String

File name

-> ByteString
-> IO a

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

Warnings

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 .

Instances

Instances details
Bounded PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Enum PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Eq PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Ord PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Show PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Generic PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

Binary PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

NFData PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

type Rep PWarnType Source #
Instance details

Defined in Distribution.Parsec.Warning

type Rep PWarnType = D1 (' MetaData "PWarnType" "Distribution.Parsec.Warning" "Cabal-3.2.1.0-3w1fQQbNnuQ5xlFGwVXcPy" ' 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 ))))))

data PWarning Source #

Parser warning.

Errors

Pretty printing

data PrettyField ann Source #

Instances

Instances details
Functor PrettyField Source #
Instance details

Defined in Distribution.Fields.Pretty

Foldable PrettyField Source #
Instance details

Defined in Distribution.Fields.Pretty

Traversable PrettyField Source #
Instance details

Defined in Distribution.Fields.Pretty

showFields :: (ann -> [ String ]) -> [ 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 #

Arguments

:: 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