HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleCabal-syntax-3.12.1.0Haskell2010

Distribution.Fields

Utilities to work with .cabal like file structure.

  • 11 types
  • 12 values

Types

5 declarations
datadata Field ann
#

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

Constructors

Instances7Functor, Foldable, Traversable, Foldable1, Eq, Ord, …
  • Functor FieldDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable FieldDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Traversable FieldDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable1 FieldDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Eq ann => Eq (Field ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Ord ann => Ord (Field ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Show ann => Show (Field ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
datadata Name ann
#

A field name.

Invariant: ByteString is lower-case ASCII.

Constructors

Instances7Functor, Foldable, Traversable, Foldable1, Eq, Ord, …
  • Functor NameDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable NameDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Traversable NameDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable1 NameDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Eq ann => Eq (Name ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Ord ann => Ord (Name ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Show ann => Show (Name ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
datadata FieldLine ann
#

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

Instances7Functor, Foldable, Traversable, Foldable1, Eq, Ord, …
  • Functor FieldLineDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable FieldLineDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Traversable FieldLineDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Foldable1 FieldLineDefined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Eq ann => Eq (FieldLine ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Ord ann => Ord (FieldLine ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
  • Show ann => Show (FieldLine ann)Defined in Cabal-syntax-3.12.1.0 · Distribution.Fields.Field
datadata SectionArg ann
#

Section arguments, e.g. name of the library

Constructors

Instances7Functor, Foldable, Traversable, Foldable1, Eq, Ord, …

Grammar and parsing

2 declarations

Parse cabal style ByteString into list of Fields, i.e. the cabal AST.

readFields assumes that input ByteString is valid UTF8, specifically it doesn't validate that file is valid UTF8. Therefore bytestrings inside returned Field will be invalid as UTF8 if the input were.

Example1 expression
readFields "foo: \223"Right [Field (Name (Position 1 1) "foo") [FieldLine (Position 1 6) "\223"]]

readFields won't (necessarily) fail on invalid UTF8 data, but the reported positions may be off.

You may get weird errors on non-UTF8 input, for example readFields will fail on latin1 encoded non-breaking space:

Example1 expression
isLeft (readFields "\xa0 foo: bar")True

That is rejected because parser thinks \xa0 is a section name, and section arguments may not contain colon. If there are just latin1 non-breaking spaces, they become part of the name:

Example1 expression
readFields "\xa0\&foo: bar"Right [Field (Name (Position 1 1) "\160foo") [FieldLine (Position 1 7) "bar"]]

The UTF8 non-breaking space is accepted as an indentation character (but warned about by readFields').

Example1 expression
readFields' "\xc2\xa0 foo: bar"Right ([Field (Name (Position 1 3) "foo") [FieldLine (Position 1 8) "bar"]],[LexWarning LexWarningNBSP (Position 1 1)])

ParseResult

newtypenewtype ParseResult a
#

A monad with failure and accumulating errors and warnings.

Instances3Monad, Functor, Applicative

Warnings

datadata PWarnType
#

Type of parser warning. We do classify warnings.

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

Constructors

Instances9Bounded, Enum, Eq, Ord, Show, Generic, …
datadata PWarning
#

Parser warning.

Instances7Eq, Ord, Show, Generic, NFData, Binary, …

Errors

datadata PError
#

Parser error.

Constructors

Instances5Show, Generic, NFData, Binary, Rep

Pretty printing

3 declarations
valueshowFields :: (ann -> CommentPosition) -> [PrettyField ann] -> String
#

Prettyprint a list of fields.

Note: the first argument should return Strings 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