1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE NamedFieldPuns #-}
4 {-# LANGUAGE NoMonomorphismRestriction #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 {-# LANGUAGE RecordWildCards #-}
7 {-# LANGUAGE TypeFamilyDependencies #-}
8 module Language.RNC.Sym where
10 import Control.Applicative (Applicative(..), (<$>), (<$))
11 import Data.Foldable (Foldable,foldl',foldr)
12 import Data.Function (($),(.),id,flip)
14 import Data.Maybe (Maybe(..), maybe)
15 import Data.Text (Text)
16 import Text.Show (Show)
17 import qualified Data.Text as Text
19 import Language.DTC.Document (Default(..), MayText(..))
20 import Language.TCT.Write.XML (XmlName(..))
21 import qualified Language.DTC.Document as DTC
23 foldlApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
24 foldlApp = foldl' (flip ($)) def
25 foldrApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
26 foldrApp = foldr ($) def
31 -- ** Class 'Sym_Rule'
32 class Sym_Rule repr where
33 rule :: Show a => Text -> Rule (repr a)
36 -- * Type family 'Perm'
37 type family Perm (repr:: * -> *) = (r :: * -> *) | r -> repr
39 -- * Class 'Sym_Interleaved'
40 class Sym_Interleaved repr where
41 interleaved :: Perm repr a -> repr a
42 (<$$>) :: (a -> b) -> repr a -> Perm repr b
44 (<$?>) :: (a -> b) -> (a,repr a) -> Perm repr b
45 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
46 (<|?>) :: Perm repr (a -> b) -> (a,repr a) -> Perm repr b
48 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
49 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
52 infixl 2 <$$>, <$?>, <$*>
53 infixl 1 <||>, <|?>, <|*>
60 , Sym_Interleaved repr
61 ) => Sym_RNC repr where
62 element :: XmlName -> repr a -> repr a
63 attribute :: XmlName -> repr a -> repr a
65 try :: repr a -> repr a
67 anyElem :: Show a => (XmlName -> repr a) -> repr a
73 (<|>) :: repr a -> repr a -> repr a
74 many :: repr a -> repr [a]
75 some :: repr a -> repr [a]
76 optional :: repr a -> repr (Maybe a)
77 option :: a -> repr a -> repr a
78 choice :: [repr a] -> repr a
79 intermany :: [repr a] -> repr [a]
80 intermany = many . choice . (try <$>)