{-|
Module      : Prosidy.Compile.Core.Rules
Description : Internal module declaring 'Rules' types and functions.
Copyright   : ©2020 James Alexander Feldman-Crough
License     : MPL-2.0
Maintainer  : alex@fldcr.com
-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
module Prosidy.Compile.Core.Rules
    ( Rules
    , Rule(..)
    , rule
    , local
    , self
    , runRules
    , mapRules
    , hoist

    , HoistRuleFor

    -- * Context-aware ADT rules.
    , RuleFor
    , BlockRule(..)
    , DocumentRule(..)
    , FragmentRule(..)
    , InlineRule(..)
    , MetadataRule(..)
    , ParagraphRule(..)
    , RegionRule(..)
    , SeriesNERule(..)
    , SeriesRule(..)
    , TagRule(..)

    -- * Reëxports
    , Alternative(..)
    )
where

import           Prosidy.Types
import           Prosidy.Source                 ( Location )
import           Data.Void.HKT                  ( Void )
import           Data.Text                      ( Text )

import           Control.Applicative            ( Alternative(..) )
import qualified Control.Alternative.Free.Final
                                               as Alt

-------------------------------------------------------------------------------
-- | A container for building up compilation rules.
--
-- * The type parameter @t@ specifies the /input type/ of these rules. It will
-- almost always be a Prosidy node type, such as 'Document' or 'Tag'.
--
-- * The type parameter @f@ is a contextual functor for implementing custom
-- extensions on top of 'Rules'.
newtype Rules t f a = Rules
  { Rules t f a -> Alt (Rule t f) a
_runRules :: Alt.Alt (Rule t f) a
  }
  deriving newtype (a -> Rules t f b -> Rules t f a
(a -> b) -> Rules t f a -> Rules t f b
(forall a b. (a -> b) -> Rules t f a -> Rules t f b)
-> (forall a b. a -> Rules t f b -> Rules t f a)
-> Functor (Rules t f)
forall a b. a -> Rules t f b -> Rules t f a
forall a b. (a -> b) -> Rules t f a -> Rules t f b
forall t (f :: * -> *) a b. a -> Rules t f b -> Rules t f a
forall t (f :: * -> *) a b. (a -> b) -> Rules t f a -> Rules t f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Rules t f b -> Rules t f a
$c<$ :: forall t (f :: * -> *) a b. a -> Rules t f b -> Rules t f a
fmap :: (a -> b) -> Rules t f a -> Rules t f b
$cfmap :: forall t (f :: * -> *) a b. (a -> b) -> Rules t f a -> Rules t f b
Functor, Functor (Rules t f)
a -> Rules t f a
Functor (Rules t f) =>
(forall a. a -> Rules t f a)
-> (forall a b. Rules t f (a -> b) -> Rules t f a -> Rules t f b)
-> (forall a b c.
    (a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c)
-> (forall a b. Rules t f a -> Rules t f b -> Rules t f b)
-> (forall a b. Rules t f a -> Rules t f b -> Rules t f a)
-> Applicative (Rules t f)
Rules t f a -> Rules t f b -> Rules t f b
Rules t f a -> Rules t f b -> Rules t f a
Rules t f (a -> b) -> Rules t f a -> Rules t f b
(a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c
forall a. a -> Rules t f a
forall a b. Rules t f a -> Rules t f b -> Rules t f a
forall a b. Rules t f a -> Rules t f b -> Rules t f b
forall a b. Rules t f (a -> b) -> Rules t f a -> Rules t f b
forall a b c.
(a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c
forall t (f :: * -> *). Functor (Rules t f)
forall t (f :: * -> *) a. a -> Rules t f a
forall t (f :: * -> *) a b.
Rules t f a -> Rules t f b -> Rules t f a
forall t (f :: * -> *) a b.
Rules t f a -> Rules t f b -> Rules t f b
forall t (f :: * -> *) a b.
Rules t f (a -> b) -> Rules t f a -> Rules t f b
forall t (f :: * -> *) a b c.
(a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Rules t f a -> Rules t f b -> Rules t f a
$c<* :: forall t (f :: * -> *) a b.
Rules t f a -> Rules t f b -> Rules t f a
*> :: Rules t f a -> Rules t f b -> Rules t f b
$c*> :: forall t (f :: * -> *) a b.
Rules t f a -> Rules t f b -> Rules t f b
liftA2 :: (a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c
$cliftA2 :: forall t (f :: * -> *) a b c.
(a -> b -> c) -> Rules t f a -> Rules t f b -> Rules t f c
<*> :: Rules t f (a -> b) -> Rules t f a -> Rules t f b
$c<*> :: forall t (f :: * -> *) a b.
Rules t f (a -> b) -> Rules t f a -> Rules t f b
pure :: a -> Rules t f a
$cpure :: forall t (f :: * -> *) a. a -> Rules t f a
$cp1Applicative :: forall t (f :: * -> *). Functor (Rules t f)
Applicative, Applicative (Rules t f)
Rules t f a
Applicative (Rules t f) =>
(forall a. Rules t f a)
-> (forall a. Rules t f a -> Rules t f a -> Rules t f a)
-> (forall a. Rules t f a -> Rules t f [a])
-> (forall a. Rules t f a -> Rules t f [a])
-> Alternative (Rules t f)
Rules t f a -> Rules t f a -> Rules t f a
Rules t f a -> Rules t f [a]
Rules t f a -> Rules t f [a]
forall a. Rules t f a
forall a. Rules t f a -> Rules t f [a]
forall a. Rules t f a -> Rules t f a -> Rules t f a
forall t (f :: * -> *). Applicative (Rules t f)
forall t (f :: * -> *) a. Rules t f a
forall t (f :: * -> *) a. Rules t f a -> Rules t f [a]
forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: Rules t f a -> Rules t f [a]
$cmany :: forall t (f :: * -> *) a. Rules t f a -> Rules t f [a]
some :: Rules t f a -> Rules t f [a]
$csome :: forall t (f :: * -> *) a. Rules t f a -> Rules t f [a]
<|> :: Rules t f a -> Rules t f a -> Rules t f a
$c<|> :: forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
empty :: Rules t f a
$cempty :: forall t (f :: * -> *) a. Rules t f a
$cp1Alternative :: forall t (f :: * -> *). Applicative (Rules t f)
Alternative, b -> Rules t f a -> Rules t f a
NonEmpty (Rules t f a) -> Rules t f a
Rules t f a -> Rules t f a -> Rules t f a
(Rules t f a -> Rules t f a -> Rules t f a)
-> (NonEmpty (Rules t f a) -> Rules t f a)
-> (forall b. Integral b => b -> Rules t f a -> Rules t f a)
-> Semigroup (Rules t f a)
forall b. Integral b => b -> Rules t f a -> Rules t f a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall t (f :: * -> *) a. NonEmpty (Rules t f a) -> Rules t f a
forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
forall t (f :: * -> *) a b.
Integral b =>
b -> Rules t f a -> Rules t f a
stimes :: b -> Rules t f a -> Rules t f a
$cstimes :: forall t (f :: * -> *) a b.
Integral b =>
b -> Rules t f a -> Rules t f a
sconcat :: NonEmpty (Rules t f a) -> Rules t f a
$csconcat :: forall t (f :: * -> *) a. NonEmpty (Rules t f a) -> Rules t f a
<> :: Rules t f a -> Rules t f a -> Rules t f a
$c<> :: forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
Semigroup, Semigroup (Rules t f a)
Rules t f a
Semigroup (Rules t f a) =>
Rules t f a
-> (Rules t f a -> Rules t f a -> Rules t f a)
-> ([Rules t f a] -> Rules t f a)
-> Monoid (Rules t f a)
[Rules t f a] -> Rules t f a
Rules t f a -> Rules t f a -> Rules t f a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall t (f :: * -> *) a. Semigroup (Rules t f a)
forall t (f :: * -> *) a. Rules t f a
forall t (f :: * -> *) a. [Rules t f a] -> Rules t f a
forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
mconcat :: [Rules t f a] -> Rules t f a
$cmconcat :: forall t (f :: * -> *) a. [Rules t f a] -> Rules t f a
mappend :: Rules t f a -> Rules t f a -> Rules t f a
$cmappend :: forall t (f :: * -> *) a. Rules t f a -> Rules t f a -> Rules t f a
mempty :: Rules t f a
$cmempty :: forall t (f :: * -> *) a. Rules t f a
$cp1Monoid :: forall t (f :: * -> *) a. Semigroup (Rules t f a)
Monoid)

-- | Lift a single rule into the 'Rules' functor.
rule :: RuleFor t f a -> Rules t f a
rule :: RuleFor t f a -> Rules t f a
rule = Alt (Rule t f) a -> Rules t f a
forall t (f :: * -> *) a. Alt (Rule t f) a -> Rules t f a
Rules (Alt (Rule t f) a -> Rules t f a)
-> (RuleFor t f a -> Alt (Rule t f) a)
-> RuleFor t f a
-> Rules t f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rule t f a -> Alt (Rule t f) a
forall (f :: * -> *) a. f a -> Alt f a
Alt.liftAlt (Rule t f a -> Alt (Rule t f) a)
-> (RuleFor t f a -> Rule t f a)
-> RuleFor t f a
-> Alt (Rule t f) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RuleFor t f a -> Rule t f a
forall t (f :: * -> *) a. RuleFor t f a -> Rule t f a
RuleFor

-- | Lift a contextual item into 'Rules'.
local :: Functor f => f a -> Rules t f a
local :: f a -> Rules t f a
local = Alt (Rule t f) a -> Rules t f a
forall t (f :: * -> *) a. Alt (Rule t f) a -> Rules t f a
Rules (Alt (Rule t f) a -> Rules t f a)
-> (f a -> Alt (Rule t f) a) -> f a -> Rules t f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rule t f a -> Alt (Rule t f) a
forall (f :: * -> *) a. f a -> Alt f a
Alt.liftAlt (Rule t f a -> Alt (Rule t f) a)
-> (f a -> Rule t f a) -> f a -> Alt (Rule t f) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> Rule t f a
forall t (f :: * -> *) a. f a -> Rule t f a
Escape

-- | Get the currently focused node as a value.
self :: Rules t f t
self :: Rules t f t
self = Alt (Rule t f) t -> Rules t f t
forall t (f :: * -> *) a. Alt (Rule t f) a -> Rules t f a
Rules (Alt (Rule t f) t -> Rules t f t)
-> (Rule t f t -> Alt (Rule t f) t) -> Rule t f t -> Rules t f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rule t f t -> Alt (Rule t f) t
forall (f :: * -> *) a. f a -> Alt f a
Alt.liftAlt (Rule t f t -> Rules t f t) -> Rule t f t -> Rules t f t
forall a b. (a -> b) -> a -> b
$ (t -> t) -> Rule t f t
forall t (f :: * -> *) a. (t -> a) -> Rule t f a
Self t -> t
forall a. a -> a
id

-- | Given an interpreter which can convert 'Rule's into the functor @g@,
-- convert 'Rules' into the functor @g@.
runRules
    :: Alternative g => (forall b . Rule t f b -> g b) -> Rules t f a -> g a
runRules :: (forall b. Rule t f b -> g b) -> Rules t f a -> g a
runRules interpret :: forall b. Rule t f b -> g b
interpret = (forall b. Rule t f b -> g b) -> Alt (Rule t f) a -> g a
forall (f :: * -> *) (g :: * -> *) a.
Alternative g =>
(forall x. f x -> g x) -> Alt f a -> g a
Alt.runAlt forall b. Rule t f b -> g b
interpret (Alt (Rule t f) a -> g a)
-> (Rules t f a -> Alt (Rule t f) a) -> Rules t f a -> g a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rules t f a -> Alt (Rule t f) a
forall t (f :: * -> *) a. Rules t f a -> Alt (Rule t f) a
_runRules

-- | Map over the contextual functor @f@ in 'Rules'.
hoist :: HoistRuleFor t => (forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist :: (forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist fToG :: forall b. f b -> g b
fToG = Alt (Rule t g) a -> Rules t g a
forall t (f :: * -> *) a. Alt (Rule t f) a -> Rules t f a
Rules (Alt (Rule t g) a -> Rules t g a)
-> (Rules t f a -> Alt (Rule t g) a) -> Rules t f a -> Rules t g a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Rule t f a -> Rule t g a)
-> Alt (Rule t f) a -> Alt (Rule t g) a
forall (f :: * -> *) (g :: * -> *) b.
(forall a. f a -> g a) -> Alt f b -> Alt g b
Alt.hoistAlt ((forall b. f b -> g b) -> Rule t f a -> Rule t g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rule t f a -> Rule t g a
hoistRule forall b. f b -> g b
fToG) (Alt (Rule t f) a -> Alt (Rule t g) a)
-> (Rules t f a -> Alt (Rule t f) a)
-> Rules t f a
-> Alt (Rule t g) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rules t f a -> Alt (Rule t f) a
forall t (f :: * -> *) a. Rules t f a -> Alt (Rule t f) a
_runRules

-- | Map over 'Rules'.
mapRules
    :: forall a a' t t' f
     . (Functor f, Functor (RuleFor t' f))
    => (forall x . RuleFor t f x -> RuleFor t' f x)
      -- ^ Maps over rules themselves, keeping the context and output types the
      -- same.
    -> (t' -> t)
      -- ^ Maps over the input to rules.
    -> (a -> a')
      -- ^ Maps over the output of rules.
    -> Rules t f a
    -> Rules t' f a'
mapRules :: (forall x. RuleFor t f x -> RuleFor t' f x)
-> (t' -> t) -> (a -> a') -> Rules t f a -> Rules t' f a'
mapRules f :: forall x. RuleFor t f x -> RuleFor t' f x
f g :: t' -> t
g h :: a -> a'
h (Rules alt :: Alt (Rule t f) a
alt) = Alt (Rule t' f) a' -> Rules t' f a'
forall t (f :: * -> *) a. Alt (Rule t f) a -> Rules t f a
Rules (Alt (Rule t' f) a' -> Rules t' f a')
-> Alt (Rule t' f) a' -> Rules t' f a'
forall a b. (a -> b) -> a -> b
$ a -> a'
h (a -> a') -> Alt (Rule t' f) a -> Alt (Rule t' f) a'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Rule t f a -> Rule t' f a)
-> Alt (Rule t f) a -> Alt (Rule t' f) a
forall (f :: * -> *) (g :: * -> *) b.
(forall a. f a -> g a) -> Alt f b -> Alt g b
Alt.hoistAlt ((forall x. RuleFor t f x -> RuleFor t' f x)
-> (t' -> t) -> (a -> a) -> Rule t f a -> Rule t' f a
forall (f :: * -> *) t' t a a'.
(Functor f, Functor (RuleFor t' f)) =>
(forall x. RuleFor t f x -> RuleFor t' f x)
-> (t' -> t) -> (a -> a') -> Rule t f a -> Rule t' f a'
mapRule forall x. RuleFor t f x -> RuleFor t' f x
f t' -> t
g a -> a
forall a. a -> a
id) Alt (Rule t f) a
alt

-------------------------------------------------------------------------------
-- | An individual 'Rule' in isolation.
data Rule t f a =
    RuleFor (RuleFor t f a)   -- ^ A rule specific to the input type @t@
  | Escape  (f a) -- ^ An escape hatch, allowing arbitrary computation
  | Self    (t -> a)          -- ^ A rule which converts the input type to an output.

instance (Functor f, Functor (RuleFor t f)) => Functor (Rule t f) where
    fmap :: (a -> b) -> Rule t f a -> Rule t f b
fmap fn :: a -> b
fn x :: Rule t f a
x = case Rule t f a
x of
        RuleFor rule :: RuleFor t f a
rule -> RuleFor t f b -> Rule t f b
forall t (f :: * -> *) a. RuleFor t f a -> Rule t f a
RuleFor (RuleFor t f b -> Rule t f b) -> RuleFor t f b -> Rule t f b
forall a b. (a -> b) -> a -> b
$ a -> b
fn (a -> b) -> RuleFor t f a -> RuleFor t f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RuleFor t f a
rule
        Escape  rule :: f a
rule -> f b -> Rule t f b
forall t (f :: * -> *) a. f a -> Rule t f a
Escape (f b -> Rule t f b) -> f b -> Rule t f b
forall a b. (a -> b) -> a -> b
$ a -> b
fn (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
rule
        Self    self :: t -> a
self -> (t -> b) -> Rule t f b
forall t (f :: * -> *) a. (t -> a) -> Rule t f a
Self ((t -> b) -> Rule t f b) -> (t -> b) -> Rule t f b
forall a b. (a -> b) -> a -> b
$ a -> b
fn (a -> b) -> (t -> a) -> t -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> a
self

hoistRule :: HoistRuleFor t => (forall b. f b -> g b) -> Rule t f a -> Rule t g a
hoistRule :: (forall b. f b -> g b) -> Rule t f a -> Rule t g a
hoistRule f :: forall b. f b -> g b
f (RuleFor rf :: RuleFor t f a
rf) = RuleFor t g a -> Rule t g a
forall t (f :: * -> *) a. RuleFor t f a -> Rule t f a
RuleFor ((forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
hoistRuleFor forall b. f b -> g b
f RuleFor t f a
rf)
hoistRule f :: forall b. f b -> g b
f (Escape fa :: f a
fa)  = g a -> Rule t g a
forall t (f :: * -> *) a. f a -> Rule t f a
Escape (f a -> g a
forall b. f b -> g b
f f a
fa)
hoistRule _ (Self fn :: t -> a
fn)    = (t -> a) -> Rule t g a
forall t (f :: * -> *) a. (t -> a) -> Rule t f a
Self t -> a
fn

mapRule
    :: (Functor f, Functor (RuleFor t' f))
    => (forall x . RuleFor t f x -> RuleFor t' f x)
    -> (t' -> t)
    -> (a -> a')
    -> Rule t f a
    -> Rule t' f a'
mapRule :: (forall x. RuleFor t f x -> RuleFor t' f x)
-> (t' -> t) -> (a -> a') -> Rule t f a -> Rule t' f a'
mapRule f :: forall x. RuleFor t f x -> RuleFor t' f x
f _ h :: a -> a'
h (RuleFor r :: RuleFor t f a
r   ) = RuleFor t' f a' -> Rule t' f a'
forall t (f :: * -> *) a. RuleFor t f a -> Rule t f a
RuleFor (RuleFor t' f a' -> Rule t' f a')
-> (RuleFor t f a -> RuleFor t' f a')
-> RuleFor t f a
-> Rule t' f a'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a') -> RuleFor t' f a -> RuleFor t' f a'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a'
h (RuleFor t' f a -> RuleFor t' f a')
-> (RuleFor t f a -> RuleFor t' f a)
-> RuleFor t f a
-> RuleFor t' f a'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RuleFor t f a -> RuleFor t' f a
forall x. RuleFor t f x -> RuleFor t' f x
f (RuleFor t f a -> Rule t' f a') -> RuleFor t f a -> Rule t' f a'
forall a b. (a -> b) -> a -> b
$ RuleFor t f a
r
mapRule _ _ h :: a -> a'
h (Escape  es :: f a
es  ) = f a' -> Rule t' f a'
forall t (f :: * -> *) a. f a -> Rule t f a
Escape (f a' -> Rule t' f a') -> f a' -> Rule t' f a'
forall a b. (a -> b) -> a -> b
$ a -> a'
h (a -> a') -> f a -> f a'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
es
mapRule _ g :: t' -> t
g h :: a -> a'
h (Self    self :: t -> a
self) = (t' -> a') -> Rule t' f a'
forall t (f :: * -> *) a. (t -> a) -> Rule t f a
Self ((t' -> a') -> Rule t' f a') -> (t' -> a') -> Rule t' f a'
forall a b. (a -> b) -> a -> b
$ a -> a'
h (a -> a') -> (t' -> a) -> t' -> a'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> a
self (t -> a) -> (t' -> t) -> t' -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t' -> t
g

-------------------------------------------------------------------------------
-- | Defines a relationship between input types and rules specific to those
-- input types.
type family RuleFor t = (rule :: (* -> *) -> * -> *) | rule -> t where
  RuleFor Block        = BlockRule
  RuleFor Document     = DocumentRule
  RuleFor Fragment     = FragmentRule
  RuleFor Inline       = InlineRule
  RuleFor Metadata     = MetadataRule
  RuleFor Paragraph    = ParagraphRule
  RuleFor (Region   a) = RegionRule   a
  RuleFor (Series   a) = SeriesRule   a
  RuleFor (SeriesNE a) = SeriesNERule a
  RuleFor (Tag      a) = TagRule      a
  RuleFor           a  = Void         a

-- | A class defining how to map over the contextual parameter @f@ in a rule for
-- the type @t@.
class HoistRuleFor t where
    hoistRuleFor :: (forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a

-------------------------------------------------------------------------------
-- | Rules for matching specific types of 'Block' nodes.
data BlockRule f a =
    BlockRuleBlockTag   (Rules BlockTag   f a)
  | BlockRuleLiteralTag (Rules LiteralTag f a)
  | BlockRuleParagraph  (Rules Paragraph  f a)
  deriving stock a -> BlockRule f b -> BlockRule f a
(a -> b) -> BlockRule f a -> BlockRule f b
(forall a b. (a -> b) -> BlockRule f a -> BlockRule f b)
-> (forall a b. a -> BlockRule f b -> BlockRule f a)
-> Functor (BlockRule f)
forall a b. a -> BlockRule f b -> BlockRule f a
forall a b. (a -> b) -> BlockRule f a -> BlockRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) a b. a -> BlockRule f b -> BlockRule f a
forall (f :: * -> *) a b.
(a -> b) -> BlockRule f a -> BlockRule f b
<$ :: a -> BlockRule f b -> BlockRule f a
$c<$ :: forall (f :: * -> *) a b. a -> BlockRule f b -> BlockRule f a
fmap :: (a -> b) -> BlockRule f a -> BlockRule f b
$cfmap :: forall (f :: * -> *) a b.
(a -> b) -> BlockRule f a -> BlockRule f b
Functor

instance HoistRuleFor Block where
    hoistRuleFor :: (forall b. f b -> g b) -> RuleFor Block f a -> RuleFor Block g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        BlockRuleBlockTag rules -> Rules BlockTag g a -> RuleFor Block g a
forall (f :: * -> *) a. Rules BlockTag f a -> BlockRule f a
BlockRuleBlockTag (Rules BlockTag g a -> RuleFor Block g a)
-> Rules BlockTag g a -> RuleFor Block g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b) -> Rules BlockTag f a -> Rules BlockTag g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules BlockTag f a
rules
        BlockRuleLiteralTag rules -> Rules LiteralTag g a -> RuleFor Block g a
forall (f :: * -> *) a. Rules LiteralTag f a -> BlockRule f a
BlockRuleLiteralTag (Rules LiteralTag g a -> RuleFor Block g a)
-> Rules LiteralTag g a -> RuleFor Block g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> Rules LiteralTag f a -> Rules LiteralTag g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules LiteralTag f a
rules
        BlockRuleParagraph rules -> Rules Paragraph g a -> RuleFor Block g a
forall (f :: * -> *) a. Rules Paragraph f a -> BlockRule f a
BlockRuleParagraph (Rules Paragraph g a -> RuleFor Block g a)
-> Rules Paragraph g a -> RuleFor Block g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> Rules Paragraph f a -> Rules Paragraph g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules Paragraph f a
rules

-------------------------------------------------------------------------------
-- | Rules applying to 'Document's.
newtype DocumentRule f a =
    DocumentRule (RegionRule (Series Block) f a)
  deriving newtype a -> DocumentRule f b -> DocumentRule f a
(a -> b) -> DocumentRule f a -> DocumentRule f b
(forall a b. (a -> b) -> DocumentRule f a -> DocumentRule f b)
-> (forall a b. a -> DocumentRule f b -> DocumentRule f a)
-> Functor (DocumentRule f)
forall a b. a -> DocumentRule f b -> DocumentRule f a
forall a b. (a -> b) -> DocumentRule f a -> DocumentRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) a b. a -> DocumentRule f b -> DocumentRule f a
forall (f :: * -> *) a b.
(a -> b) -> DocumentRule f a -> DocumentRule f b
<$ :: a -> DocumentRule f b -> DocumentRule f a
$c<$ :: forall (f :: * -> *) a b. a -> DocumentRule f b -> DocumentRule f a
fmap :: (a -> b) -> DocumentRule f a -> DocumentRule f b
$cfmap :: forall (f :: * -> *) a b.
(a -> b) -> DocumentRule f a -> DocumentRule f b
Functor

instance HoistRuleFor Document where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor Document f a -> RuleFor Document g a
hoistRuleFor f :: forall b. f b -> g b
f = \case 
        DocumentRule r -> RegionRule (Series Block) g a -> RuleFor Document g a
forall (f :: * -> *) a.
RegionRule (Series Block) f a -> DocumentRule f a
DocumentRule (RegionRule (Series Block) g a -> RuleFor Document g a)
-> RegionRule (Series Block) g a -> RuleFor Document g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> RuleFor (Region (Series Block)) f a
-> RuleFor (Region (Series Block)) g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
hoistRuleFor forall b. f b -> g b
f RegionRule (Series Block) f a
RuleFor (Region (Series Block)) f a
r

-------------------------------------------------------------------------------
-- | Rules applying to 'Fragment's (i.e. plain text).
data FragmentRule f a =
    FragmentRuleLocation (Maybe Location -> a)
  | FragmentRuleText     (Text           -> a)
  deriving stock a -> FragmentRule f b -> FragmentRule f a
(a -> b) -> FragmentRule f a -> FragmentRule f b
(forall a b. (a -> b) -> FragmentRule f a -> FragmentRule f b)
-> (forall a b. a -> FragmentRule f b -> FragmentRule f a)
-> Functor (FragmentRule f)
forall k (f :: k) a b. a -> FragmentRule f b -> FragmentRule f a
forall k (f :: k) a b.
(a -> b) -> FragmentRule f a -> FragmentRule f b
forall a b. a -> FragmentRule f b -> FragmentRule f a
forall a b. (a -> b) -> FragmentRule f a -> FragmentRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> FragmentRule f b -> FragmentRule f a
$c<$ :: forall k (f :: k) a b. a -> FragmentRule f b -> FragmentRule f a
fmap :: (a -> b) -> FragmentRule f a -> FragmentRule f b
$cfmap :: forall k (f :: k) a b.
(a -> b) -> FragmentRule f a -> FragmentRule f b
Functor

instance HoistRuleFor Fragment where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor Fragment f a -> RuleFor Fragment g a
hoistRuleFor _ = \case
        FragmentRuleLocation fn -> (Maybe Location -> a) -> FragmentRule g a
forall k (f :: k) a. (Maybe Location -> a) -> FragmentRule f a
FragmentRuleLocation Maybe Location -> a
fn
        FragmentRuleText fn -> (Text -> a) -> FragmentRule g a
forall k (f :: k) a. (Text -> a) -> FragmentRule f a
FragmentRuleText Text -> a
fn

-------------------------------------------------------------------------------
-- | Rules for matching specific types of 'Inline' nodes.
data InlineRule f a =
    InlineRuleBreak     a
  | InlineRuleFragment  (Rules Fragment  f a)
  | InlineRuleInlineTag (Rules InlineTag f a)
  deriving stock a -> InlineRule f b -> InlineRule f a
(a -> b) -> InlineRule f a -> InlineRule f b
(forall a b. (a -> b) -> InlineRule f a -> InlineRule f b)
-> (forall a b. a -> InlineRule f b -> InlineRule f a)
-> Functor (InlineRule f)
forall a b. a -> InlineRule f b -> InlineRule f a
forall a b. (a -> b) -> InlineRule f a -> InlineRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) a b. a -> InlineRule f b -> InlineRule f a
forall (f :: * -> *) a b.
(a -> b) -> InlineRule f a -> InlineRule f b
<$ :: a -> InlineRule f b -> InlineRule f a
$c<$ :: forall (f :: * -> *) a b. a -> InlineRule f b -> InlineRule f a
fmap :: (a -> b) -> InlineRule f a -> InlineRule f b
$cfmap :: forall (f :: * -> *) a b.
(a -> b) -> InlineRule f a -> InlineRule f b
Functor

instance HoistRuleFor Inline where
    hoistRuleFor :: (forall b. f b -> g b) -> RuleFor Inline f a -> RuleFor Inline g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        InlineRuleBreak a -> a -> InlineRule g a
forall (f :: * -> *) a. a -> InlineRule f a
InlineRuleBreak a
a
        InlineRuleFragment rules -> Rules Fragment g a -> RuleFor Inline g a
forall (f :: * -> *) a. Rules Fragment f a -> InlineRule f a
InlineRuleFragment (Rules Fragment g a -> RuleFor Inline g a)
-> Rules Fragment g a -> RuleFor Inline g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b) -> Rules Fragment f a -> Rules Fragment g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules Fragment f a
rules
        InlineRuleInlineTag rules -> Rules InlineTag g a -> RuleFor Inline g a
forall (f :: * -> *) a. Rules InlineTag f a -> InlineRule f a
InlineRuleInlineTag (Rules InlineTag g a -> RuleFor Inline g a)
-> Rules InlineTag g a -> RuleFor Inline g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> Rules InlineTag f a -> Rules InlineTag g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules InlineTag f a
rules

-------------------------------------------------------------------------------
-- | Rules for operating on properties and settings.
data MetadataRule f a =
    MetadataRuleProperty (Bool -> a) Key
  | MetadataRuleSetting  (Text -> Either String a) (Maybe a) Key
  | MetadataRuleAllowUnknown a
  deriving stock a -> MetadataRule f b -> MetadataRule f a
(a -> b) -> MetadataRule f a -> MetadataRule f b
(forall a b. (a -> b) -> MetadataRule f a -> MetadataRule f b)
-> (forall a b. a -> MetadataRule f b -> MetadataRule f a)
-> Functor (MetadataRule f)
forall k (f :: k) a b. a -> MetadataRule f b -> MetadataRule f a
forall k (f :: k) a b.
(a -> b) -> MetadataRule f a -> MetadataRule f b
forall a b. a -> MetadataRule f b -> MetadataRule f a
forall a b. (a -> b) -> MetadataRule f a -> MetadataRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MetadataRule f b -> MetadataRule f a
$c<$ :: forall k (f :: k) a b. a -> MetadataRule f b -> MetadataRule f a
fmap :: (a -> b) -> MetadataRule f a -> MetadataRule f b
$cfmap :: forall k (f :: k) a b.
(a -> b) -> MetadataRule f a -> MetadataRule f b
Functor

instance HoistRuleFor Metadata where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor Metadata f a -> RuleFor Metadata g a
hoistRuleFor _ = \case
        MetadataRuleProperty fn key -> (Bool -> a) -> Key -> MetadataRule g a
forall k (f :: k) a. (Bool -> a) -> Key -> MetadataRule f a
MetadataRuleProperty Bool -> a
fn Key
key
        MetadataRuleSetting fn def key -> (Text -> Either String a) -> Maybe a -> Key -> MetadataRule g a
forall k (f :: k) a.
(Text -> Either String a) -> Maybe a -> Key -> MetadataRule f a
MetadataRuleSetting Text -> Either String a
fn Maybe a
def Key
key
        MetadataRuleAllowUnknown a -> a -> MetadataRule g a
forall k (f :: k) a. a -> MetadataRule f a
MetadataRuleAllowUnknown a
a

-------------------------------------------------------------------------------
-- | Rules for accessing paragraphs.
data ParagraphRule f a =
    ParagraphRuleContent  (Rules (SeriesNE Inline) f a)
  | ParagraphRuleLocation (Maybe Location -> a)
  deriving stock a -> ParagraphRule f b -> ParagraphRule f a
(a -> b) -> ParagraphRule f a -> ParagraphRule f b
(forall a b. (a -> b) -> ParagraphRule f a -> ParagraphRule f b)
-> (forall a b. a -> ParagraphRule f b -> ParagraphRule f a)
-> Functor (ParagraphRule f)
forall a b. a -> ParagraphRule f b -> ParagraphRule f a
forall a b. (a -> b) -> ParagraphRule f a -> ParagraphRule f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) a b.
a -> ParagraphRule f b -> ParagraphRule f a
forall (f :: * -> *) a b.
(a -> b) -> ParagraphRule f a -> ParagraphRule f b
<$ :: a -> ParagraphRule f b -> ParagraphRule f a
$c<$ :: forall (f :: * -> *) a b.
a -> ParagraphRule f b -> ParagraphRule f a
fmap :: (a -> b) -> ParagraphRule f a -> ParagraphRule f b
$cfmap :: forall (f :: * -> *) a b.
(a -> b) -> ParagraphRule f a -> ParagraphRule f b
Functor

instance HoistRuleFor Paragraph where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor Paragraph f a -> RuleFor Paragraph g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        ParagraphRuleContent rules -> Rules (SeriesNE Inline) g a -> RuleFor Paragraph g a
forall (f :: * -> *) a.
Rules (SeriesNE Inline) f a -> ParagraphRule f a
ParagraphRuleContent (Rules (SeriesNE Inline) g a -> RuleFor Paragraph g a)
-> Rules (SeriesNE Inline) g a -> RuleFor Paragraph g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> Rules (SeriesNE Inline) f a -> Rules (SeriesNE Inline) g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules (SeriesNE Inline) f a
rules
        ParagraphRuleLocation fn -> (Maybe Location -> a) -> ParagraphRule g a
forall (f :: * -> *) a. (Maybe Location -> a) -> ParagraphRule f a
ParagraphRuleLocation Maybe Location -> a
fn

-------------------------------------------------------------------------------
-- | Rules for operating on a 'Region'.
data RegionRule t f a =
    RegionRuleLocation (Maybe Location -> a)
  | RegionRuleMetadata (MetadataRule f a)
  | RegionRuleContent  (Rules t f a)
  deriving stock a -> RegionRule t f b -> RegionRule t f a
(a -> b) -> RegionRule t f a -> RegionRule t f b
(forall a b. (a -> b) -> RegionRule t f a -> RegionRule t f b)
-> (forall a b. a -> RegionRule t f b -> RegionRule t f a)
-> Functor (RegionRule t f)
forall a b. a -> RegionRule t f b -> RegionRule t f a
forall a b. (a -> b) -> RegionRule t f a -> RegionRule t f b
forall t (f :: * -> *) a b.
a -> RegionRule t f b -> RegionRule t f a
forall t (f :: * -> *) a b.
(a -> b) -> RegionRule t f a -> RegionRule t f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RegionRule t f b -> RegionRule t f a
$c<$ :: forall t (f :: * -> *) a b.
a -> RegionRule t f b -> RegionRule t f a
fmap :: (a -> b) -> RegionRule t f a -> RegionRule t f b
$cfmap :: forall t (f :: * -> *) a b.
(a -> b) -> RegionRule t f a -> RegionRule t f b
Functor

instance HoistRuleFor t => HoistRuleFor (Region t) where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor (Region t) f a -> RuleFor (Region t) g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        RegionRuleLocation fn   -> (Maybe Location -> a) -> RegionRule t g a
forall t (f :: * -> *) a. (Maybe Location -> a) -> RegionRule t f a
RegionRuleLocation Maybe Location -> a
fn
        RegionRuleMetadata rule -> MetadataRule g a -> RuleFor (Region t) g a
forall t (f :: * -> *) a. MetadataRule f a -> RegionRule t f a
RegionRuleMetadata (MetadataRule g a -> RuleFor (Region t) g a)
-> MetadataRule g a -> RuleFor (Region t) g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> RuleFor Metadata f a -> RuleFor Metadata g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
hoistRuleFor forall b. f b -> g b
f MetadataRule f a
RuleFor Metadata f a
rule
        RegionRuleContent rules -> Rules t g a -> RuleFor (Region t) g a
forall t (f :: * -> *) a. Rules t f a -> RegionRule t f a
RegionRuleContent (Rules t g a -> RuleFor (Region t) g a)
-> Rules t g a -> RuleFor (Region t) g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b) -> Rules t f a -> Rules t g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules t f a
rules

-------------------------------------------------------------------------------
-- | Operates sequentially against a collection of nodes.
data SeriesRule t f a =
    SeriesRuleNext (SeriesNERule t f a)
  | SeriesRuleEmpty a

instance Functor (SeriesRule t f) where
    fmap :: (a -> b) -> SeriesRule t f a -> SeriesRule t f b
fmap fn :: a -> b
fn (SeriesRuleNext  rule :: SeriesNERule t f a
rule) = SeriesNERule t f b -> SeriesRule t f b
forall t (f :: * -> *) a. SeriesNERule t f a -> SeriesRule t f a
SeriesRuleNext ((a -> b) -> SeriesNERule t f a -> SeriesNERule t f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
fn SeriesNERule t f a
rule)
    fmap fn :: a -> b
fn (SeriesRuleEmpty x :: a
x   ) = b -> SeriesRule t f b
forall t (f :: * -> *) a. a -> SeriesRule t f a
SeriesRuleEmpty (a -> b
fn a
x)

instance HoistRuleFor t => HoistRuleFor (Series t) where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor (Series t) f a -> RuleFor (Series t) g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        SeriesRuleNext rule -> SeriesNERule t g a -> RuleFor (Series t) g a
forall t (f :: * -> *) a. SeriesNERule t f a -> SeriesRule t f a
SeriesRuleNext (SeriesNERule t g a -> RuleFor (Series t) g a)
-> SeriesNERule t g a -> RuleFor (Series t) g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> RuleFor (SeriesNE t) f a -> RuleFor (SeriesNE t) g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
hoistRuleFor forall b. f b -> g b
f SeriesNERule t f a
RuleFor (SeriesNE t) f a
rule
        SeriesRuleEmpty a -> a -> SeriesRule t g a
forall t (f :: * -> *) a. a -> SeriesRule t f a
SeriesRuleEmpty a
a

-------------------------------------------------------------------------------
-- | Operates sequentially against a non-empty collection of nodes.
data SeriesNERule t f a =
    forall b c. SeriesNERule (b -> c -> a) (Rules t f b) (Rules (Series t) f c)

instance Functor (SeriesNERule t f) where
    fmap :: (a -> b) -> SeriesNERule t f a -> SeriesNERule t f b
fmap fn :: a -> b
fn (SeriesNERule k :: b -> c -> a
k rule :: Rules t f b
rule next :: Rules (Series t) f c
next) = (b -> c -> b)
-> Rules t f b -> Rules (Series t) f c -> SeriesNERule t f b
forall t (f :: * -> *) a b c.
(b -> c -> a)
-> Rules t f b -> Rules (Series t) f c -> SeriesNERule t f a
SeriesNERule ((a -> b) -> (c -> a) -> c -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
fn ((c -> a) -> c -> b) -> (b -> c -> a) -> b -> c -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> c -> a
k) Rules t f b
rule Rules (Series t) f c
next

instance HoistRuleFor t => HoistRuleFor (SeriesNE t) where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor (SeriesNE t) f a -> RuleFor (SeriesNE t) g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        SeriesNERule k r1 rs -> (b -> c -> a)
-> Rules t g b -> Rules (Series t) g c -> SeriesNERule t g a
forall t (f :: * -> *) a b c.
(b -> c -> a)
-> Rules t f b -> Rules (Series t) f c -> SeriesNERule t f a
SeriesNERule b -> c -> a
k ((forall b. f b -> g b) -> Rules t f b -> Rules t g b
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules t f b
r1) ((forall b. f b -> g b)
-> Rules (Series t) f c -> Rules (Series t) g c
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> Rules t f a -> Rules t g a
hoist forall b. f b -> g b
f Rules (Series t) f c
rs)

-------------------------------------------------------------------------------
-- | Rules for operating on 'Tag's.
data TagRule t f a =
    TagRuleKey Key a
  | TagRuleRegion (RegionRule t f a)
  deriving stock a -> TagRule t f b -> TagRule t f a
(a -> b) -> TagRule t f a -> TagRule t f b
(forall a b. (a -> b) -> TagRule t f a -> TagRule t f b)
-> (forall a b. a -> TagRule t f b -> TagRule t f a)
-> Functor (TagRule t f)
forall a b. a -> TagRule t f b -> TagRule t f a
forall a b. (a -> b) -> TagRule t f a -> TagRule t f b
forall t (f :: * -> *) a b. a -> TagRule t f b -> TagRule t f a
forall t (f :: * -> *) a b.
(a -> b) -> TagRule t f a -> TagRule t f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> TagRule t f b -> TagRule t f a
$c<$ :: forall t (f :: * -> *) a b. a -> TagRule t f b -> TagRule t f a
fmap :: (a -> b) -> TagRule t f a -> TagRule t f b
$cfmap :: forall t (f :: * -> *) a b.
(a -> b) -> TagRule t f a -> TagRule t f b
Functor

instance HoistRuleFor t => HoistRuleFor (Tag t) where
    hoistRuleFor :: (forall b. f b -> g b)
-> RuleFor (Tag t) f a -> RuleFor (Tag t) g a
hoistRuleFor f :: forall b. f b -> g b
f = \case
        TagRuleKey k a -> Key -> a -> TagRule t g a
forall t (f :: * -> *) a. Key -> a -> TagRule t f a
TagRuleKey Key
k a
a
        TagRuleRegion rule -> RegionRule t g a -> RuleFor (Tag t) g a
forall t (f :: * -> *) a. RegionRule t f a -> TagRule t f a
TagRuleRegion (RegionRule t g a -> RuleFor (Tag t) g a)
-> RegionRule t g a -> RuleFor (Tag t) g a
forall a b. (a -> b) -> a -> b
$ (forall b. f b -> g b)
-> RuleFor (Region t) f a -> RuleFor (Region t) g a
forall t (f :: * -> *) (g :: * -> *) a.
HoistRuleFor t =>
(forall b. f b -> g b) -> RuleFor t f a -> RuleFor t g a
hoistRuleFor forall b. f b -> g b
f RegionRule t f a
RuleFor (Region t) f a
rule

-------------------------------------------------------------------------------
instance HoistRuleFor Text where
    hoistRuleFor :: (forall b. f b -> g b) -> RuleFor Text f a -> RuleFor Text g a
hoistRuleFor _ = \case