module PostgresqlSyntax.Ast.WindowDefinition where

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

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

instance IsAst WindowDefinition where
  toTextBuilder :: Settings -> WindowDefinition -> TextBuilder
toTextBuilder Settings
settings (WindowDefinition Ident
a WindowSpecification
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
<> TextBuilder
" AS " TextBuilder -> TextBuilder -> TextBuilder
forall a. Semigroup a => a -> a -> a
<> Settings -> WindowSpecification -> TextBuilder
forall a. IsAst a => Settings -> a -> TextBuilder
toTextBuilder Settings
settings WindowSpecification
b
  parser :: Settings -> Parser WindowDefinition
parser Settings
settings = Ident -> WindowSpecification -> WindowDefinition
WindowDefinition (Ident -> WindowSpecification -> WindowDefinition)
-> HeadedParsec Void Text Ident
-> HeadedParsec Void Text (WindowSpecification -> WindowDefinition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Settings -> HeadedParsec Void Text Ident
colId Settings
settings HeadedParsec Void Text Ident
-> HeadedParsec Void Text () -> HeadedParsec Void Text Ident
forall a b.
HeadedParsec Void Text a
-> HeadedParsec Void Text b -> HeadedParsec Void Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* HeadedParsec Void Text ()
forall err strm.
(Ord err, Stream strm, Token strm ~ Char) =>
HeadedParsec err strm ()
Parsers.space1 HeadedParsec Void Text Ident
-> HeadedParsec Void Text Text -> HeadedParsec Void Text Ident
forall a b.
HeadedParsec Void Text a
-> HeadedParsec Void Text b -> HeadedParsec Void Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> HeadedParsec Void Text Text
forall {s} {e}.
(Tokens s ~ Text, Token s ~ Char, Ord e, Stream s) =>
Text -> HeadedParsec e s Text
Parsers.keyword Text
"as" HeadedParsec Void Text Ident
-> HeadedParsec Void Text () -> HeadedParsec Void Text Ident
forall a b.
HeadedParsec Void Text a
-> HeadedParsec Void Text b -> HeadedParsec Void Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* HeadedParsec Void Text ()
forall err strm.
(Ord err, Stream strm, Token strm ~ Char) =>
HeadedParsec err strm ()
Parsers.space1 HeadedParsec Void Text Ident
-> HeadedParsec Void Text () -> HeadedParsec Void Text Ident
forall a b.
HeadedParsec Void Text a
-> HeadedParsec Void Text b -> HeadedParsec Void Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* HeadedParsec Void Text ()
forall strm err. Stream strm => HeadedParsec err strm ()
Parser.endHead) HeadedParsec Void Text (WindowSpecification -> WindowDefinition)
-> HeadedParsec Void Text WindowSpecification
-> Parser WindowDefinition
forall a b.
HeadedParsec Void Text (a -> b)
-> HeadedParsec Void Text a -> HeadedParsec Void Text b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Settings -> HeadedParsec Void Text WindowSpecification
forall a. IsAst a => Settings -> Parser a
parser Settings
settings

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