1 {-# LANGUAGE TypeFamilyDependencies #-}
2 module Language.Symantic.RNC.Sym
3 ( module Language.Symantic.RNC.Sym
9 import Control.Applicative (Applicative(..), Alternative(..))
11 import Data.Function ((.), id)
12 import Data.Functor (Functor(..), (<$>))
13 import Data.Maybe (Maybe(..))
14 import Data.Sequence (Seq)
15 import Data.String (String)
16 import Text.Show (Show(..))
17 import qualified Data.Sequence as Seq
19 import qualified Language.Symantic.XML as XML
21 infixl 2 <$$>, <$?>, <$*>, <$:>
22 infixl 1 <||>, <|?>, <|*>{-, <|:>-}
29 , Sym_Interleaved repr
30 ) => Sym_RNC repr where
31 namespace :: Maybe XML.NCName -> XML.Namespace -> repr ()
32 element :: XML.QName -> repr a -> repr a
33 attribute :: XML.QName -> repr a -> repr a
35 anyElem :: XML.Namespace -> (XML.NCName -> repr a) -> repr a
38 try :: repr a -> repr a
39 option :: a -> repr a -> repr a
40 optional :: repr a -> repr (Maybe a)
41 choice :: [repr a] -> repr a
42 intermany :: [repr a] -> repr [a]
43 intermany = many . choice . (try <$>)
44 manySeq :: repr a -> repr (Seq a)
45 manySeq r = Seq.fromList <$> many r
46 someSeq :: repr a -> repr (Seq a)
47 someSeq r = Seq.fromList <$> some r
50 class Sym_Rule repr where
51 rule :: Show a => String -> repr a -> repr a
53 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_Interleaved'
64 class Sym_Interleaved repr where
65 interleaved :: Perm repr a -> repr a
66 (<$$>) :: (a -> b) -> repr a -> Perm repr b
68 (<$?>) :: (a -> b) -> (a, repr a) -> Perm repr b
69 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
70 (<|?>) :: Perm repr (a -> b) -> (a, repr a) -> Perm repr b
72 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
73 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
75 (<$:>) :: (Seq a -> b) -> repr a -> Perm repr b
76 (<$:>) f = (f . Seq.fromList <$*>)
77 {- NOTE: Megaparsec's PermParser has no Functor instance.
78 (<|:>) :: Perm repr (Seq a -> b) -> repr a -> Perm repr b
79 default (<|:>) :: Functor (Perm repr) => Perm repr (Seq a -> b) -> repr a -> Perm repr b
80 (<|:>) f x = (. Seq.fromList) <$> f <|*> x
83 -- ** Type family 'Perm'
84 -- | Type of permutations, depending on the representation.
85 type family Perm (repr:: * -> *) = (r :: * -> *) | r -> repr
86 -- type instance Perm (Dup x y) = Dup (Perm x) (Perm y)
87 -- type instance Perm (Rule repr) = Rule (Perm repr) -- Compose [] (Rule (Perm repr))