Cabal-1.17.0: A framework for packaging Haskell software

Portabilityportable
Maintainercabal-devel@haskell.org
Safe HaskellNone

Distribution.ParseUtils

Description

Utilities for parsing PackageDescription and InstalledPackageInfo.

The .cabal file format is not trivial, especially with the introduction of configurations and the section syntax that goes with that. This module has a bunch of parsing functions that is used by the .cabal parser and a couple others. It has the parsing framework code and also little parsers for many of the formats we get in various .cabal file fields, like module names, comma separated lists etc.

Synopsis

Documentation

data Field Source

Constructors

F LineNo String String

A regular property: value field

Section LineNo String String [Field]

A section with a name and possible parameter. The syntactic structure is:

   sectionname arg {
     field*
   }
IfBlock LineNo String [Field] [Field]

A conditional block with an optional else branch:

  if condition {
    field*
  } else {
    field*
  }

Instances

data FieldDescr a Source

Field descriptor. The parameter a parameterizes over where the field's value is stored in.

Constructors

FieldDescr 

Fields

fieldName :: String
 
fieldGet :: a -> Doc
 
fieldSet :: LineNo -> String -> a -> ParseResult a

fieldSet n str x Parses the field value from the given input string str and stores the result in x if the parse was successful. Otherwise, reports an error on line number n.

parseModuleNameQ :: ReadP r ModuleNameSource

parse a module name

parseSepListSource

Arguments

:: ReadP r b 
-> ReadP r a

The parser for the stuff between commas

-> ReadP r [a] 

parseCommaListSource

Arguments

:: ReadP r a

The parser for the stuff between commas

-> ReadP r [a] 

parseOptCommaListSource

Arguments

:: ReadP r a

The parser for the stuff between commas

-> ReadP r [a] 

showFreeText :: String -> DocSource

Pretty-print free-format text, ensuring that it is vertically aligned, and with blank lines replaced by dots for correct re-parsing.

field :: String -> (a -> Doc) -> ReadP a a -> FieldDescr aSource

simpleField :: String -> (a -> Doc) -> ReadP a a -> (b -> a) -> (a -> b -> b) -> FieldDescr bSource

listField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr bSource

spaceListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr bSource

commaListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr bSource

optsField :: String -> CompilerFlavor -> (b -> [(CompilerFlavor, [String])]) -> ([(CompilerFlavor, [String])] -> b -> b) -> FieldDescr bSource

liftField :: (b -> a) -> (a -> b -> b) -> FieldDescr a -> FieldDescr bSource

boolField :: String -> (b -> Bool) -> (Bool -> b -> b) -> FieldDescr bSource

type UnrecFieldParser a = (String, String) -> a -> Maybe aSource

The type of a function which, given a name-value pair of an unrecognized field, and the current structure being built, decides whether to incorporate the unrecognized field (by returning Just x, where x is a possibly modified version of the structure being built), or not (by returning Nothing).

warnUnrec :: UnrecFieldParser aSource

A default unrecognized field parser which simply returns Nothing, i.e. ignores all unrecognized fields, so warnings will be generated.

ignoreUnrec :: UnrecFieldParser aSource

A default unrecognized field parser which silently (i.e. no warnings will be generated) ignores unrecognized fields, by returning the structure being built unmodified.