Safe Haskell | None |
---|---|
Language | Haskell2010 |
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, Show a) => FieldName -> LensLike' (Pretext (Maybe a) (Maybe a)) s a -> a -> g s a
- optionalFieldDefAla :: (FieldGrammar g, Functor (g s), Parsec b, Pretty b, Newtype b a, Eq a, Show a) => FieldName -> (a -> b) -> LensLike' (Pretext (Maybe a) (Maybe a)) 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 :: 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 -> FieldParser a -> [FieldLine Position] -> ParseResult a
- runFieldParser' :: Position -> FieldParser a -> String -> ParseResult a
Field grammar type
class FieldGrammar g where Source #
FieldGrammar
is parametrised by
s
which is a structure we are parsing. We need this to provide prettyprinter functionalitya
type of the field.
Note: We'd like to have forall s. Applicative (f s)
context.
blurFieldGrammar, uniqueFieldAla, booleanFieldDef, optionalFieldAla, monoidalFieldAla, prefixedFields, knownField, hiddenField, deprecatedSince, availableSince
blurFieldGrammar :: ALens' a b -> g b c -> g a c Source #
Unfocus, zoom out, blur FieldGrammar
.
:: (Parsec b, Pretty b, Newtype b a) | |
=> FieldName | field name |
-> (a -> b) |
|
-> ALens' s a | lens into the field |
-> g s a |
Field which should be defined, exactly once.
Boolean field with a default value.
:: (Parsec b, Pretty b, Newtype b a) | |
=> FieldName | field name |
-> (a -> b) |
|
-> ALens' s (Maybe a) | lens into the field |
-> g s (Maybe a) |
Optional field.
:: (Parsec b, Pretty b, Monoid a, Newtype b a) | |
=> FieldName | field name |
-> (a -> b) |
|
-> 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.
:: 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 () Source #
Known field, which we don't parse, neither pretty print.
Field which is parsed but not pretty printed.
Deprecated since
:: [Int] | spec version |
-> g s a | |
-> g s a |
Annotate field with since spec-version.
Instances
:: (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.
:: (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.
:: (FieldGrammar g, Functor (g s), Parsec a, Pretty a, Eq a, Show a) | |
=> FieldName | field name |
-> LensLike' (Pretext (Maybe a) (Maybe a)) s a |
|
-> a | default value |
-> g s a |
Optional field with default value.
:: (FieldGrammar g, Functor (g s), Parsec b, Pretty b, Newtype b a, Eq a, Show a) | |
=> FieldName | field name |
-> (a -> b) |
|
-> LensLike' (Pretext (Maybe a) (Maybe a)) s a |
|
-> a | default value |
-> g s a |
Optional field with default value.
:: (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.
:: 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 Source #
Instances
type ParsecFieldGrammar' a = ParsecFieldGrammar a a Source #
parseFieldGrammar :: Fields Position -> ParsecFieldGrammar s a -> ParseResult a Source #
fieldGrammarKnownFieldList :: ParsecFieldGrammar s a -> [FieldName] Source #
data PrettyFieldGrammar s a Source #
Instances
type PrettyFieldGrammar' a = PrettyFieldGrammar a a Source #
prettyFieldGrammar :: PrettyFieldGrammar s a -> s -> Doc Source #
We can use PrettyFieldGrammar
to pp print the s
.
Auxlilary
(^^^) :: a -> (a -> b) -> b infixl 5 Source #
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."
MkSection !(Name ann) [SectionArg ann] [Field ann] |
partitionFields :: [Field ann] -> (Fields ann, [[Section ann]]) Source #
Partition field list into field map and groups of sections.
runFieldParser :: Position -> FieldParser a -> [FieldLine Position] -> ParseResult a Source #
runFieldParser' :: Position -> FieldParser a -> String -> ParseResult a Source #