module Biegunka.Language
( Scope(..)
, Term(..), Action(..), Source(..), Modifier(..)
, PatchSpec(..), React(..)
) where
import Control.Applicative((<$>))
import Data.Foldable (Foldable(..))
import Data.Traversable (Traversable(..), fmapDefault, foldMapDefault)
import Control.Monad.Free (Free(..))
import Data.Copointed (Copointed(..))
import Data.Default (Default(..))
import Data.Set (Set)
import Data.Text.Lazy (Text)
import System.Process (CmdSpec)
import Text.StringTemplate (ToSElem)
import Text.StringTemplate.GenericStandard ()
data Scope = Actions | Sources
data Term :: (Scope -> *) -> Scope -> * -> * where
TS :: f Sources -> Source -> Free (Term f Actions) () -> x -> Term f Sources x
TA :: f Actions -> Action -> x -> Term f Actions x
TM :: Modifier -> x -> Term f s x
instance Functor (Term f s) where
fmap = fmapDefault
instance Foldable (Term f s) where
foldMap = foldMapDefault
instance Traversable (Term f s) where
traverse f (TS a s i x) = TS a s i <$> f x
traverse f (TA a z x) = TA a z <$> f x
traverse f (TM w x) = TM w <$> f x
instance Copointed (Term f s) where
copoint (TS _ _ _ x) = x
copoint (TA _ _ x) = x
copoint (TM _ x) = x
data Source = Source {
stype :: String
, suri :: String
, spath :: FilePath
, supdate :: FilePath -> IO ()
}
data Action =
Link FilePath FilePath
| Copy FilePath FilePath
| Template FilePath FilePath (forall t. ToSElem t => t -> String -> Text)
| Command FilePath CmdSpec
| Patch FilePath FilePath PatchSpec
data PatchSpec = PatchSpec
{ strip :: Int
, reversely :: Bool
}
instance Default PatchSpec where
def = PatchSpec
{ strip = 1
, reversely = False
}
data Modifier =
User (Maybe String)
| Reacting (Maybe React)
| Wait (Set Int)
| Chain
data React = Ignorant | Abortive | Retry
deriving (Show, Read, Eq, Ord, Enum, Bounded)
instance Default React where
def = Ignorant