1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE TypeFamilyDependencies #-}
5 module Hdoc.RNC.Sym where
7 import Control.Applicative (Applicative(..), (<$>))
8 import Data.Function ((.),id)
10 import Data.Maybe (Maybe(..))
11 import Data.Ratio (Rational)
12 import Data.Text (Text)
13 import Text.Show (Show)
14 import qualified Data.Text.Lazy as TL
16 import Hdoc.Utils (Nat(..), Nat1(..))
17 import qualified Hdoc.XML as XML
22 -- ** Class 'Sym_Rule'
23 class Sym_Rule repr where
24 rule :: Show a => Text -> Rule (repr a)
27 -- * Type family 'Perm'
28 type family Perm (repr:: * -> *) = (r :: * -> *) | r -> repr
30 -- * Class 'Sym_Interleaved'
31 class Sym_Interleaved repr where
32 interleaved :: Perm repr a -> repr a
33 (<$$>) :: (a -> b) -> repr a -> Perm repr b
35 (<$?>) :: (a -> b) -> (a,repr a) -> Perm repr b
36 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
37 (<|?>) :: Perm repr (a -> b) -> (a,repr a) -> Perm repr b
39 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
40 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
43 infixl 2 <$$>, <$?>, <$*>
44 infixl 1 <||>, <|?>, <|*>
51 , Sym_Interleaved repr
52 ) => Sym_RNC repr where
53 element :: XML.Name -> repr a -> repr a
54 attribute :: XML.Name -> repr a -> repr a
55 comment :: repr TL.Text
56 try :: repr a -> repr a
59 anyElem :: Show a => (XML.Name -> repr a) -> repr a
63 rational :: repr Rational
64 rationalPositive :: repr Rational
67 (<|>) :: repr a -> repr a -> repr a
68 many :: repr a -> repr [a]
69 -- TODO: maybe use Seq instead of []
70 some :: repr a -> repr [a]
71 optional :: repr a -> repr (Maybe a)
72 option :: a -> repr a -> repr a
73 choice :: [repr a] -> repr a
74 intermany :: [repr a] -> repr [a]
75 intermany = many . choice . (try <$>)