1 {-# LANGUAGE TypeFamilyDependencies #-}
2 module Language.Symantic.RNC.Sym
3 ( module Language.Symantic.RNC.Sym
9 import Control.Applicative (Applicative(..), Alternative(..))
10 import Control.Monad (Monad(..))
12 import Data.Function ((.), id)
13 import Data.Functor (Functor(..), (<$>))
14 import Data.Maybe (Maybe(..))
15 import Data.Sequence (Seq)
16 import Data.String (String)
17 import Text.Show (Show(..))
18 import qualified Data.Sequence as Seq
19 import qualified Data.Text.Lazy as TL
21 import qualified Language.Symantic.XML as XML
28 , Sym_Permutation repr
29 ) => Sym_RNC repr where
30 namespace :: Maybe XML.NCName -> XML.Namespace -> repr ()
31 element :: XML.QName -> repr a -> repr a
32 attribute :: XML.QName -> repr a -> repr a
34 anyElem :: XML.Namespace -> (XML.NCName -> repr a) -> repr a
35 escapedText :: repr XML.EscapedText
37 text = XML.unescapeText <$> escapedText
39 try :: repr a -> repr a
40 option :: a -> repr a -> repr a
41 optional :: repr a -> repr (Maybe a)
42 choice :: [repr a] -> repr a
43 intermany :: [repr a] -> repr [a]
44 intermany = many . choice . (try <$>)
45 manySeq :: repr a -> repr (Seq a)
46 manySeq r = Seq.fromList <$> many r
47 someSeq :: repr a -> repr (Seq a)
48 someSeq r = Seq.fromList <$> some r
51 class Sym_Rule repr where
52 rule :: Show a => String -> repr a -> repr a
54 arg :: String -> repr ()
58 = RuleMode_Body -- ^ Request to generate the body of the rule.
59 | RuleMode_Ref -- ^ Request to generate a reference to the rule.
60 | RuleMode_Def -- ^ Request to generate a definition of the rule.
63 -- * Class 'Sym_Permutation'
64 class (Alternative repr, Applicative (Permutation repr)) => Sym_Permutation repr where
65 runPermutation :: Permutation repr a -> repr a
66 toPermutation :: repr a -> Permutation repr a
67 toPermutationWithDefault :: a -> repr a -> Permutation repr a
69 (<$$>) :: (a -> b) -> repr a -> Permutation repr b
70 (<$?>) :: (a -> b) -> (a, repr a) -> Permutation repr b
71 (<$*>) :: ([a] -> b) -> repr a -> Permutation repr b
72 (<$:>) :: (Seq a -> b) -> repr a -> Permutation repr b
73 infixl 2 <$$>, <$?>, <$*>, <$:>
79 (<||>) :: Permutation repr (a -> b) -> repr a -> Permutation repr b
80 (<|?>) :: Permutation repr (a -> b) -> (a, repr a) -> Permutation repr b
81 (<|*>) :: Permutation repr ([a] -> b) -> repr a -> Permutation repr b
82 (<|:>) :: Permutation repr (Seq a -> b) -> repr a -> Permutation repr b
83 infixl 1 <||>, <|?>, <|*>, <|:>
89 f <$$> x = f <$> toPermutation x
90 f <$?> (d,x) = f <$> toPermutationWithDefault d x
91 f <$*> x = f <$> toPermutationWithDefault [] (many x)
92 f <$:> x = f . Seq.fromList <$> toPermutationWithDefault [] (many x)
94 f <||> x = f <*> toPermutation x
95 f <|?> (d,x) = f <*> toPermutationWithDefault d x
96 f <|*> x = f <*> toPermutationWithDefault [] (many x)
97 f <|:> x = f <*> toPermutationWithDefault Seq.empty (Seq.fromList <$> many x)
99 -- ** Type family 'Permutation'
100 -- | Type of permutations, depending on the representation.
101 type family Permutation (repr:: * -> *) = (r :: * -> *) | r -> repr