module Language.ATS.Types.Lens ( -- * Lenses
                                 iExpression
                               , constructorUniversals
                               , expression
                               , preF
                               , propExpr1
                               , propExpr2
                               -- * Traversals
                               , typeCall
                               , typeCallArgs
                               , fun
                               , impl
                               , valExpression
                               , varExpr1
                               , varExpr2
                               , andExpr
                               , propLeaves
                               , leaves
                               , comment
                               , prValExpr
                               ) where

import           Data.List.NonEmpty (NonEmpty)
import           Language.ATS.Types
import           Lens.Micro

constructorUniversals :: Lens' (Leaf a) [Universal a]
constructorUniversals :: ([Universal a] -> f [Universal a]) -> Leaf a -> f (Leaf a)
constructorUniversals [Universal a] -> f [Universal a]
f Leaf a
s = ([Universal a] -> Leaf a) -> f [Universal a] -> f (Leaf a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[Universal a]
x -> Leaf a
s { $sel:_constructorUniversals:Leaf :: [Universal a]
_constructorUniversals = [Universal a]
x}) ([Universal a] -> f [Universal a]
f (Leaf a -> [Universal a]
forall a. Leaf a -> [Universal a]
_constructorUniversals Leaf a
s))

expression :: Lens' (PreFunction ek a) (Maybe (ek a))
expression :: (Maybe (ek a) -> f (Maybe (ek a)))
-> PreFunction ek a -> f (PreFunction ek a)
expression Maybe (ek a) -> f (Maybe (ek a))
f PreFunction ek a
s = (Maybe (ek a) -> PreFunction ek a)
-> f (Maybe (ek a)) -> f (PreFunction ek a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe (ek a)
x -> PreFunction ek a
s { $sel:_expression:PreF :: Maybe (ek a)
_expression = Maybe (ek a)
x}) (Maybe (ek a) -> f (Maybe (ek a))
f (PreFunction ek a -> Maybe (ek a)
forall (ek :: * -> *) a. PreFunction ek a -> Maybe (ek a)
_expression PreFunction ek a
s))

iExpression :: Lens' (Implementation a) (Either (StaticExpression a) (Expression a))
iExpression :: (Either (StaticExpression a) (Expression a)
 -> f (Either (StaticExpression a) (Expression a)))
-> Implementation a -> f (Implementation a)
iExpression Either (StaticExpression a) (Expression a)
-> f (Either (StaticExpression a) (Expression a))
f Implementation a
s = (Either (StaticExpression a) (Expression a) -> Implementation a)
-> f (Either (StaticExpression a) (Expression a))
-> f (Implementation a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Either (StaticExpression a) (Expression a)
x -> Implementation a
s { $sel:_iExpression:Implement :: Either (StaticExpression a) (Expression a)
_iExpression = Either (StaticExpression a) (Expression a)
x}) (Either (StaticExpression a) (Expression a)
-> f (Either (StaticExpression a) (Expression a))
f (Implementation a -> Either (StaticExpression a) (Expression a)
forall a.
Implementation a -> Either (StaticExpression a) (Expression a)
_iExpression Implementation a
s))

propExpr1 :: Lens' (DataPropLeaf a) (Expression a)
propExpr1 :: (Expression a -> f (Expression a))
-> DataPropLeaf a -> f (DataPropLeaf a)
propExpr1 Expression a -> f (Expression a)
f DataPropLeaf a
s = (Expression a -> DataPropLeaf a)
-> f (Expression a) -> f (DataPropLeaf a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Expression a
x -> DataPropLeaf a
s { $sel:_propExpr1:DataPropLeaf :: Expression a
_propExpr1 = Expression a
x}) (Expression a -> f (Expression a)
f (DataPropLeaf a -> Expression a
forall a. DataPropLeaf a -> Expression a
_propExpr1 DataPropLeaf a
s))

propExpr2 :: Lens' (DataPropLeaf a) (Maybe (Expression a))
propExpr2 :: (Maybe (Expression a) -> f (Maybe (Expression a)))
-> DataPropLeaf a -> f (DataPropLeaf a)
propExpr2 Maybe (Expression a) -> f (Maybe (Expression a))
f DataPropLeaf a
s = (Maybe (Expression a) -> DataPropLeaf a)
-> f (Maybe (Expression a)) -> f (DataPropLeaf a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe (Expression a)
x -> DataPropLeaf a
s { $sel:_propExpr2:DataPropLeaf :: Maybe (Expression a)
_propExpr2 = Maybe (Expression a)
x}) (Maybe (Expression a) -> f (Maybe (Expression a))
f (DataPropLeaf a -> Maybe (Expression a)
forall a. DataPropLeaf a -> Maybe (Expression a)
_propExpr2 DataPropLeaf a
s))

preF :: Traversal' (Function a) (PreFunction Expression a)
preF :: (PreFunction Expression a -> f (PreFunction Expression a))
-> Function a -> f (Function a)
preF PreFunction Expression a -> f (PreFunction Expression a)
f (Fun PreFunction Expression a
x)    = (\PreFunction Expression a
x' -> PreFunction Expression a -> Function a
forall a. PreFunction Expression a -> Function a
Fun PreFunction Expression a
x') (PreFunction Expression a -> Function a)
-> f (PreFunction Expression a) -> f (Function a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PreFunction Expression a -> f (PreFunction Expression a)
f PreFunction Expression a
x
preF PreFunction Expression a -> f (PreFunction Expression a)
f (Fn PreFunction Expression a
x)     = (\PreFunction Expression a
x' -> PreFunction Expression a -> Function a
forall a. PreFunction Expression a -> Function a
Fn PreFunction Expression a
x') (PreFunction Expression a -> Function a)
-> f (PreFunction Expression a) -> f (Function a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PreFunction Expression a -> f (PreFunction Expression a)
f PreFunction Expression a
x
preF PreFunction Expression a -> f (PreFunction Expression a)
f (CastFn PreFunction Expression a
x) = (\PreFunction Expression a
x' -> PreFunction Expression a -> Function a
forall a. PreFunction Expression a -> Function a
CastFn PreFunction Expression a
x') (PreFunction Expression a -> Function a)
-> f (PreFunction Expression a) -> f (Function a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PreFunction Expression a -> f (PreFunction Expression a)
f PreFunction Expression a
x
preF PreFunction Expression a -> f (PreFunction Expression a)
f (Fnx PreFunction Expression a
x)    = (\PreFunction Expression a
x' -> PreFunction Expression a -> Function a
forall a. PreFunction Expression a -> Function a
Fnx PreFunction Expression a
x') (PreFunction Expression a -> Function a)
-> f (PreFunction Expression a) -> f (Function a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PreFunction Expression a -> f (PreFunction Expression a)
f PreFunction Expression a
x
preF PreFunction Expression a -> f (PreFunction Expression a)
f (And PreFunction Expression a
x)    = (\PreFunction Expression a
x' -> PreFunction Expression a -> Function a
forall a. PreFunction Expression a -> Function a
And PreFunction Expression a
x') (PreFunction Expression a -> Function a)
-> f (PreFunction Expression a) -> f (Function a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PreFunction Expression a -> f (PreFunction Expression a)
f PreFunction Expression a
x
preF PreFunction Expression a -> f (PreFunction Expression a)
_ Function a
x          = Function a -> f (Function a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Function a
x

typeCall :: Traversal' (Type a) (Name a)
typeCall :: (Name a -> f (Name a)) -> Type a -> f (Type a)
typeCall Name a -> f (Name a)
f (Dependent Name a
x [Type a]
y) = (\Name a
x' -> Name a -> [Type a] -> Type a
forall a. Name a -> [Type a] -> Type a
Dependent Name a
x' [Type a]
y) (Name a -> Type a) -> f (Name a) -> f (Type a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name a -> f (Name a)
f Name a
x
typeCall Name a -> f (Name a)
_ Type a
x               = Type a -> f (Type a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type a
x

typeCallArgs :: Traversal' (Type a) [Type a]
typeCallArgs :: ([Type a] -> f [Type a]) -> Type a -> f (Type a)
typeCallArgs [Type a] -> f [Type a]
f (Dependent Name a
x [Type a]
y) = (\[Type a]
y' -> Name a -> [Type a] -> Type a
forall a. Name a -> [Type a] -> Type a
Dependent Name a
x [Type a]
y') ([Type a] -> Type a) -> f [Type a] -> f (Type a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Type a] -> f [Type a]
f [Type a]
y
typeCallArgs [Type a] -> f [Type a]
_ Type a
x               = Type a -> f (Type a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type a
x

fun :: Traversal' (Declaration a) (Function a)
fun :: (Function a -> f (Function a))
-> Declaration a -> f (Declaration a)
fun Function a -> f (Function a)
f (Func a
x Function a
y) = a -> Function a -> Declaration a
forall a. a -> Function a -> Declaration a
Func a
x (Function a -> Declaration a)
-> f (Function a) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Function a -> f (Function a)
f Function a
y
fun Function a -> f (Function a)
_ Declaration a
x          = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

impl :: Traversal' (Declaration a) (Implementation a)
impl :: (Implementation a -> f (Implementation a))
-> Declaration a -> f (Declaration a)
impl Implementation a -> f (Implementation a)
f (Impl Args a
x Implementation a
y)      = Args a -> Implementation a -> Declaration a
forall a. Args a -> Implementation a -> Declaration a
Impl Args a
x (Implementation a -> Declaration a)
-> f (Implementation a) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Implementation a -> f (Implementation a)
f Implementation a
y
impl Implementation a -> f (Implementation a)
f (ProofImpl Args a
x Implementation a
y) = Args a -> Implementation a -> Declaration a
forall a. Args a -> Implementation a -> Declaration a
ProofImpl Args a
x (Implementation a -> Declaration a)
-> f (Implementation a) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Implementation a -> f (Implementation a)
f Implementation a
y
impl Implementation a -> f (Implementation a)
_ Declaration a
x               = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

valExpression :: Traversal' (Declaration a) (Maybe (Expression a))
valExpression :: (Maybe (Expression a) -> f (Maybe (Expression a)))
-> Declaration a -> f (Declaration a)
valExpression Maybe (Expression a) -> f (Maybe (Expression a))
f (Val Addendum
a Maybe (Type a)
v Maybe (Pattern a)
p Maybe (Expression a)
e) = Addendum
-> Maybe (Type a)
-> Maybe (Pattern a)
-> Maybe (Expression a)
-> Declaration a
forall a.
Addendum
-> Maybe (Type a)
-> Maybe (Pattern a)
-> Maybe (Expression a)
-> Declaration a
Val Addendum
a Maybe (Type a)
v Maybe (Pattern a)
p (Maybe (Expression a) -> Declaration a)
-> f (Maybe (Expression a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Expression a) -> f (Maybe (Expression a))
f Maybe (Expression a)
e
valExpression Maybe (Expression a) -> f (Maybe (Expression a))
_ Declaration a
x             = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

prValExpr :: Traversal' (Declaration a) (Maybe (StaticExpression a))
prValExpr :: (Maybe (StaticExpression a) -> f (Maybe (StaticExpression a)))
-> Declaration a -> f (Declaration a)
prValExpr Maybe (StaticExpression a) -> f (Maybe (StaticExpression a))
f (PrVal [Universal a]
us Pattern a
p Maybe (StaticExpression a)
me Maybe (Type a)
mt) = (\Maybe (StaticExpression a)
e -> [Universal a]
-> Pattern a
-> Maybe (StaticExpression a)
-> Maybe (Type a)
-> Declaration a
forall a.
[Universal a]
-> Pattern a
-> Maybe (StaticExpression a)
-> Maybe (Type a)
-> Declaration a
PrVal [Universal a]
us Pattern a
p Maybe (StaticExpression a)
e Maybe (Type a)
mt) (Maybe (StaticExpression a) -> Declaration a)
-> f (Maybe (StaticExpression a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (StaticExpression a) -> f (Maybe (StaticExpression a))
f Maybe (StaticExpression a)
me
prValExpr Maybe (StaticExpression a) -> f (Maybe (StaticExpression a))
f (PrVar Pattern a
p Maybe (StaticExpression a)
me Maybe (Type a)
mt)    = (\Maybe (StaticExpression a)
e -> Pattern a
-> Maybe (StaticExpression a) -> Maybe (Type a) -> Declaration a
forall a.
Pattern a
-> Maybe (StaticExpression a) -> Maybe (Type a) -> Declaration a
PrVar Pattern a
p Maybe (StaticExpression a)
e Maybe (Type a)
mt) (Maybe (StaticExpression a) -> Declaration a)
-> f (Maybe (StaticExpression a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (StaticExpression a) -> f (Maybe (StaticExpression a))
f Maybe (StaticExpression a)
me
prValExpr Maybe (StaticExpression a) -> f (Maybe (StaticExpression a))
_ Declaration a
x                  = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

varExpr1 :: Traversal' (Declaration a) (Maybe (Expression a))
varExpr1 :: (Maybe (Expression a) -> f (Maybe (Expression a)))
-> Declaration a -> f (Declaration a)
varExpr1 Maybe (Expression a) -> f (Maybe (Expression a))
f (Var Maybe (Type a)
t Pattern a
p Maybe (Expression a)
e Maybe (Expression a)
e') = (\Maybe (Expression a)
e'' -> Maybe (Type a)
-> Pattern a
-> Maybe (Expression a)
-> Maybe (Expression a)
-> Declaration a
forall a.
Maybe (Type a)
-> Pattern a
-> Maybe (Expression a)
-> Maybe (Expression a)
-> Declaration a
Var Maybe (Type a)
t Pattern a
p Maybe (Expression a)
e'' Maybe (Expression a)
e') (Maybe (Expression a) -> Declaration a)
-> f (Maybe (Expression a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Expression a) -> f (Maybe (Expression a))
f Maybe (Expression a)
e
varExpr1 Maybe (Expression a) -> f (Maybe (Expression a))
_ Declaration a
x              = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

varExpr2 :: Traversal' (Declaration a) (Maybe (Expression a))
varExpr2 :: (Maybe (Expression a) -> f (Maybe (Expression a)))
-> Declaration a -> f (Declaration a)
varExpr2 Maybe (Expression a) -> f (Maybe (Expression a))
f (Var Maybe (Type a)
t Pattern a
p Maybe (Expression a)
e Maybe (Expression a)
e') = (\Maybe (Expression a)
e'' -> Maybe (Type a)
-> Pattern a
-> Maybe (Expression a)
-> Maybe (Expression a)
-> Declaration a
forall a.
Maybe (Type a)
-> Pattern a
-> Maybe (Expression a)
-> Maybe (Expression a)
-> Declaration a
Var Maybe (Type a)
t Pattern a
p Maybe (Expression a)
e Maybe (Expression a)
e'') (Maybe (Expression a) -> Declaration a)
-> f (Maybe (Expression a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Expression a) -> f (Maybe (Expression a))
f Maybe (Expression a)
e'
varExpr2 Maybe (Expression a) -> f (Maybe (Expression a))
_ Declaration a
x              = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

andExpr :: Traversal' (Declaration a) (Expression a)
andExpr :: (Expression a -> f (Expression a))
-> Declaration a -> f (Declaration a)
andExpr Expression a -> f (Expression a)
f (AndDecl Maybe (Type a)
t Pattern a
p Expression a
e) = Maybe (Type a) -> Pattern a -> Expression a -> Declaration a
forall a.
Maybe (Type a) -> Pattern a -> Expression a -> Declaration a
AndDecl Maybe (Type a)
t Pattern a
p (Expression a -> Declaration a)
-> f (Expression a) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expression a -> f (Expression a)
f Expression a
e
andExpr Expression a -> f (Expression a)
_ Declaration a
x               = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

propLeaves :: Traversal' (Declaration a) [DataPropLeaf a]
propLeaves :: ([DataPropLeaf a] -> f [DataPropLeaf a])
-> Declaration a -> f (Declaration a)
propLeaves [DataPropLeaf a] -> f [DataPropLeaf a]
f (DataProp a
l String
n SortArgs a
as [DataPropLeaf a]
pl) = a -> String -> SortArgs a -> [DataPropLeaf a] -> Declaration a
forall a.
a -> String -> SortArgs a -> [DataPropLeaf a] -> Declaration a
DataProp a
l String
n SortArgs a
as ([DataPropLeaf a] -> Declaration a)
-> f [DataPropLeaf a] -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [DataPropLeaf a] -> f [DataPropLeaf a]
f [DataPropLeaf a]
pl
propLeaves [DataPropLeaf a] -> f [DataPropLeaf a]
_ Declaration a
x                    = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

leaves :: Traversal' (Declaration a) (NonEmpty (Leaf a))
leaves :: (NonEmpty (Leaf a) -> f (NonEmpty (Leaf a)))
-> Declaration a -> f (Declaration a)
leaves NonEmpty (Leaf a) -> f (NonEmpty (Leaf a))
f (SumType String
t SortArgs a
as NonEmpty (Leaf a)
l)     = String -> SortArgs a -> NonEmpty (Leaf a) -> Declaration a
forall a.
String -> SortArgs a -> NonEmpty (Leaf a) -> Declaration a
SumType String
t SortArgs a
as (NonEmpty (Leaf a) -> Declaration a)
-> f (NonEmpty (Leaf a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty (Leaf a) -> f (NonEmpty (Leaf a))
f NonEmpty (Leaf a)
l
leaves NonEmpty (Leaf a) -> f (NonEmpty (Leaf a))
f (SumViewType String
t SortArgs a
as NonEmpty (Leaf a)
l) = String -> SortArgs a -> NonEmpty (Leaf a) -> Declaration a
forall a.
String -> SortArgs a -> NonEmpty (Leaf a) -> Declaration a
SumViewType String
t SortArgs a
as (NonEmpty (Leaf a) -> Declaration a)
-> f (NonEmpty (Leaf a)) -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty (Leaf a) -> f (NonEmpty (Leaf a))
f NonEmpty (Leaf a)
l
leaves NonEmpty (Leaf a) -> f (NonEmpty (Leaf a))
_ Declaration a
x                    = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x

comment :: Traversal' (Declaration a) String
comment :: (String -> f String) -> Declaration a -> f (Declaration a)
comment String -> f String
f (Comment String
c) = String -> Declaration a
forall a. String -> Declaration a
Comment (String -> Declaration a) -> f String -> f (Declaration a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> f String
f String
c
comment String -> f String
_ Declaration a
x           = Declaration a -> f (Declaration a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Declaration a
x