{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Brassica.SoundChange.Types
(
Grapheme(..)
, PWord
, addBoundaries
, removeBoundaries
, concatWithBoundary
, Lexeme(..)
, pattern Boundary
, LexemeType(..)
, generalise
, mapCategory
, mapCategoryA
, Expanded(..)
, generaliseExpanded
, Rule(..)
, Environment
, Direction(..)
, Flags(..)
, defFlags
, Statement(..)
, plaintext'
, SoundChanges
, CategoryModification(..)
, CategorySpec(..)
, FeatureSpec(..)
, CategoryDefinition(..)
, Directive(..)
, OneOf
) where
import Control.DeepSeq (NFData(..))
import Data.Kind (Constraint)
import Data.String (IsString(..))
import GHC.Generics (Generic)
import GHC.OldList (dropWhileEnd)
import GHC.TypeLits
type family OneOf a x y :: Constraint where
OneOf a a y = ()
OneOf a x a = ()
OneOf a b c =
( () ~ Bool
, TypeError ('Text "Couldn't match type "
':<>: 'ShowType a
':<>: 'Text " with "
':<>: 'ShowType b
':<>: 'Text " or "
':<>: 'ShowType c))
data Grapheme
= GMulti [Char]
| GBoundary
deriving (Grapheme -> Grapheme -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Grapheme -> Grapheme -> Bool
$c/= :: Grapheme -> Grapheme -> Bool
== :: Grapheme -> Grapheme -> Bool
$c== :: Grapheme -> Grapheme -> Bool
Eq, Eq Grapheme
Grapheme -> Grapheme -> Bool
Grapheme -> Grapheme -> Ordering
Grapheme -> Grapheme -> Grapheme
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
min :: Grapheme -> Grapheme -> Grapheme
$cmin :: Grapheme -> Grapheme -> Grapheme
max :: Grapheme -> Grapheme -> Grapheme
$cmax :: Grapheme -> Grapheme -> Grapheme
>= :: Grapheme -> Grapheme -> Bool
$c>= :: Grapheme -> Grapheme -> Bool
> :: Grapheme -> Grapheme -> Bool
$c> :: Grapheme -> Grapheme -> Bool
<= :: Grapheme -> Grapheme -> Bool
$c<= :: Grapheme -> Grapheme -> Bool
< :: Grapheme -> Grapheme -> Bool
$c< :: Grapheme -> Grapheme -> Bool
compare :: Grapheme -> Grapheme -> Ordering
$ccompare :: Grapheme -> Grapheme -> Ordering
Ord, Int -> Grapheme -> ShowS
[Grapheme] -> ShowS
Grapheme -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Grapheme] -> ShowS
$cshowList :: [Grapheme] -> ShowS
show :: Grapheme -> String
$cshow :: Grapheme -> String
showsPrec :: Int -> Grapheme -> ShowS
$cshowsPrec :: Int -> Grapheme -> ShowS
Show, forall x. Rep Grapheme x -> Grapheme
forall x. Grapheme -> Rep Grapheme x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Grapheme x -> Grapheme
$cfrom :: forall x. Grapheme -> Rep Grapheme x
Generic, Grapheme -> ()
forall a. (a -> ()) -> NFData a
rnf :: Grapheme -> ()
$crnf :: Grapheme -> ()
NFData)
instance IsString Grapheme where
fromString :: String -> Grapheme
fromString = String -> Grapheme
GMulti
type PWord = [Grapheme]
addBoundaries :: PWord -> PWord
addBoundaries :: [Grapheme] -> [Grapheme]
addBoundaries [Grapheme]
w = Grapheme
GBoundary forall a. a -> [a] -> [a]
: [Grapheme]
w forall a. [a] -> [a] -> [a]
++ [Grapheme
GBoundary]
removeBoundaries :: PWord -> PWord
removeBoundaries :: [Grapheme] -> [Grapheme]
removeBoundaries = forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
==Grapheme
GBoundary) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd (forall a. Eq a => a -> a -> Bool
==Grapheme
GBoundary)
concatWithBoundary :: PWord -> String
concatWithBoundary :: [Grapheme] -> String
concatWithBoundary = [Grapheme] -> String
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Grapheme] -> [Grapheme]
removeBoundaries
where
go :: [Grapheme] -> String
go = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a b. (a -> b) -> a -> b
$ \case
GMulti String
g -> String
g
Grapheme
GBoundary -> String
"#"
data LexemeType = Target | Replacement | Env | AnyPart
data Lexeme category (a :: LexemeType) where
Grapheme :: Grapheme -> Lexeme category a
Category :: category a -> Lexeme category a
Optional :: [Lexeme category a] -> Lexeme category a
Metathesis :: Lexeme category 'Replacement
Geminate :: Lexeme category a
Wildcard :: OneOf a 'Target 'Env => Lexeme category a -> Lexeme category a
Kleene :: OneOf a 'Target 'Env => Lexeme category a -> Lexeme category a
Discard :: Lexeme category 'Replacement
Backreference :: Int -> category a -> Lexeme category a
Multiple :: category 'Replacement -> Lexeme category 'Replacement
mapCategory :: (forall x. c x -> c' x) -> Lexeme c a -> Lexeme c' a
mapCategory :: forall (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
(forall (x :: LexemeType). c x -> c' x)
-> Lexeme c a -> Lexeme c' a
mapCategory forall (x :: LexemeType). c x -> c' x
_ (Grapheme Grapheme
g) = forall (category :: LexemeType -> *) (a :: LexemeType).
Grapheme -> Lexeme category a
Grapheme Grapheme
g
mapCategory forall (x :: LexemeType). c x -> c' x
f (Category c a
c) = forall (category :: LexemeType -> *) (a :: LexemeType).
category a -> Lexeme category a
Category (forall (x :: LexemeType). c x -> c' x
f c a
c)
mapCategory forall (x :: LexemeType). c x -> c' x
f (Optional [Lexeme c a]
ls) = forall (category :: LexemeType -> *) (a :: LexemeType).
[Lexeme category a] -> Lexeme category a
Optional (forall (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
(forall (x :: LexemeType). c x -> c' x)
-> Lexeme c a -> Lexeme c' a
mapCategory forall (x :: LexemeType). c x -> c' x
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Lexeme c a]
ls)
mapCategory forall (x :: LexemeType). c x -> c' x
_ Lexeme c a
Metathesis = forall (category :: LexemeType -> *). Lexeme category 'Replacement
Metathesis
mapCategory forall (x :: LexemeType). c x -> c' x
_ Lexeme c a
Geminate = forall (category :: LexemeType -> *) (a :: LexemeType).
Lexeme category a
Geminate
mapCategory forall (x :: LexemeType). c x -> c' x
f (Wildcard Lexeme c a
l) = forall (a :: LexemeType) (category :: LexemeType -> *).
OneOf a 'Target 'Env =>
Lexeme category a -> Lexeme category a
Wildcard (forall (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
(forall (x :: LexemeType). c x -> c' x)
-> Lexeme c a -> Lexeme c' a
mapCategory forall (x :: LexemeType). c x -> c' x
f Lexeme c a
l)
mapCategory forall (x :: LexemeType). c x -> c' x
f (Kleene Lexeme c a
l) = forall (a :: LexemeType) (category :: LexemeType -> *).
OneOf a 'Target 'Env =>
Lexeme category a -> Lexeme category a
Kleene (forall (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
(forall (x :: LexemeType). c x -> c' x)
-> Lexeme c a -> Lexeme c' a
mapCategory forall (x :: LexemeType). c x -> c' x
f Lexeme c a
l)
mapCategory forall (x :: LexemeType). c x -> c' x
_ Lexeme c a
Discard = forall (category :: LexemeType -> *). Lexeme category 'Replacement
Discard
mapCategory forall (x :: LexemeType). c x -> c' x
f (Backreference Int
i c a
c) = forall (category :: LexemeType -> *) (a :: LexemeType).
Int -> category a -> Lexeme category a
Backreference Int
i (forall (x :: LexemeType). c x -> c' x
f c a
c)
mapCategory forall (x :: LexemeType). c x -> c' x
f (Multiple c 'Replacement
c) = forall (category :: LexemeType -> *).
category 'Replacement -> Lexeme category 'Replacement
Multiple (forall (x :: LexemeType). c x -> c' x
f c 'Replacement
c)
mapCategoryA
:: Applicative t
=> (forall x. c x -> t (c' x))
-> Lexeme c a
-> t (Lexeme c' a)
mapCategoryA :: forall (t :: * -> *) (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
Applicative t =>
(forall (x :: LexemeType). c x -> t (c' x))
-> Lexeme c a -> t (Lexeme c' a)
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
_ (Grapheme Grapheme
g) = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (category :: LexemeType -> *) (a :: LexemeType).
Grapheme -> Lexeme category a
Grapheme Grapheme
g
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Category c a
c) = forall (category :: LexemeType -> *) (a :: LexemeType).
category a -> Lexeme category a
Category forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (x :: LexemeType). c x -> t (c' x)
f c a
c
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Optional [Lexeme c a]
ls) = forall (category :: LexemeType -> *) (a :: LexemeType).
[Lexeme category a] -> Lexeme category a
Optional forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (t :: * -> *) (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
Applicative t =>
(forall (x :: LexemeType). c x -> t (c' x))
-> Lexeme c a -> t (Lexeme c' a)
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f) [Lexeme c a]
ls
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
_ Lexeme c a
Metathesis = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (category :: LexemeType -> *). Lexeme category 'Replacement
Metathesis
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
_ Lexeme c a
Geminate = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (category :: LexemeType -> *) (a :: LexemeType).
Lexeme category a
Geminate
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Wildcard Lexeme c a
l) = forall (a :: LexemeType) (category :: LexemeType -> *).
OneOf a 'Target 'Env =>
Lexeme category a -> Lexeme category a
Wildcard forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
Applicative t =>
(forall (x :: LexemeType). c x -> t (c' x))
-> Lexeme c a -> t (Lexeme c' a)
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f Lexeme c a
l
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Kleene Lexeme c a
l) = forall (a :: LexemeType) (category :: LexemeType -> *).
OneOf a 'Target 'Env =>
Lexeme category a -> Lexeme category a
Kleene forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (c :: LexemeType -> *) (c' :: LexemeType -> *)
(a :: LexemeType).
Applicative t =>
(forall (x :: LexemeType). c x -> t (c' x))
-> Lexeme c a -> t (Lexeme c' a)
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f Lexeme c a
l
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
_ Lexeme c a
Discard = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (category :: LexemeType -> *). Lexeme category 'Replacement
Discard
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Backreference Int
i c a
c) = forall (category :: LexemeType -> *) (a :: LexemeType).
Int -> category a -> Lexeme category a
Backreference Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (x :: LexemeType). c x -> t (c' x)
f c a
c
mapCategoryA forall (x :: LexemeType). c x -> t (c' x)
f (Multiple c 'Replacement
c) = forall (category :: LexemeType -> *).
category 'Replacement -> Lexeme category 'Replacement
Multiple forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (x :: LexemeType). c x -> t (c' x)
f c 'Replacement
c
newtype Expanded a = FromElements { forall (a :: LexemeType).
Expanded a -> [Either Grapheme [Lexeme Expanded a]]
elements :: [Either Grapheme [Lexeme Expanded a]] }
deriving (Expanded a -> Expanded a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
/= :: Expanded a -> Expanded a -> Bool
$c/= :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
== :: Expanded a -> Expanded a -> Bool
$c== :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
Eq, Expanded a -> Expanded a -> Bool
Expanded a -> Expanded a -> Ordering
Expanded a -> Expanded a -> Expanded a
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
forall (x :: LexemeType). Eq (Expanded x)
forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
forall (a :: LexemeType). Expanded a -> Expanded a -> Ordering
forall (a :: LexemeType). Expanded a -> Expanded a -> Expanded a
min :: Expanded a -> Expanded a -> Expanded a
$cmin :: forall (a :: LexemeType). Expanded a -> Expanded a -> Expanded a
max :: Expanded a -> Expanded a -> Expanded a
$cmax :: forall (a :: LexemeType). Expanded a -> Expanded a -> Expanded a
>= :: Expanded a -> Expanded a -> Bool
$c>= :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
> :: Expanded a -> Expanded a -> Bool
$c> :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
<= :: Expanded a -> Expanded a -> Bool
$c<= :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
< :: Expanded a -> Expanded a -> Bool
$c< :: forall (a :: LexemeType). Expanded a -> Expanded a -> Bool
compare :: Expanded a -> Expanded a -> Ordering
$ccompare :: forall (a :: LexemeType). Expanded a -> Expanded a -> Ordering
Ord, Int -> Expanded a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (a :: LexemeType). Int -> Expanded a -> ShowS
forall (a :: LexemeType). [Expanded a] -> ShowS
forall (a :: LexemeType). Expanded a -> String
showList :: [Expanded a] -> ShowS
$cshowList :: forall (a :: LexemeType). [Expanded a] -> ShowS
show :: Expanded a -> String
$cshow :: forall (a :: LexemeType). Expanded a -> String
showsPrec :: Int -> Expanded a -> ShowS
$cshowsPrec :: forall (a :: LexemeType). Int -> Expanded a -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (a :: LexemeType) x. Rep (Expanded a) x -> Expanded a
forall (a :: LexemeType) x. Expanded a -> Rep (Expanded a) x
$cto :: forall (a :: LexemeType) x. Rep (Expanded a) x -> Expanded a
$cfrom :: forall (a :: LexemeType) x. Expanded a -> Rep (Expanded a) x
Generic, forall a. (a -> ()) -> NFData a
forall (a :: LexemeType). Expanded a -> ()
rnf :: Expanded a -> ()
$crnf :: forall (a :: LexemeType). Expanded a -> ()
NFData)
instance Semigroup (Expanded a) where
(FromElements [Either Grapheme [Lexeme Expanded a]]
es) <> :: Expanded a -> Expanded a -> Expanded a
<> (FromElements [Either Grapheme [Lexeme Expanded a]]
es') = forall (a :: LexemeType).
[Either Grapheme [Lexeme Expanded a]] -> Expanded a
FromElements ([Either Grapheme [Lexeme Expanded a]]
es forall a. Semigroup a => a -> a -> a
<> [Either Grapheme [Lexeme Expanded a]]
es')
instance Monoid (Expanded a) where
mempty :: Expanded a
mempty = forall (a :: LexemeType).
[Either Grapheme [Lexeme Expanded a]] -> Expanded a
FromElements []
generalise :: (c 'AnyPart -> c a) -> Lexeme c 'AnyPart -> Lexeme c a
generalise :: forall (c :: LexemeType -> *) (a :: LexemeType).
(c 'AnyPart -> c a) -> Lexeme c 'AnyPart -> Lexeme c a
generalise c 'AnyPart -> c a
_ (Grapheme Grapheme
g) = forall (category :: LexemeType -> *) (a :: LexemeType).
Grapheme -> Lexeme category a
Grapheme Grapheme
g
generalise c 'AnyPart -> c a
f (Category c 'AnyPart
es) = forall (category :: LexemeType -> *) (a :: LexemeType).
category a -> Lexeme category a
Category forall a b. (a -> b) -> a -> b
$ c 'AnyPart -> c a
f c 'AnyPart
es
generalise c 'AnyPart -> c a
f (Optional [Lexeme c 'AnyPart]
ls) = forall (category :: LexemeType -> *) (a :: LexemeType).
[Lexeme category a] -> Lexeme category a
Optional forall a b. (a -> b) -> a -> b
$ forall (c :: LexemeType -> *) (a :: LexemeType).
(c 'AnyPart -> c a) -> Lexeme c 'AnyPart -> Lexeme c a
generalise c 'AnyPart -> c a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Lexeme c 'AnyPart]
ls
generalise c 'AnyPart -> c a
_ Lexeme c 'AnyPart
Geminate = forall (category :: LexemeType -> *) (a :: LexemeType).
Lexeme category a
Geminate
generalise c 'AnyPart -> c a
f (Backreference Int
i c 'AnyPart
es) = forall (category :: LexemeType -> *) (a :: LexemeType).
Int -> category a -> Lexeme category a
Backreference Int
i forall a b. (a -> b) -> a -> b
$ c 'AnyPart -> c a
f c 'AnyPart
es
generaliseExpanded :: Expanded 'AnyPart -> Expanded a
generaliseExpanded :: forall (a :: LexemeType). Expanded 'AnyPart -> Expanded a
generaliseExpanded = forall (a :: LexemeType).
[Either Grapheme [Lexeme Expanded a]] -> Expanded a
FromElements forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmapforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmapforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) (forall (c :: LexemeType -> *) (a :: LexemeType).
(c 'AnyPart -> c a) -> Lexeme c 'AnyPart -> Lexeme c a
generalise forall (a :: LexemeType). Expanded 'AnyPart -> Expanded a
generaliseExpanded) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: LexemeType).
Expanded a -> [Either Grapheme [Lexeme Expanded a]]
elements
pattern Boundary :: Lexeme c a
pattern $bBoundary :: forall (category :: LexemeType -> *) (a :: LexemeType).
Lexeme category a
$mBoundary :: forall {r} {c :: LexemeType -> *} {a :: LexemeType}.
Lexeme c a -> ((# #) -> r) -> ((# #) -> r) -> r
Boundary = Grapheme GBoundary
deriving instance (forall x. Show (c x)) => Show (Lexeme c a)
deriving instance (forall x. Eq (c x)) => Eq (Lexeme c a)
deriving instance (forall x. Ord (c x)) => Ord (Lexeme c a)
instance (forall x. NFData (c x)) => NFData (Lexeme c a) where
rnf :: Lexeme c a -> ()
rnf (Grapheme Grapheme
g) = forall a. NFData a => a -> ()
rnf Grapheme
g
rnf (Category c a
cs) = forall a. NFData a => a -> ()
rnf c a
cs
rnf (Optional [Lexeme c a]
ls) = forall a. NFData a => a -> ()
rnf [Lexeme c a]
ls
rnf Lexeme c a
Metathesis = ()
rnf Lexeme c a
Geminate = ()
rnf (Wildcard Lexeme c a
l) = forall a. NFData a => a -> ()
rnf Lexeme c a
l
rnf (Kleene Lexeme c a
l) = forall a. NFData a => a -> ()
rnf Lexeme c a
l
rnf Lexeme c a
Discard = ()
rnf (Backreference Int
i c a
l) = seq :: forall a b. a -> b -> b
seq Int
i forall a b. (a -> b) -> a -> b
$ forall a. NFData a => a -> ()
rnf c a
l
rnf (Multiple c 'Replacement
l) = forall a. NFData a => a -> ()
rnf c 'Replacement
l
type Environment c = ([Lexeme c 'Env], [Lexeme c 'Env])
data Direction = LTR | RTL
deriving (Direction -> Direction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Direction -> Direction -> Bool
$c/= :: Direction -> Direction -> Bool
== :: Direction -> Direction -> Bool
$c== :: Direction -> Direction -> Bool
Eq, Int -> Direction -> ShowS
[Direction] -> ShowS
Direction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Direction] -> ShowS
$cshowList :: [Direction] -> ShowS
show :: Direction -> String
$cshow :: Direction -> String
showsPrec :: Int -> Direction -> ShowS
$cshowsPrec :: Int -> Direction -> ShowS
Show, forall x. Rep Direction x -> Direction
forall x. Direction -> Rep Direction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Direction x -> Direction
$cfrom :: forall x. Direction -> Rep Direction x
Generic, Direction -> ()
forall a. (a -> ()) -> NFData a
rnf :: Direction -> ()
$crnf :: Direction -> ()
NFData)
data Flags = Flags
{ Flags -> Bool
highlightChanges :: Bool
, Flags -> Direction
applyDirection :: Direction
, Flags -> Bool
applyOnceOnly :: Bool
, Flags -> Bool
sporadic :: Bool
} deriving (Int -> Flags -> ShowS
[Flags] -> ShowS
Flags -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Flags] -> ShowS
$cshowList :: [Flags] -> ShowS
show :: Flags -> String
$cshow :: Flags -> String
showsPrec :: Int -> Flags -> ShowS
$cshowsPrec :: Int -> Flags -> ShowS
Show, forall x. Rep Flags x -> Flags
forall x. Flags -> Rep Flags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Flags x -> Flags
$cfrom :: forall x. Flags -> Rep Flags x
Generic, Flags -> ()
forall a. (a -> ()) -> NFData a
rnf :: Flags -> ()
$crnf :: Flags -> ()
NFData)
defFlags :: Flags
defFlags :: Flags
defFlags = Flags
{ highlightChanges :: Bool
highlightChanges = Bool
True
, applyDirection :: Direction
applyDirection = Direction
LTR
, applyOnceOnly :: Bool
applyOnceOnly = Bool
False
, sporadic :: Bool
sporadic = Bool
False
}
data Rule c = Rule
{ forall (c :: LexemeType -> *). Rule c -> [Lexeme c 'Target]
target :: [Lexeme c 'Target]
, forall (c :: LexemeType -> *). Rule c -> [Lexeme c 'Replacement]
replacement :: [Lexeme c 'Replacement]
, forall (c :: LexemeType -> *). Rule c -> [Environment c]
environment :: [Environment c]
, forall (c :: LexemeType -> *). Rule c -> Maybe (Environment c)
exception :: Maybe (Environment c)
, forall (c :: LexemeType -> *). Rule c -> Flags
flags :: Flags
, forall (c :: LexemeType -> *). Rule c -> String
plaintext :: String
} deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (c :: LexemeType -> *) x. Rep (Rule c) x -> Rule c
forall (c :: LexemeType -> *) x. Rule c -> Rep (Rule c) x
$cto :: forall (c :: LexemeType -> *) x. Rep (Rule c) x -> Rule c
$cfrom :: forall (c :: LexemeType -> *) x. Rule c -> Rep (Rule c) x
Generic)
deriving instance (forall a. Show (c a)) => Show (Rule c)
deriving instance (forall a. NFData (c a)) => NFData (Rule c)
data Statement c decl = RuleS (Rule c) | DirectiveS decl
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (c :: LexemeType -> *) decl x.
Rep (Statement c decl) x -> Statement c decl
forall (c :: LexemeType -> *) decl x.
Statement c decl -> Rep (Statement c decl) x
$cto :: forall (c :: LexemeType -> *) decl x.
Rep (Statement c decl) x -> Statement c decl
$cfrom :: forall (c :: LexemeType -> *) decl x.
Statement c decl -> Rep (Statement c decl) x
Generic)
deriving instance (forall a. Show (c a), Show decl) => Show (Statement c decl)
deriving instance (forall a. NFData (c a), NFData decl) => NFData (Statement c decl)
plaintext' :: Statement c decl -> String
plaintext' :: forall (c :: LexemeType -> *) decl. Statement c decl -> String
plaintext' (RuleS Rule c
r) = forall (c :: LexemeType -> *). Rule c -> String
plaintext Rule c
r
plaintext' (DirectiveS decl
_) = String
"<directive>"
type SoundChanges c decl = [Statement c decl]
data CategoryModification = Union | Intersect | Subtract
deriving (Int -> CategoryModification -> ShowS
[CategoryModification] -> ShowS
CategoryModification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CategoryModification] -> ShowS
$cshowList :: [CategoryModification] -> ShowS
show :: CategoryModification -> String
$cshow :: CategoryModification -> String
showsPrec :: Int -> CategoryModification -> ShowS
$cshowsPrec :: Int -> CategoryModification -> ShowS
Show, CategoryModification -> CategoryModification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CategoryModification -> CategoryModification -> Bool
$c/= :: CategoryModification -> CategoryModification -> Bool
== :: CategoryModification -> CategoryModification -> Bool
$c== :: CategoryModification -> CategoryModification -> Bool
Eq, Eq CategoryModification
CategoryModification -> CategoryModification -> Bool
CategoryModification -> CategoryModification -> Ordering
CategoryModification
-> CategoryModification -> CategoryModification
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
min :: CategoryModification
-> CategoryModification -> CategoryModification
$cmin :: CategoryModification
-> CategoryModification -> CategoryModification
max :: CategoryModification
-> CategoryModification -> CategoryModification
$cmax :: CategoryModification
-> CategoryModification -> CategoryModification
>= :: CategoryModification -> CategoryModification -> Bool
$c>= :: CategoryModification -> CategoryModification -> Bool
> :: CategoryModification -> CategoryModification -> Bool
$c> :: CategoryModification -> CategoryModification -> Bool
<= :: CategoryModification -> CategoryModification -> Bool
$c<= :: CategoryModification -> CategoryModification -> Bool
< :: CategoryModification -> CategoryModification -> Bool
$c< :: CategoryModification -> CategoryModification -> Bool
compare :: CategoryModification -> CategoryModification -> Ordering
$ccompare :: CategoryModification -> CategoryModification -> Ordering
Ord, forall x. Rep CategoryModification x -> CategoryModification
forall x. CategoryModification -> Rep CategoryModification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CategoryModification x -> CategoryModification
$cfrom :: forall x. CategoryModification -> Rep CategoryModification x
Generic, CategoryModification -> ()
forall a. (a -> ()) -> NFData a
rnf :: CategoryModification -> ()
$crnf :: CategoryModification -> ()
NFData)
data CategorySpec a
= CategorySpec [(CategoryModification, Either Grapheme [Lexeme CategorySpec a])]
| MustInline String
deriving (Int -> CategorySpec a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (a :: LexemeType). Int -> CategorySpec a -> ShowS
forall (a :: LexemeType). [CategorySpec a] -> ShowS
forall (a :: LexemeType). CategorySpec a -> String
showList :: [CategorySpec a] -> ShowS
$cshowList :: forall (a :: LexemeType). [CategorySpec a] -> ShowS
show :: CategorySpec a -> String
$cshow :: forall (a :: LexemeType). CategorySpec a -> String
showsPrec :: Int -> CategorySpec a -> ShowS
$cshowsPrec :: forall (a :: LexemeType). Int -> CategorySpec a -> ShowS
Show, CategorySpec a -> CategorySpec a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
/= :: CategorySpec a -> CategorySpec a -> Bool
$c/= :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
== :: CategorySpec a -> CategorySpec a -> Bool
$c== :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
Eq, CategorySpec a -> CategorySpec a -> Bool
CategorySpec a -> CategorySpec a -> Ordering
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
forall (x :: LexemeType). Eq (CategorySpec x)
forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
forall (a :: LexemeType).
CategorySpec a -> CategorySpec a -> Ordering
forall (a :: LexemeType).
CategorySpec a -> CategorySpec a -> CategorySpec a
min :: CategorySpec a -> CategorySpec a -> CategorySpec a
$cmin :: forall (a :: LexemeType).
CategorySpec a -> CategorySpec a -> CategorySpec a
max :: CategorySpec a -> CategorySpec a -> CategorySpec a
$cmax :: forall (a :: LexemeType).
CategorySpec a -> CategorySpec a -> CategorySpec a
>= :: CategorySpec a -> CategorySpec a -> Bool
$c>= :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
> :: CategorySpec a -> CategorySpec a -> Bool
$c> :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
<= :: CategorySpec a -> CategorySpec a -> Bool
$c<= :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
< :: CategorySpec a -> CategorySpec a -> Bool
$c< :: forall (a :: LexemeType). CategorySpec a -> CategorySpec a -> Bool
compare :: CategorySpec a -> CategorySpec a -> Ordering
$ccompare :: forall (a :: LexemeType).
CategorySpec a -> CategorySpec a -> Ordering
Ord, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (a :: LexemeType) x.
Rep (CategorySpec a) x -> CategorySpec a
forall (a :: LexemeType) x.
CategorySpec a -> Rep (CategorySpec a) x
$cto :: forall (a :: LexemeType) x.
Rep (CategorySpec a) x -> CategorySpec a
$cfrom :: forall (a :: LexemeType) x.
CategorySpec a -> Rep (CategorySpec a) x
Generic, forall a. (a -> ()) -> NFData a
forall (a :: LexemeType). CategorySpec a -> ()
rnf :: CategorySpec a -> ()
$crnf :: forall (a :: LexemeType). CategorySpec a -> ()
NFData)
data FeatureSpec = FeatureSpec
{ FeatureSpec -> Maybe String
featureBaseName :: Maybe String
, FeatureSpec -> CategorySpec 'AnyPart
featureBaseValues :: CategorySpec 'AnyPart
, FeatureSpec -> [(String, CategorySpec 'AnyPart)]
featureDerived :: [(String, CategorySpec 'AnyPart)]
}
deriving (Int -> FeatureSpec -> ShowS
[FeatureSpec] -> ShowS
FeatureSpec -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FeatureSpec] -> ShowS
$cshowList :: [FeatureSpec] -> ShowS
show :: FeatureSpec -> String
$cshow :: FeatureSpec -> String
showsPrec :: Int -> FeatureSpec -> ShowS
$cshowsPrec :: Int -> FeatureSpec -> ShowS
Show, FeatureSpec -> FeatureSpec -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FeatureSpec -> FeatureSpec -> Bool
$c/= :: FeatureSpec -> FeatureSpec -> Bool
== :: FeatureSpec -> FeatureSpec -> Bool
$c== :: FeatureSpec -> FeatureSpec -> Bool
Eq, Eq FeatureSpec
FeatureSpec -> FeatureSpec -> Bool
FeatureSpec -> FeatureSpec -> Ordering
FeatureSpec -> FeatureSpec -> FeatureSpec
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
min :: FeatureSpec -> FeatureSpec -> FeatureSpec
$cmin :: FeatureSpec -> FeatureSpec -> FeatureSpec
max :: FeatureSpec -> FeatureSpec -> FeatureSpec
$cmax :: FeatureSpec -> FeatureSpec -> FeatureSpec
>= :: FeatureSpec -> FeatureSpec -> Bool
$c>= :: FeatureSpec -> FeatureSpec -> Bool
> :: FeatureSpec -> FeatureSpec -> Bool
$c> :: FeatureSpec -> FeatureSpec -> Bool
<= :: FeatureSpec -> FeatureSpec -> Bool
$c<= :: FeatureSpec -> FeatureSpec -> Bool
< :: FeatureSpec -> FeatureSpec -> Bool
$c< :: FeatureSpec -> FeatureSpec -> Bool
compare :: FeatureSpec -> FeatureSpec -> Ordering
$ccompare :: FeatureSpec -> FeatureSpec -> Ordering
Ord, forall x. Rep FeatureSpec x -> FeatureSpec
forall x. FeatureSpec -> Rep FeatureSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FeatureSpec x -> FeatureSpec
$cfrom :: forall x. FeatureSpec -> Rep FeatureSpec x
Generic, FeatureSpec -> ()
forall a. (a -> ()) -> NFData a
rnf :: FeatureSpec -> ()
$crnf :: FeatureSpec -> ()
NFData)
data CategoryDefinition
= DefineCategory String (CategorySpec 'AnyPart)
| DefineFeature FeatureSpec
deriving (Int -> CategoryDefinition -> ShowS
[CategoryDefinition] -> ShowS
CategoryDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CategoryDefinition] -> ShowS
$cshowList :: [CategoryDefinition] -> ShowS
show :: CategoryDefinition -> String
$cshow :: CategoryDefinition -> String
showsPrec :: Int -> CategoryDefinition -> ShowS
$cshowsPrec :: Int -> CategoryDefinition -> ShowS
Show, CategoryDefinition -> CategoryDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CategoryDefinition -> CategoryDefinition -> Bool
$c/= :: CategoryDefinition -> CategoryDefinition -> Bool
== :: CategoryDefinition -> CategoryDefinition -> Bool
$c== :: CategoryDefinition -> CategoryDefinition -> Bool
Eq, Eq CategoryDefinition
CategoryDefinition -> CategoryDefinition -> Bool
CategoryDefinition -> CategoryDefinition -> Ordering
CategoryDefinition -> CategoryDefinition -> CategoryDefinition
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
min :: CategoryDefinition -> CategoryDefinition -> CategoryDefinition
$cmin :: CategoryDefinition -> CategoryDefinition -> CategoryDefinition
max :: CategoryDefinition -> CategoryDefinition -> CategoryDefinition
$cmax :: CategoryDefinition -> CategoryDefinition -> CategoryDefinition
>= :: CategoryDefinition -> CategoryDefinition -> Bool
$c>= :: CategoryDefinition -> CategoryDefinition -> Bool
> :: CategoryDefinition -> CategoryDefinition -> Bool
$c> :: CategoryDefinition -> CategoryDefinition -> Bool
<= :: CategoryDefinition -> CategoryDefinition -> Bool
$c<= :: CategoryDefinition -> CategoryDefinition -> Bool
< :: CategoryDefinition -> CategoryDefinition -> Bool
$c< :: CategoryDefinition -> CategoryDefinition -> Bool
compare :: CategoryDefinition -> CategoryDefinition -> Ordering
$ccompare :: CategoryDefinition -> CategoryDefinition -> Ordering
Ord, forall x. Rep CategoryDefinition x -> CategoryDefinition
forall x. CategoryDefinition -> Rep CategoryDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CategoryDefinition x -> CategoryDefinition
$cfrom :: forall x. CategoryDefinition -> Rep CategoryDefinition x
Generic, CategoryDefinition -> ()
forall a. (a -> ()) -> NFData a
rnf :: CategoryDefinition -> ()
$crnf :: CategoryDefinition -> ()
NFData)
data Directive = Categories Bool [CategoryDefinition]
deriving (Int -> Directive -> ShowS
[Directive] -> ShowS
Directive -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Directive] -> ShowS
$cshowList :: [Directive] -> ShowS
show :: Directive -> String
$cshow :: Directive -> String
showsPrec :: Int -> Directive -> ShowS
$cshowsPrec :: Int -> Directive -> ShowS
Show, Directive -> Directive -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Directive -> Directive -> Bool
$c/= :: Directive -> Directive -> Bool
== :: Directive -> Directive -> Bool
$c== :: Directive -> Directive -> Bool
Eq, Eq Directive
Directive -> Directive -> Bool
Directive -> Directive -> Ordering
Directive -> Directive -> Directive
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
min :: Directive -> Directive -> Directive
$cmin :: Directive -> Directive -> Directive
max :: Directive -> Directive -> Directive
$cmax :: Directive -> Directive -> Directive
>= :: Directive -> Directive -> Bool
$c>= :: Directive -> Directive -> Bool
> :: Directive -> Directive -> Bool
$c> :: Directive -> Directive -> Bool
<= :: Directive -> Directive -> Bool
$c<= :: Directive -> Directive -> Bool
< :: Directive -> Directive -> Bool
$c< :: Directive -> Directive -> Bool
compare :: Directive -> Directive -> Ordering
$ccompare :: Directive -> Directive -> Ordering
Ord, forall x. Rep Directive x -> Directive
forall x. Directive -> Rep Directive x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Directive x -> Directive
$cfrom :: forall x. Directive -> Rep Directive x
Generic, Directive -> ()
forall a. (a -> ()) -> NFData a
rnf :: Directive -> ()
$crnf :: Directive -> ()
NFData)