Distribution.FieldGrammar

Cabal-2.2.0.1: A framework for packaging Haskell software

Safe Haskell | None
Language | Haskell2010

Distribution.FieldGrammar

Contents

- Field grammar type
- Concrete grammar implementations
- Auxlilary

Description

This module provides a way to specify a grammar of `.cabal` -like files.

Synopsis

- class FieldGrammar g where
- uniqueField :: (FieldGrammar g, Parsec a, Pretty a) => FieldName -> ALens' s a -> g s a
- optionalField :: (FieldGrammar g, Parsec a, Pretty a) => FieldName -> ALens' s (Maybe a) -> g s (Maybe a)
- optionalFieldDef :: (FieldGrammar g, Functor (g s), Parsec a, Pretty a, Eq a) => FieldName -> ALens' s a -> a -> g s a
- monoidalField :: (FieldGrammar g, Parsec a, Pretty a, Monoid a) => FieldName -> ALens' s a -> g s a
- deprecatedField' :: FieldGrammar g => String -> g s a -> g s a
- data ParsecFieldGrammar s a
- type ParsecFieldGrammar' a = ParsecFieldGrammar a a
- parseFieldGrammar :: CabalSpecVersion -> Fields Position -> ParsecFieldGrammar s a -> ParseResult a
- fieldGrammarKnownFieldList :: ParsecFieldGrammar s a -> [FieldName]
- data PrettyFieldGrammar s a
- type PrettyFieldGrammar' a = PrettyFieldGrammar a a
- prettyFieldGrammar :: PrettyFieldGrammar s a -> s -> Doc
- (^^^) :: a -> (a -> b) -> b
- data Section ann = MkSection !(Name ann) [SectionArg ann] [Field ann]
- type Fields ann = Map FieldName [NamelessField ann]
- partitionFields :: [Field ann] -> (Fields ann, [[Section ann]])
- takeFields :: [Field ann] -> (Fields ann, [Field ann])
- runFieldParser :: Position -> ParsecParser a -> CabalSpecVersion -> [FieldLine Position] -> ParseResult a
- runFieldParser' :: Position -> ParsecParser a -> CabalSpecVersion -> FieldLineStream -> ParseResult a

# Field grammar type

class FieldGrammar g where #

`FieldGrammar` is parametrised by

- `s` which is a structure we are parsing. We need this to provide prettyprinter functionality
- `a` type of the field.

Note: We'd like to have `forall s. Applicative (f s)` context.

Minimal complete definition

blurFieldGrammar, uniqueFieldAla, booleanFieldDef, optionalFieldAla, optionalFieldDefAla, monoidalFieldAla, prefixedFields, knownField, hiddenField, deprecatedSince, availableSince

Methods

blurFieldGrammar :: ALens' a b -> g b c -> g a c #

Unfocus, zoom out, blur `FieldGrammar`.

uniqueFieldAla #

Arguments

:: (Parsec b, Pretty b, Newtype b a) |
=> FieldName | field name
-> (a -> b) | `Newtype` pack
-> ALens' s a | lens into the field
-> g s a |

Field which should be defined, exactly once.

booleanFieldDef #

Arguments

:: FieldName | field name
-> ALens' s Bool | lens into the field
-> Bool | default
-> g s Bool |

Boolean field with a default value.

optionalFieldAla #

Arguments

:: (Parsec b, Pretty b, Newtype b a) |
=> FieldName | field name
-> (a -> b) | `pack`
-> ALens' s (Maybe a) | lens into the field
-> g s (Maybe a) |

Optional field.

optionalFieldDefAla #

Arguments

:: (Parsec b, Pretty b, Newtype b a, Eq a) |
=> FieldName | field name
-> (a -> b) | `Newtype` pack
-> ALens' s a | ``Lens'` s a`: lens into the field
-> a | default value
-> g s a |

Optional field with default value.

monoidalFieldAla #

Arguments

:: (Parsec b, Pretty b, Monoid a, Newtype b a) |
=> FieldName | field name
-> (a -> b) | `pack`
-> ALens' s a | lens into the field
-> g s a |

Monoidal field.

Values are combined with `mappend`.

Note: `optionalFieldAla` is a `monoidalField` with `Last` monoid.

prefixedFields #

Arguments

:: FieldName | field name prefix
-> ALens' s [(String, String)] | lens into the field
-> g s [(String, String)] |

Parser matching all fields with a name starting with a prefix.

knownField :: FieldName -> g s () #

Known field, which we don't parse, neither pretty print.

hiddenField :: g s a -> g s a #

Field which is parsed but not pretty printed.

deprecatedSince #

Arguments

:: [Int] | version
-> String | deprecation message
-> g s a |
-> g s a |

Deprecated since

availableSince #

Arguments

:: [Int] | spec version
-> a | default value
-> g s a |
-> g s a |

Annotate field with since spec-version.

Instances

FieldGrammar PrettyFieldGrammar # |
Instance details Defined in Distribution.FieldGrammar.Pretty Methods blurFieldGrammar :: ALens' a b -> PrettyFieldGrammar b c -> PrettyFieldGrammar a c # uniqueFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> PrettyFieldGrammar s a # booleanFieldDef :: FieldName -> ALens' s Bool -> Bool -> PrettyFieldGrammar s Bool # optionalFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s (Maybe a) -> PrettyFieldGrammar s (Maybe a) # optionalFieldDefAla :: (Parsec b, Pretty b, Newtype b a, Eq a) => FieldName -> (a -> b) -> ALens' s a -> a -> PrettyFieldGrammar s a # monoidalFieldAla :: (Parsec b, Pretty b, Monoid a, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> PrettyFieldGrammar s a # prefixedFields :: FieldName -> ALens' s [(String, String)] -> PrettyFieldGrammar s [(String, String)] # knownField :: FieldName -> PrettyFieldGrammar s () # hiddenField :: PrettyFieldGrammar s a -> PrettyFieldGrammar s a # deprecatedSince :: [Int] -> String -> PrettyFieldGrammar s a -> PrettyFieldGrammar s a # availableSince :: [Int] -> a -> PrettyFieldGrammar s a -> PrettyFieldGrammar s a #
FieldGrammar ParsecFieldGrammar # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods blurFieldGrammar :: ALens' a b -> ParsecFieldGrammar b c -> ParsecFieldGrammar a c # uniqueFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> ParsecFieldGrammar s a # booleanFieldDef :: FieldName -> ALens' s Bool -> Bool -> ParsecFieldGrammar s Bool # optionalFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s (Maybe a) -> ParsecFieldGrammar s (Maybe a) # optionalFieldDefAla :: (Parsec b, Pretty b, Newtype b a, Eq a) => FieldName -> (a -> b) -> ALens' s a -> a -> ParsecFieldGrammar s a # monoidalFieldAla :: (Parsec b, Pretty b, Monoid a, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> ParsecFieldGrammar s a # prefixedFields :: FieldName -> ALens' s [(String, String)] -> ParsecFieldGrammar s [(String, String)] # knownField :: FieldName -> ParsecFieldGrammar s () # hiddenField :: ParsecFieldGrammar s a -> ParsecFieldGrammar s a # deprecatedSince :: [Int] -> String -> ParsecFieldGrammar s a -> ParsecFieldGrammar s a # availableSince :: [Int] -> a -> ParsecFieldGrammar s a -> ParsecFieldGrammar s a #
FieldGrammar FieldDescrs # | Note: default values are printed.
Instance details Defined in Distribution.FieldGrammar.FieldDescrs Methods blurFieldGrammar :: ALens' a b -> FieldDescrs b c -> FieldDescrs a c # uniqueFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> FieldDescrs s a # booleanFieldDef :: FieldName -> ALens' s Bool -> Bool -> FieldDescrs s Bool # optionalFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s (Maybe a) -> FieldDescrs s (Maybe a) # optionalFieldDefAla :: (Parsec b, Pretty b, Newtype b a, Eq a) => FieldName -> (a -> b) -> ALens' s a -> a -> FieldDescrs s a # monoidalFieldAla :: (Parsec b, Pretty b, Monoid a, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> FieldDescrs s a # prefixedFields :: FieldName -> ALens' s [(String, String)] -> FieldDescrs s [(String, String)] # knownField :: FieldName -> FieldDescrs s () # hiddenField :: FieldDescrs s a -> FieldDescrs s a # deprecatedSince :: [Int] -> String -> FieldDescrs s a -> FieldDescrs s a # availableSince :: [Int] -> a -> FieldDescrs s a -> FieldDescrs s a #

uniqueField #

Arguments

:: (FieldGrammar g, Parsec a, Pretty a) |
=> FieldName | field name
-> ALens' s a | lens into the field
-> g s a |

Field which can be defined at most once.

optionalField #

Arguments

:: (FieldGrammar g, Parsec a, Pretty a) |
=> FieldName | field name
-> ALens' s (Maybe a) | lens into the field
-> g s (Maybe a) |

Field which can be defined at most once.

optionalFieldDef #

Arguments

:: (FieldGrammar g, Functor (g s), Parsec a, Pretty a, Eq a) |
=> FieldName | field name
-> ALens' s a | ``Lens'` s a`: lens into the field
-> a | default value
-> g s a |

Optional field with default value.

monoidalField #

Arguments

:: (FieldGrammar g, Parsec a, Pretty a, Monoid a) |
=> FieldName | field name
-> ALens' s a | lens into the field
-> g s a |

Field which can be define multiple times, and the results are `mappend`ed.

deprecatedField' #

Arguments

:: FieldGrammar g |
=> String | deprecation message
-> g s a |
-> g s a |

Deprecated field. If found, warning is issued.

Note: also it's not pretty printed!

# Concrete grammar implementations

data ParsecFieldGrammar s a #

Instances

FieldGrammar ParsecFieldGrammar # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods blurFieldGrammar :: ALens' a b -> ParsecFieldGrammar b c -> ParsecFieldGrammar a c # uniqueFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> ParsecFieldGrammar s a # booleanFieldDef :: FieldName -> ALens' s Bool -> Bool -> ParsecFieldGrammar s Bool # optionalFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s (Maybe a) -> ParsecFieldGrammar s (Maybe a) # optionalFieldDefAla :: (Parsec b, Pretty b, Newtype b a, Eq a) => FieldName -> (a -> b) -> ALens' s a -> a -> ParsecFieldGrammar s a # monoidalFieldAla :: (Parsec b, Pretty b, Monoid a, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> ParsecFieldGrammar s a # prefixedFields :: FieldName -> ALens' s [(String, String)] -> ParsecFieldGrammar s [(String, String)] # knownField :: FieldName -> ParsecFieldGrammar s () # hiddenField :: ParsecFieldGrammar s a -> ParsecFieldGrammar s a # deprecatedSince :: [Int] -> String -> ParsecFieldGrammar s a -> ParsecFieldGrammar s a # availableSince :: [Int] -> a -> ParsecFieldGrammar s a -> ParsecFieldGrammar s a #
Functor (ParsecFieldGrammar s) # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods fmap :: (a -> b) -> ParsecFieldGrammar s a -> ParsecFieldGrammar s b Source # (<$) :: a -> ParsecFieldGrammar s b -> ParsecFieldGrammar s a Source #
Applicative (ParsecFieldGrammar s) # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods pure :: a -> ParsecFieldGrammar s a Source # (<*>) :: ParsecFieldGrammar s (a -> b) -> ParsecFieldGrammar s a -> ParsecFieldGrammar s b Source # liftA2 :: (a -> b -> c) -> ParsecFieldGrammar s a -> ParsecFieldGrammar s b -> ParsecFieldGrammar s c Source # (*>) :: ParsecFieldGrammar s a -> ParsecFieldGrammar s b -> ParsecFieldGrammar s b Source # (<*) :: ParsecFieldGrammar s a -> ParsecFieldGrammar s b -> ParsecFieldGrammar s a Source #

type ParsecFieldGrammar' a = ParsecFieldGrammar a a #

parseFieldGrammar :: CabalSpecVersion -> Fields Position -> ParsecFieldGrammar s a -> ParseResult a #

fieldGrammarKnownFieldList :: ParsecFieldGrammar s a -> [FieldName] #

data PrettyFieldGrammar s a #

Instances

FieldGrammar PrettyFieldGrammar # |
Instance details Defined in Distribution.FieldGrammar.Pretty Methods blurFieldGrammar :: ALens' a b -> PrettyFieldGrammar b c -> PrettyFieldGrammar a c # uniqueFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> PrettyFieldGrammar s a # booleanFieldDef :: FieldName -> ALens' s Bool -> Bool -> PrettyFieldGrammar s Bool # optionalFieldAla :: (Parsec b, Pretty b, Newtype b a) => FieldName -> (a -> b) -> ALens' s (Maybe a) -> PrettyFieldGrammar s (Maybe a) # optionalFieldDefAla :: (Parsec b, Pretty b, Newtype b a, Eq a) => FieldName -> (a -> b) -> ALens' s a -> a -> PrettyFieldGrammar s a # monoidalFieldAla :: (Parsec b, Pretty b, Monoid a, Newtype b a) => FieldName -> (a -> b) -> ALens' s a -> PrettyFieldGrammar s a # prefixedFields :: FieldName -> ALens' s [(String, String)] -> PrettyFieldGrammar s [(String, String)] # knownField :: FieldName -> PrettyFieldGrammar s () # hiddenField :: PrettyFieldGrammar s a -> PrettyFieldGrammar s a # deprecatedSince :: [Int] -> String -> PrettyFieldGrammar s a -> PrettyFieldGrammar s a # availableSince :: [Int] -> a -> PrettyFieldGrammar s a -> PrettyFieldGrammar s a #
Functor (PrettyFieldGrammar s) # |
Instance details Defined in Distribution.FieldGrammar.Pretty Methods fmap :: (a -> b) -> PrettyFieldGrammar s a -> PrettyFieldGrammar s b Source # (<$) :: a -> PrettyFieldGrammar s b -> PrettyFieldGrammar s a Source #
Applicative (PrettyFieldGrammar s) # |
Instance details Defined in Distribution.FieldGrammar.Pretty Methods pure :: a -> PrettyFieldGrammar s a Source # (<*>) :: PrettyFieldGrammar s (a -> b) -> PrettyFieldGrammar s a -> PrettyFieldGrammar s b Source # liftA2 :: (a -> b -> c) -> PrettyFieldGrammar s a -> PrettyFieldGrammar s b -> PrettyFieldGrammar s c Source # (*>) :: PrettyFieldGrammar s a -> PrettyFieldGrammar s b -> PrettyFieldGrammar s b Source # (<*) :: PrettyFieldGrammar s a -> PrettyFieldGrammar s b -> PrettyFieldGrammar s a Source #

type PrettyFieldGrammar' a = PrettyFieldGrammar a a #

prettyFieldGrammar :: PrettyFieldGrammar s a -> s -> Doc #

We can use `PrettyFieldGrammar` to pp print the `s`.

Note: there is not trailing `($+$ text "")`.

# Auxlilary

(^^^) :: a -> (a -> b) -> b infixl 5 #

Reverse function application which binds tighter than `<$>` and `<*>`. Useful for refining grammar specification.

    <*> monoidalFieldAla "extensions"           (alaList' FSep MQuoted)       oldExtensions
        ^^^ deprecatedSince [1,12] "Please use 'default-extensions' or 'other-extensions' fields."

data Section ann #

The `Section` constructor of `Field`.

Constructors

MkSection !(Name ann) [SectionArg ann] [Field ann] |

Instances

Functor Section # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods fmap :: (a -> b) -> Section a -> Section b Source # (<$) :: a -> Section b -> Section a Source #
Eq ann => Eq (Section ann) # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods (==) :: Section ann -> Section ann -> Bool # (/=) :: Section ann -> Section ann -> Bool #
Show ann => Show (Section ann) # |
Instance details Defined in Distribution.FieldGrammar.Parsec Methods showsPrec :: Int -> Section ann -> ShowS Source # show :: Section ann -> String Source # showList :: [Section ann] -> ShowS Source #

type Fields ann = Map FieldName [NamelessField ann] #

partitionFields :: [Field ann] -> (Fields ann, [[Section ann]]) #

Partition field list into field map and groups of sections.

takeFields :: [Field ann] -> (Fields ann, [Field ann]) #

Take all fields from the front.

runFieldParser :: Position -> ParsecParser a -> CabalSpecVersion -> [FieldLine Position] -> ParseResult a #

runFieldParser' :: Position -> ParsecParser a -> CabalSpecVersion -> FieldLineStream -> ParseResult a #