| Cabal-1.6.0.3: A framework for packaging Haskell software | Source code | Contents | Index
Distribution.ParseUtils |
Portability | portable
Maintainer | cabal-devel@haskell.org
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
type LineNo = Int
data PError
= AmbigousParse String LineNo
| NoParse String LineNo
| TabsError LineNo
| FromString String (Maybe LineNo)
data PWarning
= PWarning String
| UTFWarning LineNo String
locatedErrorMsg :: PError -> (Maybe LineNo, String)
syntaxError :: LineNo -> String -> ParseResult a
warning :: String -> ParseResult ()
runP :: LineNo -> String -> ReadP a a -> String -> ParseResult a
runE :: LineNo -> String -> ReadE a -> String -> ParseResult a
data ParseResult a
= ParseFailed PError
| ParseOk [PWarning] a
catchParseError :: ParseResult a -> (PError -> ParseResult a) -> ParseResult a
parseFail :: PError -> ParseResult a
showPWarning :: FilePath -> PWarning -> String
data Field
= F LineNo String String
| Section LineNo String String [Field]
| IfBlock LineNo String [Field] [Field]
fName :: Field -> String
lineNo :: Field -> LineNo
data FieldDescr a = FieldDescr {
fieldName :: String
fieldGet :: a -> Doc
fieldSet :: LineNo -> String -> a -> ParseResult a
}
ppField :: String -> Doc -> Doc
ppFields :: [FieldDescr a] -> a -> Doc
readFields :: String -> ParseResult [Field]
showFields :: [FieldDescr a] -> a -> String
showSingleNamedField :: [FieldDescr a] -> String -> Maybe (a -> String)
parseFields :: [FieldDescr a] -> a -> String -> ParseResult a
parseFilePathQ :: ReadP r FilePath
parseTokenQ :: ReadP r String
parseTokenQ' :: ReadP r String
parseModuleNameQ :: ReadP r ModuleName
parseBuildTool :: ReadP r Dependency
parsePkgconfigDependency :: ReadP r Dependency
parseOptVersion :: ReadP r Version
parsePackageNameQ :: ReadP r PackageName
parseVersionRangeQ :: ReadP r VersionRange
parseTestedWithQ :: ReadP r (CompilerFlavor, VersionRange)
parseLicenseQ :: ReadP r License
parseExtensionQ :: ReadP r Extension
parseSepList :: ReadP r b -> ReadP r a -> ReadP r [a]
parseCommaList :: ReadP r a -> ReadP r [a]
parseOptCommaList :: ReadP r a -> ReadP r [a]
showFilePath :: FilePath -> Doc
showToken :: String -> Doc
showTestedWith :: (CompilerFlavor, VersionRange) -> Doc
showFreeText :: String -> Doc
parseFreeText :: ReadP s String
field :: String -> (a -> Doc) -> ReadP a a -> FieldDescr a
simpleField :: String -> (a -> Doc) -> ReadP a a -> (b -> a) -> (a -> b -> b) -> FieldDescr b
listField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b
spaceListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b
commaListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b
optsField :: String -> CompilerFlavor -> (b -> [(CompilerFlavor, [String])]) -> ([(CompilerFlavor, [String])] -> b -> b) -> FieldDescr b
liftField :: (b -> a) -> (a -> b -> b) -> FieldDescr a -> FieldDescr b
boolField :: String -> (b -> Bool) -> (Bool -> b -> b) -> FieldDescr b
parseQuoted :: ReadP r a -> ReadP r a
type UnrecFieldParser a = (String, String) -> a -> Maybe a
warnUnrec :: UnrecFieldParser a
ignoreUnrec :: UnrecFieldParser a
Documentation
type LineNo = Int | Source
data PError | Source
Constructors
AmbigousParse String LineNo |
NoParse String LineNo |
TabsError LineNo |
FromString String (Maybe LineNo) |
Instances
Show PError
data PWarning | Source
Constructors
PWarning String |
UTFWarning LineNo String |
Instances
Show PWarning
locatedErrorMsg :: PError -> (Maybe LineNo, String) | Source
syntaxError :: LineNo -> String -> ParseResult a | Source
warning :: String -> ParseResult () | Source
runP :: LineNo -> String -> ReadP a a -> String -> ParseResult a | Source
runE :: LineNo -> String -> ReadE a -> String -> ParseResult a | Source
data ParseResult a | Source
Constructors
ParseFailed PError |
ParseOk [PWarning] a |
Instances
Monad ParseResult
Show a => Show (ParseResult a)
catchParseError :: ParseResult a -> (PError -> ParseResult a) -> ParseResult a | Source
parseFail :: PError -> ParseResult a | Source
showPWarning :: FilePath -> PWarning -> String | Source
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
Eq Field
Show Field
fName :: Field -> String | Source
lineNo :: Field -> LineNo | Source
data FieldDescr a | Source
Field descriptor. The parameter `a` parameterizes over where the field's value is stored in.
Constructors
FieldDescr |
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`.
ppField :: String -> Doc -> Doc | Source
ppFields :: [FieldDescr a] -> a -> Doc | Source
readFields :: String -> ParseResult [Field] | Source
showFields :: [FieldDescr a] -> a -> String | Source
showSingleNamedField :: [FieldDescr a] -> String -> Maybe (a -> String) | Source
parseFields :: [FieldDescr a] -> a -> String -> ParseResult a | Source
parseFilePathQ :: ReadP r FilePath | Source
parseTokenQ :: ReadP r String | Source
parseTokenQ' :: ReadP r String | Source
parseModuleNameQ :: ReadP r ModuleName | Source
parse a module name
parseBuildTool :: ReadP r Dependency | Source
parsePkgconfigDependency :: ReadP r Dependency | Source
parseOptVersion :: ReadP r Version | Source
parsePackageNameQ :: ReadP r PackageName | Source
parseVersionRangeQ :: ReadP r VersionRange | Source
parseTestedWithQ :: ReadP r (CompilerFlavor, VersionRange) | Source
parseLicenseQ :: ReadP r License | Source
parseExtensionQ :: ReadP r Extension | Source
parseSepList | Source
:: |
=> ReadP r b |
-> ReadP r a | The parser for the stuff between commas
-> ReadP r [a] |
parseCommaList | Source
:: |
=> ReadP r a | The parser for the stuff between commas
-> ReadP r [a] |
parseOptCommaList | Source
:: |
=> ReadP r a | The parser for the stuff between commas
-> ReadP r [a] |
showFilePath :: FilePath -> Doc | Source
showToken :: String -> Doc | Source
showTestedWith :: (CompilerFlavor, VersionRange) -> Doc | Source
showFreeText :: String -> Doc | Source
Pretty-print free-format text, ensuring that it is vertically aligned, and with blank lines replaced by dots for correct re-parsing.
parseFreeText :: ReadP s String | Source
field :: String -> (a -> Doc) -> ReadP a a -> FieldDescr a | Source
simpleField :: String -> (a -> Doc) -> ReadP a a -> (b -> a) -> (a -> b -> b) -> FieldDescr b | Source
listField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b | Source
spaceListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b | Source
commaListField :: String -> (a -> Doc) -> ReadP [a] a -> (b -> [a]) -> ([a] -> b -> b) -> FieldDescr b | Source
optsField :: String -> CompilerFlavor -> (b -> [(CompilerFlavor, [String])]) -> ([(CompilerFlavor, [String])] -> b -> b) -> FieldDescr b | Source
liftField :: (b -> a) -> (a -> b -> b) -> FieldDescr a -> FieldDescr b | Source
boolField :: String -> (b -> Bool) -> (Bool -> b -> b) -> FieldDescr b | Source
parseQuoted :: ReadP r a -> ReadP r a | Source
type UnrecFieldParser a = (String, String) -> a -> Maybe a | Source
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 a | Source
A default unrecognized field parser which simply returns Nothing, i.e. ignores all unrecognized fields, so warnings will be generated.
ignoreUnrec :: UnrecFieldParser a | Source
A default unrecognized field parser which silently (i.e. no warnings will be generated) ignores unrecognized fields, by returning the structure being built unmodified.
Produced by Haddock version 2.4.2