{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
-- | Cabal-like file AST types: 'Field', 'Section' etc
--
-- These types are parametrized by an annotation.
module Distribution.Fields.Field (
    -- * Cabal file
    Field (..),
    fieldName,
    fieldAnn,
    fieldUniverse,
    FieldLine (..),
    fieldLineAnn,
    fieldLineBS,
    SectionArg (..),
    sectionArgAnn,
    -- * Name
    FieldName,
    Name (..),
    mkName,
    getName,
    nameAnn,
    ) where

import           Prelude ()
import           Distribution.Compat.Prelude
import           Data.ByteString             (ByteString)
import qualified Data.ByteString.Char8       as B
import qualified Data.Char                   as Char

-------------------------------------------------------------------------------
-- Cabal file
-------------------------------------------------------------------------------

-- | A Cabal-like file consists of a series of fields (@foo: bar@) and sections (@library ...@).
data Field ann
    = Field   !(Name ann) [FieldLine ann]
    | Section !(Name ann) [SectionArg ann] [Field ann]
  deriving (Field ann -> Field ann -> Bool
(Field ann -> Field ann -> Bool)
-> (Field ann -> Field ann -> Bool) -> Eq (Field ann)
forall ann. Eq ann => Field ann -> Field ann -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Field ann -> Field ann -> Bool
$c/= :: forall ann. Eq ann => Field ann -> Field ann -> Bool
== :: Field ann -> Field ann -> Bool
$c== :: forall ann. Eq ann => Field ann -> Field ann -> Bool
Eq, Int -> Field ann -> ShowS
[Field ann] -> ShowS
Field ann -> String
(Int -> Field ann -> ShowS)
-> (Field ann -> String)
-> ([Field ann] -> ShowS)
-> Show (Field ann)
forall ann. Show ann => Int -> Field ann -> ShowS
forall ann. Show ann => [Field ann] -> ShowS
forall ann. Show ann => Field ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Field ann] -> ShowS
$cshowList :: forall ann. Show ann => [Field ann] -> ShowS
show :: Field ann -> String
$cshow :: forall ann. Show ann => Field ann -> String
showsPrec :: Int -> Field ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> Field ann -> ShowS
Show, a -> Field b -> Field a
(a -> b) -> Field a -> Field b
(forall a b. (a -> b) -> Field a -> Field b)
-> (forall a b. a -> Field b -> Field a) -> Functor Field
forall a b. a -> Field b -> Field a
forall a b. (a -> b) -> Field a -> Field b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Field b -> Field a
$c<$ :: forall a b. a -> Field b -> Field a
fmap :: (a -> b) -> Field a -> Field b
$cfmap :: forall a b. (a -> b) -> Field a -> Field b
Functor, Field a -> Bool
(a -> m) -> Field a -> m
(a -> b -> b) -> b -> Field a -> b
(forall m. Monoid m => Field m -> m)
-> (forall m a. Monoid m => (a -> m) -> Field a -> m)
-> (forall m a. Monoid m => (a -> m) -> Field a -> m)
-> (forall a b. (a -> b -> b) -> b -> Field a -> b)
-> (forall a b. (a -> b -> b) -> b -> Field a -> b)
-> (forall b a. (b -> a -> b) -> b -> Field a -> b)
-> (forall b a. (b -> a -> b) -> b -> Field a -> b)
-> (forall a. (a -> a -> a) -> Field a -> a)
-> (forall a. (a -> a -> a) -> Field a -> a)
-> (forall a. Field a -> [a])
-> (forall a. Field a -> Bool)
-> (forall a. Field a -> Int)
-> (forall a. Eq a => a -> Field a -> Bool)
-> (forall a. Ord a => Field a -> a)
-> (forall a. Ord a => Field a -> a)
-> (forall a. Num a => Field a -> a)
-> (forall a. Num a => Field a -> a)
-> Foldable Field
forall a. Eq a => a -> Field a -> Bool
forall a. Num a => Field a -> a
forall a. Ord a => Field a -> a
forall m. Monoid m => Field m -> m
forall a. Field a -> Bool
forall a. Field a -> Int
forall a. Field a -> [a]
forall a. (a -> a -> a) -> Field a -> a
forall m a. Monoid m => (a -> m) -> Field a -> m
forall b a. (b -> a -> b) -> b -> Field a -> b
forall a b. (a -> b -> b) -> b -> Field a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Field a -> a
$cproduct :: forall a. Num a => Field a -> a
sum :: Field a -> a
$csum :: forall a. Num a => Field a -> a
minimum :: Field a -> a
$cminimum :: forall a. Ord a => Field a -> a
maximum :: Field a -> a
$cmaximum :: forall a. Ord a => Field a -> a
elem :: a -> Field a -> Bool
$celem :: forall a. Eq a => a -> Field a -> Bool
length :: Field a -> Int
$clength :: forall a. Field a -> Int
null :: Field a -> Bool
$cnull :: forall a. Field a -> Bool
toList :: Field a -> [a]
$ctoList :: forall a. Field a -> [a]
foldl1 :: (a -> a -> a) -> Field a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Field a -> a
foldr1 :: (a -> a -> a) -> Field a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Field a -> a
foldl' :: (b -> a -> b) -> b -> Field a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Field a -> b
foldl :: (b -> a -> b) -> b -> Field a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Field a -> b
foldr' :: (a -> b -> b) -> b -> Field a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Field a -> b
foldr :: (a -> b -> b) -> b -> Field a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Field a -> b
foldMap' :: (a -> m) -> Field a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Field a -> m
foldMap :: (a -> m) -> Field a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Field a -> m
fold :: Field m -> m
$cfold :: forall m. Monoid m => Field m -> m
Foldable, Functor Field
Foldable Field
Functor Field
-> Foldable Field
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Field a -> f (Field b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Field (f a) -> f (Field a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Field a -> m (Field b))
-> (forall (m :: * -> *) a. Monad m => Field (m a) -> m (Field a))
-> Traversable Field
(a -> f b) -> Field a -> f (Field b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Field (m a) -> m (Field a)
forall (f :: * -> *) a. Applicative f => Field (f a) -> f (Field a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Field a -> m (Field b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Field a -> f (Field b)
sequence :: Field (m a) -> m (Field a)
$csequence :: forall (m :: * -> *) a. Monad m => Field (m a) -> m (Field a)
mapM :: (a -> m b) -> Field a -> m (Field b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Field a -> m (Field b)
sequenceA :: Field (f a) -> f (Field a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Field (f a) -> f (Field a)
traverse :: (a -> f b) -> Field a -> f (Field b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Field a -> f (Field b)
$cp2Traversable :: Foldable Field
$cp1Traversable :: Functor Field
Traversable)

-- | Section of field name
fieldName :: Field ann -> Name ann
fieldName :: Field ann -> Name ann
fieldName (Field Name ann
n [FieldLine ann]
_ )    = Name ann
n
fieldName (Section Name ann
n [SectionArg ann]
_ [Field ann]
_) = Name ann
n

fieldAnn :: Field ann -> ann
fieldAnn :: Field ann -> ann
fieldAnn = Name ann -> ann
forall ann. Name ann -> ann
nameAnn (Name ann -> ann) -> (Field ann -> Name ann) -> Field ann -> ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Field ann -> Name ann
forall ann. Field ann -> Name ann
fieldName

-- | All transitive descendants of 'Field', including itself.
--
-- /Note:/ the resulting list is never empty.
--
fieldUniverse :: Field ann -> [Field ann]
fieldUniverse :: Field ann -> [Field ann]
fieldUniverse f :: Field ann
f@(Section Name ann
_ [SectionArg ann]
_ [Field ann]
fs) = Field ann
f Field ann -> [Field ann] -> [Field ann]
forall a. a -> [a] -> [a]
: (Field ann -> [Field ann]) -> [Field ann] -> [Field ann]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Field ann -> [Field ann]
forall ann. Field ann -> [Field ann]
fieldUniverse [Field ann]
fs
fieldUniverse f :: Field ann
f@(Field Name ann
_ [FieldLine ann]
_)      = [Field ann
f]

-- | A line of text representing the value of a field from a Cabal file.
-- A field may contain multiple lines.
--
-- /Invariant:/ 'ByteString' has no newlines.
data FieldLine ann  = FieldLine  !ann !ByteString
  deriving (FieldLine ann -> FieldLine ann -> Bool
(FieldLine ann -> FieldLine ann -> Bool)
-> (FieldLine ann -> FieldLine ann -> Bool) -> Eq (FieldLine ann)
forall ann. Eq ann => FieldLine ann -> FieldLine ann -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldLine ann -> FieldLine ann -> Bool
$c/= :: forall ann. Eq ann => FieldLine ann -> FieldLine ann -> Bool
== :: FieldLine ann -> FieldLine ann -> Bool
$c== :: forall ann. Eq ann => FieldLine ann -> FieldLine ann -> Bool
Eq, Int -> FieldLine ann -> ShowS
[FieldLine ann] -> ShowS
FieldLine ann -> String
(Int -> FieldLine ann -> ShowS)
-> (FieldLine ann -> String)
-> ([FieldLine ann] -> ShowS)
-> Show (FieldLine ann)
forall ann. Show ann => Int -> FieldLine ann -> ShowS
forall ann. Show ann => [FieldLine ann] -> ShowS
forall ann. Show ann => FieldLine ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldLine ann] -> ShowS
$cshowList :: forall ann. Show ann => [FieldLine ann] -> ShowS
show :: FieldLine ann -> String
$cshow :: forall ann. Show ann => FieldLine ann -> String
showsPrec :: Int -> FieldLine ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> FieldLine ann -> ShowS
Show, a -> FieldLine b -> FieldLine a
(a -> b) -> FieldLine a -> FieldLine b
(forall a b. (a -> b) -> FieldLine a -> FieldLine b)
-> (forall a b. a -> FieldLine b -> FieldLine a)
-> Functor FieldLine
forall a b. a -> FieldLine b -> FieldLine a
forall a b. (a -> b) -> FieldLine a -> FieldLine b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> FieldLine b -> FieldLine a
$c<$ :: forall a b. a -> FieldLine b -> FieldLine a
fmap :: (a -> b) -> FieldLine a -> FieldLine b
$cfmap :: forall a b. (a -> b) -> FieldLine a -> FieldLine b
Functor, FieldLine a -> Bool
(a -> m) -> FieldLine a -> m
(a -> b -> b) -> b -> FieldLine a -> b
(forall m. Monoid m => FieldLine m -> m)
-> (forall m a. Monoid m => (a -> m) -> FieldLine a -> m)
-> (forall m a. Monoid m => (a -> m) -> FieldLine a -> m)
-> (forall a b. (a -> b -> b) -> b -> FieldLine a -> b)
-> (forall a b. (a -> b -> b) -> b -> FieldLine a -> b)
-> (forall b a. (b -> a -> b) -> b -> FieldLine a -> b)
-> (forall b a. (b -> a -> b) -> b -> FieldLine a -> b)
-> (forall a. (a -> a -> a) -> FieldLine a -> a)
-> (forall a. (a -> a -> a) -> FieldLine a -> a)
-> (forall a. FieldLine a -> [a])
-> (forall a. FieldLine a -> Bool)
-> (forall a. FieldLine a -> Int)
-> (forall a. Eq a => a -> FieldLine a -> Bool)
-> (forall a. Ord a => FieldLine a -> a)
-> (forall a. Ord a => FieldLine a -> a)
-> (forall a. Num a => FieldLine a -> a)
-> (forall a. Num a => FieldLine a -> a)
-> Foldable FieldLine
forall a. Eq a => a -> FieldLine a -> Bool
forall a. Num a => FieldLine a -> a
forall a. Ord a => FieldLine a -> a
forall m. Monoid m => FieldLine m -> m
forall a. FieldLine a -> Bool
forall a. FieldLine a -> Int
forall a. FieldLine a -> [a]
forall a. (a -> a -> a) -> FieldLine a -> a
forall m a. Monoid m => (a -> m) -> FieldLine a -> m
forall b a. (b -> a -> b) -> b -> FieldLine a -> b
forall a b. (a -> b -> b) -> b -> FieldLine a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: FieldLine a -> a
$cproduct :: forall a. Num a => FieldLine a -> a
sum :: FieldLine a -> a
$csum :: forall a. Num a => FieldLine a -> a
minimum :: FieldLine a -> a
$cminimum :: forall a. Ord a => FieldLine a -> a
maximum :: FieldLine a -> a
$cmaximum :: forall a. Ord a => FieldLine a -> a
elem :: a -> FieldLine a -> Bool
$celem :: forall a. Eq a => a -> FieldLine a -> Bool
length :: FieldLine a -> Int
$clength :: forall a. FieldLine a -> Int
null :: FieldLine a -> Bool
$cnull :: forall a. FieldLine a -> Bool
toList :: FieldLine a -> [a]
$ctoList :: forall a. FieldLine a -> [a]
foldl1 :: (a -> a -> a) -> FieldLine a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> FieldLine a -> a
foldr1 :: (a -> a -> a) -> FieldLine a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> FieldLine a -> a
foldl' :: (b -> a -> b) -> b -> FieldLine a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> FieldLine a -> b
foldl :: (b -> a -> b) -> b -> FieldLine a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> FieldLine a -> b
foldr' :: (a -> b -> b) -> b -> FieldLine a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> FieldLine a -> b
foldr :: (a -> b -> b) -> b -> FieldLine a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> FieldLine a -> b
foldMap' :: (a -> m) -> FieldLine a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> FieldLine a -> m
foldMap :: (a -> m) -> FieldLine a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> FieldLine a -> m
fold :: FieldLine m -> m
$cfold :: forall m. Monoid m => FieldLine m -> m
Foldable, Functor FieldLine
Foldable FieldLine
Functor FieldLine
-> Foldable FieldLine
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> FieldLine a -> f (FieldLine b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    FieldLine (f a) -> f (FieldLine a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> FieldLine a -> m (FieldLine b))
-> (forall (m :: * -> *) a.
    Monad m =>
    FieldLine (m a) -> m (FieldLine a))
-> Traversable FieldLine
(a -> f b) -> FieldLine a -> f (FieldLine b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
FieldLine (m a) -> m (FieldLine a)
forall (f :: * -> *) a.
Applicative f =>
FieldLine (f a) -> f (FieldLine a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FieldLine a -> m (FieldLine b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FieldLine a -> f (FieldLine b)
sequence :: FieldLine (m a) -> m (FieldLine a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
FieldLine (m a) -> m (FieldLine a)
mapM :: (a -> m b) -> FieldLine a -> m (FieldLine b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FieldLine a -> m (FieldLine b)
sequenceA :: FieldLine (f a) -> f (FieldLine a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
FieldLine (f a) -> f (FieldLine a)
traverse :: (a -> f b) -> FieldLine a -> f (FieldLine b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FieldLine a -> f (FieldLine b)
$cp2Traversable :: Foldable FieldLine
$cp1Traversable :: Functor FieldLine
Traversable)

-- | @since 3.0.0.0
fieldLineAnn :: FieldLine ann -> ann
fieldLineAnn :: FieldLine ann -> ann
fieldLineAnn (FieldLine ann
ann ByteString
_) = ann
ann

-- | @since 3.0.0.0
fieldLineBS :: FieldLine ann -> ByteString
fieldLineBS :: FieldLine ann -> ByteString
fieldLineBS (FieldLine ann
_ ByteString
bs) = ByteString
bs

-- | Section arguments, e.g. name of the library
data SectionArg ann
    = SecArgName  !ann !ByteString
      -- ^ identifier, or something which looks like number. Also many dot numbers, i.e. "7.6.3"
    | SecArgStr   !ann !ByteString
      -- ^ quoted string
    | SecArgOther !ann !ByteString
      -- ^ everything else, mm. operators (e.g. in if-section conditionals)
  deriving (SectionArg ann -> SectionArg ann -> Bool
(SectionArg ann -> SectionArg ann -> Bool)
-> (SectionArg ann -> SectionArg ann -> Bool)
-> Eq (SectionArg ann)
forall ann. Eq ann => SectionArg ann -> SectionArg ann -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SectionArg ann -> SectionArg ann -> Bool
$c/= :: forall ann. Eq ann => SectionArg ann -> SectionArg ann -> Bool
== :: SectionArg ann -> SectionArg ann -> Bool
$c== :: forall ann. Eq ann => SectionArg ann -> SectionArg ann -> Bool
Eq, Int -> SectionArg ann -> ShowS
[SectionArg ann] -> ShowS
SectionArg ann -> String
(Int -> SectionArg ann -> ShowS)
-> (SectionArg ann -> String)
-> ([SectionArg ann] -> ShowS)
-> Show (SectionArg ann)
forall ann. Show ann => Int -> SectionArg ann -> ShowS
forall ann. Show ann => [SectionArg ann] -> ShowS
forall ann. Show ann => SectionArg ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SectionArg ann] -> ShowS
$cshowList :: forall ann. Show ann => [SectionArg ann] -> ShowS
show :: SectionArg ann -> String
$cshow :: forall ann. Show ann => SectionArg ann -> String
showsPrec :: Int -> SectionArg ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> SectionArg ann -> ShowS
Show, a -> SectionArg b -> SectionArg a
(a -> b) -> SectionArg a -> SectionArg b
(forall a b. (a -> b) -> SectionArg a -> SectionArg b)
-> (forall a b. a -> SectionArg b -> SectionArg a)
-> Functor SectionArg
forall a b. a -> SectionArg b -> SectionArg a
forall a b. (a -> b) -> SectionArg a -> SectionArg b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SectionArg b -> SectionArg a
$c<$ :: forall a b. a -> SectionArg b -> SectionArg a
fmap :: (a -> b) -> SectionArg a -> SectionArg b
$cfmap :: forall a b. (a -> b) -> SectionArg a -> SectionArg b
Functor, SectionArg a -> Bool
(a -> m) -> SectionArg a -> m
(a -> b -> b) -> b -> SectionArg a -> b
(forall m. Monoid m => SectionArg m -> m)
-> (forall m a. Monoid m => (a -> m) -> SectionArg a -> m)
-> (forall m a. Monoid m => (a -> m) -> SectionArg a -> m)
-> (forall a b. (a -> b -> b) -> b -> SectionArg a -> b)
-> (forall a b. (a -> b -> b) -> b -> SectionArg a -> b)
-> (forall b a. (b -> a -> b) -> b -> SectionArg a -> b)
-> (forall b a. (b -> a -> b) -> b -> SectionArg a -> b)
-> (forall a. (a -> a -> a) -> SectionArg a -> a)
-> (forall a. (a -> a -> a) -> SectionArg a -> a)
-> (forall a. SectionArg a -> [a])
-> (forall a. SectionArg a -> Bool)
-> (forall a. SectionArg a -> Int)
-> (forall a. Eq a => a -> SectionArg a -> Bool)
-> (forall a. Ord a => SectionArg a -> a)
-> (forall a. Ord a => SectionArg a -> a)
-> (forall a. Num a => SectionArg a -> a)
-> (forall a. Num a => SectionArg a -> a)
-> Foldable SectionArg
forall a. Eq a => a -> SectionArg a -> Bool
forall a. Num a => SectionArg a -> a
forall a. Ord a => SectionArg a -> a
forall m. Monoid m => SectionArg m -> m
forall a. SectionArg a -> Bool
forall a. SectionArg a -> Int
forall a. SectionArg a -> [a]
forall a. (a -> a -> a) -> SectionArg a -> a
forall m a. Monoid m => (a -> m) -> SectionArg a -> m
forall b a. (b -> a -> b) -> b -> SectionArg a -> b
forall a b. (a -> b -> b) -> b -> SectionArg a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: SectionArg a -> a
$cproduct :: forall a. Num a => SectionArg a -> a
sum :: SectionArg a -> a
$csum :: forall a. Num a => SectionArg a -> a
minimum :: SectionArg a -> a
$cminimum :: forall a. Ord a => SectionArg a -> a
maximum :: SectionArg a -> a
$cmaximum :: forall a. Ord a => SectionArg a -> a
elem :: a -> SectionArg a -> Bool
$celem :: forall a. Eq a => a -> SectionArg a -> Bool
length :: SectionArg a -> Int
$clength :: forall a. SectionArg a -> Int
null :: SectionArg a -> Bool
$cnull :: forall a. SectionArg a -> Bool
toList :: SectionArg a -> [a]
$ctoList :: forall a. SectionArg a -> [a]
foldl1 :: (a -> a -> a) -> SectionArg a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> SectionArg a -> a
foldr1 :: (a -> a -> a) -> SectionArg a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> SectionArg a -> a
foldl' :: (b -> a -> b) -> b -> SectionArg a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> SectionArg a -> b
foldl :: (b -> a -> b) -> b -> SectionArg a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> SectionArg a -> b
foldr' :: (a -> b -> b) -> b -> SectionArg a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> SectionArg a -> b
foldr :: (a -> b -> b) -> b -> SectionArg a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> SectionArg a -> b
foldMap' :: (a -> m) -> SectionArg a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> SectionArg a -> m
foldMap :: (a -> m) -> SectionArg a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> SectionArg a -> m
fold :: SectionArg m -> m
$cfold :: forall m. Monoid m => SectionArg m -> m
Foldable, Functor SectionArg
Foldable SectionArg
Functor SectionArg
-> Foldable SectionArg
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> SectionArg a -> f (SectionArg b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    SectionArg (f a) -> f (SectionArg a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> SectionArg a -> m (SectionArg b))
-> (forall (m :: * -> *) a.
    Monad m =>
    SectionArg (m a) -> m (SectionArg a))
-> Traversable SectionArg
(a -> f b) -> SectionArg a -> f (SectionArg b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
SectionArg (m a) -> m (SectionArg a)
forall (f :: * -> *) a.
Applicative f =>
SectionArg (f a) -> f (SectionArg a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SectionArg a -> m (SectionArg b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SectionArg a -> f (SectionArg b)
sequence :: SectionArg (m a) -> m (SectionArg a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
SectionArg (m a) -> m (SectionArg a)
mapM :: (a -> m b) -> SectionArg a -> m (SectionArg b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SectionArg a -> m (SectionArg b)
sequenceA :: SectionArg (f a) -> f (SectionArg a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
SectionArg (f a) -> f (SectionArg a)
traverse :: (a -> f b) -> SectionArg a -> f (SectionArg b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SectionArg a -> f (SectionArg b)
$cp2Traversable :: Foldable SectionArg
$cp1Traversable :: Functor SectionArg
Traversable)

-- | Extract annotation from 'SectionArg'.
sectionArgAnn :: SectionArg ann -> ann
sectionArgAnn :: SectionArg ann -> ann
sectionArgAnn (SecArgName ann
ann ByteString
_)  = ann
ann
sectionArgAnn (SecArgStr ann
ann ByteString
_)   = ann
ann
sectionArgAnn (SecArgOther ann
ann ByteString
_) = ann
ann

-------------------------------------------------------------------------------
-- Name
-------------------------------------------------------------------------------

type FieldName = ByteString

-- | A field name.
--
-- /Invariant/: 'ByteString' is lower-case ASCII.
data Name ann  = Name       !ann !FieldName
  deriving (Name ann -> Name ann -> Bool
(Name ann -> Name ann -> Bool)
-> (Name ann -> Name ann -> Bool) -> Eq (Name ann)
forall ann. Eq ann => Name ann -> Name ann -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Name ann -> Name ann -> Bool
$c/= :: forall ann. Eq ann => Name ann -> Name ann -> Bool
== :: Name ann -> Name ann -> Bool
$c== :: forall ann. Eq ann => Name ann -> Name ann -> Bool
Eq, Int -> Name ann -> ShowS
[Name ann] -> ShowS
Name ann -> String
(Int -> Name ann -> ShowS)
-> (Name ann -> String) -> ([Name ann] -> ShowS) -> Show (Name ann)
forall ann. Show ann => Int -> Name ann -> ShowS
forall ann. Show ann => [Name ann] -> ShowS
forall ann. Show ann => Name ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Name ann] -> ShowS
$cshowList :: forall ann. Show ann => [Name ann] -> ShowS
show :: Name ann -> String
$cshow :: forall ann. Show ann => Name ann -> String
showsPrec :: Int -> Name ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> Name ann -> ShowS
Show, a -> Name b -> Name a
(a -> b) -> Name a -> Name b
(forall a b. (a -> b) -> Name a -> Name b)
-> (forall a b. a -> Name b -> Name a) -> Functor Name
forall a b. a -> Name b -> Name a
forall a b. (a -> b) -> Name a -> Name b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Name b -> Name a
$c<$ :: forall a b. a -> Name b -> Name a
fmap :: (a -> b) -> Name a -> Name b
$cfmap :: forall a b. (a -> b) -> Name a -> Name b
Functor, Name a -> Bool
(a -> m) -> Name a -> m
(a -> b -> b) -> b -> Name a -> b
(forall m. Monoid m => Name m -> m)
-> (forall m a. Monoid m => (a -> m) -> Name a -> m)
-> (forall m a. Monoid m => (a -> m) -> Name a -> m)
-> (forall a b. (a -> b -> b) -> b -> Name a -> b)
-> (forall a b. (a -> b -> b) -> b -> Name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Name a -> b)
-> (forall a. (a -> a -> a) -> Name a -> a)
-> (forall a. (a -> a -> a) -> Name a -> a)
-> (forall a. Name a -> [a])
-> (forall a. Name a -> Bool)
-> (forall a. Name a -> Int)
-> (forall a. Eq a => a -> Name a -> Bool)
-> (forall a. Ord a => Name a -> a)
-> (forall a. Ord a => Name a -> a)
-> (forall a. Num a => Name a -> a)
-> (forall a. Num a => Name a -> a)
-> Foldable Name
forall a. Eq a => a -> Name a -> Bool
forall a. Num a => Name a -> a
forall a. Ord a => Name a -> a
forall m. Monoid m => Name m -> m
forall a. Name a -> Bool
forall a. Name a -> Int
forall a. Name a -> [a]
forall a. (a -> a -> a) -> Name a -> a
forall m a. Monoid m => (a -> m) -> Name a -> m
forall b a. (b -> a -> b) -> b -> Name a -> b
forall a b. (a -> b -> b) -> b -> Name a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Name a -> a
$cproduct :: forall a. Num a => Name a -> a
sum :: Name a -> a
$csum :: forall a. Num a => Name a -> a
minimum :: Name a -> a
$cminimum :: forall a. Ord a => Name a -> a
maximum :: Name a -> a
$cmaximum :: forall a. Ord a => Name a -> a
elem :: a -> Name a -> Bool
$celem :: forall a. Eq a => a -> Name a -> Bool
length :: Name a -> Int
$clength :: forall a. Name a -> Int
null :: Name a -> Bool
$cnull :: forall a. Name a -> Bool
toList :: Name a -> [a]
$ctoList :: forall a. Name a -> [a]
foldl1 :: (a -> a -> a) -> Name a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Name a -> a
foldr1 :: (a -> a -> a) -> Name a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Name a -> a
foldl' :: (b -> a -> b) -> b -> Name a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Name a -> b
foldl :: (b -> a -> b) -> b -> Name a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Name a -> b
foldr' :: (a -> b -> b) -> b -> Name a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Name a -> b
foldr :: (a -> b -> b) -> b -> Name a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Name a -> b
foldMap' :: (a -> m) -> Name a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Name a -> m
foldMap :: (a -> m) -> Name a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Name a -> m
fold :: Name m -> m
$cfold :: forall m. Monoid m => Name m -> m
Foldable, Functor Name
Foldable Name
Functor Name
-> Foldable Name
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Name a -> f (Name b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Name (f a) -> f (Name a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Name a -> m (Name b))
-> (forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a))
-> Traversable Name
(a -> f b) -> Name a -> f (Name b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a)
forall (f :: * -> *) a. Applicative f => Name (f a) -> f (Name a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Name a -> m (Name b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Name a -> f (Name b)
sequence :: Name (m a) -> m (Name a)
$csequence :: forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a)
mapM :: (a -> m b) -> Name a -> m (Name b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Name a -> m (Name b)
sequenceA :: Name (f a) -> f (Name a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Name (f a) -> f (Name a)
traverse :: (a -> f b) -> Name a -> f (Name b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Name a -> f (Name b)
$cp2Traversable :: Foldable Name
$cp1Traversable :: Functor Name
Traversable)

mkName :: ann -> FieldName -> Name ann
mkName :: ann -> ByteString -> Name ann
mkName ann
ann ByteString
bs = ann -> ByteString -> Name ann
forall ann. ann -> ByteString -> Name ann
Name ann
ann ((Char -> Char) -> ByteString -> ByteString
B.map Char -> Char
Char.toLower ByteString
bs)

getName :: Name ann -> FieldName
getName :: Name ann -> ByteString
getName (Name ann
_ ByteString
bs) = ByteString
bs

nameAnn :: Name ann -> ann
nameAnn :: Name ann -> ann
nameAnn (Name ann
ann ByteString
_) = ann
ann