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
18 import qualified Data.Text.Lazy as TL
20 import qualified Language.Symantic.XML as XML
22 infixl 2 <$$>, <$?>, <$*>, <$:>
23 infixl 1 <||>, <|?>, <|*>{-, <|:>-}
30 , Sym_Interleaved repr
31 ) => Sym_RNC repr where
32 namespace :: Maybe XML.NCName -> XML.Namespace -> repr ()
33 element :: XML.QName -> repr a -> repr a
34 attribute :: XML.QName -> repr a -> repr a
36 anyElem :: XML.Namespace -> (XML.NCName -> repr a) -> repr a
37 escapedText :: repr XML.EscapedText
39 text = XML.unescapeText <$> escapedText
41 try :: repr a -> repr a
42 option :: a -> repr a -> repr a
43 optional :: repr a -> repr (Maybe a)
44 choice :: [repr a] -> repr a
45 intermany :: [repr a] -> repr [a]
46 intermany = many . choice . (try <$>)
47 manySeq :: repr a -> repr (Seq a)
48 manySeq r = Seq.fromList <$> many r
49 someSeq :: repr a -> repr (Seq a)
50 someSeq r = Seq.fromList <$> some r
53 class Sym_Rule repr where
54 rule :: Show a => String -> repr a -> repr a
56 arg :: String -> repr ()
60 = RuleMode_Body -- ^ Request to generate the body of the rule.
61 | RuleMode_Ref -- ^ Request to generate a reference to the rule.
62 | RuleMode_Def -- ^ Request to generate a definition of the rule.
65 -- * Class 'Sym_Interleaved'
66 class Sym_Interleaved repr where
67 interleaved :: Perm repr a -> repr a
68 (<$$>) :: (a -> b) -> repr a -> Perm repr b
70 (<$?>) :: (a -> b) -> (a, repr a) -> Perm repr b
71 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
72 (<|?>) :: Perm repr (a -> b) -> (a, repr a) -> Perm repr b
74 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
75 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
77 (<$:>) :: (Seq a -> b) -> repr a -> Perm repr b
78 (<$:>) f = (f . Seq.fromList <$*>)
79 {- NOTE: Megaparsec's PermParser has no Functor instance.
80 (<|:>) :: Perm repr (Seq a -> b) -> repr a -> Perm repr b
81 default (<|:>) :: Functor (Perm repr) => Perm repr (Seq a -> b) -> repr a -> Perm repr b
82 (<|:>) f x = (. Seq.fromList) <$> f <|*> x
85 -- ** Type family 'Perm'
86 -- | Type of permutations, depending on the representation.
87 type family Perm (repr:: * -> *) = (r :: * -> *) | r -> repr
88 -- type instance Perm (Dup x y) = Dup (Perm x) (Perm y)
89 -- type instance Perm (Rule repr) = Rule (Perm repr) -- Compose [] (Rule (Perm repr))