Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a FieldGrammarParser
, one way to parse
.cabal
-like files.
Fields can be specified multiple times in the .cabal files. The order of such entries is important, but the mutual ordering of different fields is not.Also conditional sections are considered after non-conditional data. The example of this silent-commutation quirk is the fact that
buildable: True if os(linux) buildable: False
and
if os(linux) buildable: False buildable: True
behave the same! This is the limitation of GeneralPackageDescription
structure.
So we transform the list of fields [
into
a map of grouped ordinary fields and a list of lists of sections:
Field
ann]
and Fields
ann = Map
FieldName
[NamelessField
ann][[
.Section
ann]]
We need list of list of sections, because we need to distinguish situations where there are fields in between. For example
if flag(bytestring-lt-0_10_4) build-depends: bytestring < 0.10.4 default-language: Haskell2020 else build-depends: bytestring >= 0.10.4
is obviously invalid specification.
We can parse Fields
like we parse aeson
objects, yet we use
slighly higher-level API, so we can process unspecified fields,
to report unknown fields and save custom x-fields
.
Synopsis
- data ParsecFieldGrammar s a
- parseFieldGrammar :: CabalSpecVersion -> Fields Position -> ParsecFieldGrammar s a -> ParseResult a
- fieldGrammarKnownFieldList :: ParsecFieldGrammar s a -> [FieldName]
- type Fields ann = Map FieldName [NamelessField ann]
- data NamelessField ann = MkNamelessField !ann [FieldLine ann]
- namelessFieldAnn :: NamelessField ann -> ann
- data Section ann = MkSection !(Name ann) [SectionArg ann] [Field ann]
- runFieldParser :: Position -> ParsecParser a -> CabalSpecVersion -> [FieldLine Position] -> ParseResult a
- runFieldParser' :: Position -> ParsecParser a -> CabalSpecVersion -> String -> ParseResult a
Documentation
data ParsecFieldGrammar s a Source #
Instances
parseFieldGrammar :: CabalSpecVersion -> Fields Position -> ParsecFieldGrammar s a -> ParseResult a Source #
fieldGrammarKnownFieldList :: ParsecFieldGrammar s a -> [FieldName] Source #
Auxiliary
data NamelessField ann Source #
Single field, without name, but with its annotation.
MkNamelessField !ann [FieldLine ann] |
Instances
Functor NamelessField # | |
fmap :: (a -> b) -> NamelessField a -> NamelessField b Source # (<$) :: a -> NamelessField b -> NamelessField a Source # | |
Eq ann => Eq (NamelessField ann) # | |
(==) :: NamelessField ann -> NamelessField ann -> Bool # (/=) :: NamelessField ann -> NamelessField ann -> Bool # | |
Show ann => Show (NamelessField ann) # | |
namelessFieldAnn :: NamelessField ann -> ann Source #
MkSection !(Name ann) [SectionArg ann] [Field ann] |
runFieldParser :: Position -> ParsecParser a -> CabalSpecVersion -> [FieldLine Position] -> ParseResult a Source #
runFieldParser' :: Position -> ParsecParser a -> CabalSpecVersion -> String -> ParseResult a Source #