module CabalGild.Extra.Name where

import qualified CabalGild.Extra.String as String
import qualified Distribution.Compat.Lens as Lens
import qualified Distribution.Fields as Fields

-- | Extracts the annotation from the given 'Fields.Name'.
annotation :: Fields.Name a -> a
annotation :: forall a. Name a -> a
annotation (Fields.Name a
x FieldName
_) = a
x

-- | A lens for the 'annotation'.
annotationLens :: Lens.Lens' (Fields.Name a) a
annotationLens :: forall a (f :: * -> *).
Functor f =>
LensLike f (Name a) (Name a) a a
annotationLens a -> f a
f Name a
s = (a -> Name a) -> f a -> f (Name a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
a -> a -> FieldName -> Name a
forall ann. ann -> FieldName -> Name ann
Fields.Name a
a (FieldName -> Name a) -> FieldName -> Name a
forall a b. (a -> b) -> a -> b
$ Name a -> FieldName
forall a. Name a -> FieldName
value Name a
s) (f a -> f (Name a)) -> (a -> f a) -> a -> f (Name a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f a
f (a -> f (Name a)) -> a -> f (Name a)
forall a b. (a -> b) -> a -> b
$ Name a -> a
forall a. Name a -> a
annotation Name a
s

-- | Extracts the value from the given 'Fields.Name'.
value :: Fields.Name a -> Fields.FieldName
value :: forall a. Name a -> FieldName
value (Fields.Name a
_ FieldName
x) = FieldName
x

-- | Returns true when the name is @"if"@, false otherwise.
isIf :: Fields.Name a -> Bool
isIf :: forall a. Name a -> Bool
isIf = (FieldName -> FieldName -> Bool
forall a. Eq a => a -> a -> Bool
== String -> FieldName
String.toUtf8 String
"if") (FieldName -> Bool) -> (Name a -> FieldName) -> Name a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name a -> FieldName
forall a. Name a -> FieldName
value

-- | Returns true when the name is @"elif"@, false otherwise.
isElif :: Fields.Name a -> Bool
isElif :: forall a. Name a -> Bool
isElif = (FieldName -> FieldName -> Bool
forall a. Eq a => a -> a -> Bool
== String -> FieldName
String.toUtf8 String
"elif") (FieldName -> Bool) -> (Name a -> FieldName) -> Name a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name a -> FieldName
forall a. Name a -> FieldName
value

-- | Returns true when the name is @"else"@, false otherwise.
isElse :: Fields.Name a -> Bool
isElse :: forall a. Name a -> Bool
isElse = (FieldName -> FieldName -> Bool
forall a. Eq a => a -> a -> Bool
== String -> FieldName
String.toUtf8 String
"else") (FieldName -> Bool) -> (Name a -> FieldName) -> Name a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name a -> FieldName
forall a. Name a -> FieldName
value