module PostgresqlSyntax.Ast.SetTarget where

import qualified HeadedMegaparsec as Parser
import PostgresqlSyntax.Algebra
import PostgresqlSyntax.Ast.Ident
import PostgresqlSyntax.Ast.Indirection
import qualified PostgresqlSyntax.Helpers.Gens as Gens
import qualified PostgresqlSyntax.Helpers.Parsers as Parsers
import qualified PostgresqlSyntax.Helpers.TextBuilders as TextBuilders
import PostgresqlSyntax.Prelude
import qualified Test.QuickCheck as Qc

-- |
-- ==== References
-- @
-- set_target:
--   | ColId opt_indirection
-- @
data SetTarget = SetTarget Ident (Maybe Indirection)
  deriving (Int -> SetTarget -> ShowS
[SetTarget] -> ShowS
SetTarget -> String
(Int -> SetTarget -> ShowS)
-> (SetTarget -> String)
-> ([SetTarget] -> ShowS)
-> Show SetTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetTarget -> ShowS
showsPrec :: Int -> SetTarget -> ShowS
$cshow :: SetTarget -> String
show :: SetTarget -> String
$cshowList :: [SetTarget] -> ShowS
showList :: [SetTarget] -> ShowS
Show, (forall x. SetTarget -> Rep SetTarget x)
-> (forall x. Rep SetTarget x -> SetTarget) -> Generic SetTarget
forall x. Rep SetTarget x -> SetTarget
forall x. SetTarget -> Rep SetTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SetTarget -> Rep SetTarget x
from :: forall x. SetTarget -> Rep SetTarget x
$cto :: forall x. Rep SetTarget x -> SetTarget
to :: forall x. Rep SetTarget x -> SetTarget
Generic, SetTarget -> SetTarget -> Bool
(SetTarget -> SetTarget -> Bool)
-> (SetTarget -> SetTarget -> Bool) -> Eq SetTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetTarget -> SetTarget -> Bool
== :: SetTarget -> SetTarget -> Bool
$c/= :: SetTarget -> SetTarget -> Bool
/= :: SetTarget -> SetTarget -> Bool
Eq, Eq SetTarget
Eq SetTarget =>
(SetTarget -> SetTarget -> Ordering)
-> (SetTarget -> SetTarget -> Bool)
-> (SetTarget -> SetTarget -> Bool)
-> (SetTarget -> SetTarget -> Bool)
-> (SetTarget -> SetTarget -> Bool)
-> (SetTarget -> SetTarget -> SetTarget)
-> (SetTarget -> SetTarget -> SetTarget)
-> Ord SetTarget
SetTarget -> SetTarget -> Bool
SetTarget -> SetTarget -> Ordering
SetTarget -> SetTarget -> SetTarget
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SetTarget -> SetTarget -> Ordering
compare :: SetTarget -> SetTarget -> Ordering
$c< :: SetTarget -> SetTarget -> Bool
< :: SetTarget -> SetTarget -> Bool
$c<= :: SetTarget -> SetTarget -> Bool
<= :: SetTarget -> SetTarget -> Bool
$c> :: SetTarget -> SetTarget -> Bool
> :: SetTarget -> SetTarget -> Bool
$c>= :: SetTarget -> SetTarget -> Bool
>= :: SetTarget -> SetTarget -> Bool
$cmax :: SetTarget -> SetTarget -> SetTarget
max :: SetTarget -> SetTarget -> SetTarget
$cmin :: SetTarget -> SetTarget -> SetTarget
min :: SetTarget -> SetTarget -> SetTarget
Ord, Typeable SetTarget
Typeable SetTarget =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> SetTarget -> c SetTarget)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SetTarget)
-> (SetTarget -> Constr)
-> (SetTarget -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SetTarget))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SetTarget))
-> ((forall b. Data b => b -> b) -> SetTarget -> SetTarget)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SetTarget -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SetTarget -> r)
-> (forall u. (forall d. Data d => d -> u) -> SetTarget -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SetTarget -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SetTarget -> m SetTarget)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SetTarget -> m SetTarget)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SetTarget -> m SetTarget)
-> Data SetTarget
SetTarget -> Constr
SetTarget -> DataType
(forall b. Data b => b -> b) -> SetTarget -> SetTarget
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SetTarget -> u
forall u. (forall d. Data d => d -> u) -> SetTarget -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SetTarget
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SetTarget -> c SetTarget
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SetTarget)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SetTarget)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SetTarget -> c SetTarget
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SetTarget -> c SetTarget
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SetTarget
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SetTarget
$ctoConstr :: SetTarget -> Constr
toConstr :: SetTarget -> Constr
$cdataTypeOf :: SetTarget -> DataType
dataTypeOf :: SetTarget -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SetTarget)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SetTarget)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SetTarget)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SetTarget)
$cgmapT :: (forall b. Data b => b -> b) -> SetTarget -> SetTarget
gmapT :: (forall b. Data b => b -> b) -> SetTarget -> SetTarget
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SetTarget -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SetTarget -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SetTarget -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SetTarget -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SetTarget -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SetTarget -> m SetTarget
Data)

instance IsAst SetTarget where
  toTextBuilder :: Settings -> SetTarget -> TextBuilder
toTextBuilder Settings
settings (SetTarget Ident
a Maybe Indirection
b) = Settings -> Ident -> TextBuilder
forall a. IsAst a => Settings -> a -> TextBuilder
toTextBuilder Settings
settings Ident
a TextBuilder -> TextBuilder -> TextBuilder
forall a. Semigroup a => a -> a -> a
<> (Indirection -> TextBuilder) -> Maybe Indirection -> TextBuilder
forall a. (a -> TextBuilder) -> Maybe a -> TextBuilder
TextBuilders.suffixMaybe (Settings -> Indirection -> TextBuilder
forall a. IsAst a => Settings -> a -> TextBuilder
toTextBuilder Settings
settings) Maybe Indirection
b
  parser :: Settings -> Parser SetTarget
parser Settings
settings = do
    Ident
a <- Settings -> HeadedParsec Void Text Ident
colId Settings
settings
    HeadedParsec Void Text ()
forall strm err. Stream strm => HeadedParsec err strm ()
Parser.endHead
    Maybe Indirection
b <- HeadedParsec Void Text Indirection
-> HeadedParsec Void Text (Maybe Indirection)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (HeadedParsec Void Text ()
forall err strm.
(Ord err, Stream strm, Token strm ~ Char) =>
HeadedParsec err strm ()
Parsers.space1 HeadedParsec Void Text ()
-> HeadedParsec Void Text Indirection
-> HeadedParsec Void Text Indirection
forall a b.
HeadedParsec Void Text a
-> HeadedParsec Void Text b -> HeadedParsec Void Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Settings -> HeadedParsec Void Text Indirection
forall a. IsAst a => Settings -> Parser a
parser Settings
settings)
    return (Ident -> Maybe Indirection -> SetTarget
SetTarget Ident
a Maybe Indirection
b)

instance Qc.Arbitrary SetTarget where
  shrink :: SetTarget -> [SetTarget]
shrink = SetTarget -> [SetTarget]
forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
Qc.genericShrink
  arbitrary :: Gen SetTarget
arbitrary = Ident -> Maybe Indirection -> SetTarget
SetTarget (Ident -> Maybe Indirection -> SetTarget)
-> Gen Ident -> Gen (Maybe Indirection -> SetTarget)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Ident
forall a. Arbitrary a => Gen a
arbitrary Gen (Maybe Indirection -> SetTarget)
-> Gen (Maybe Indirection) -> Gen SetTarget
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Indirection -> Gen (Maybe Indirection)
forall a. Gen a -> Gen (Maybe a)
Gens.terminatingMaybe Gen Indirection
forall a. Arbitrary a => Gen a
arbitrary