]> Git — Sourcephile - doclang.git/blob - Language/RNC/Sym.hs
Add better support for HeaderDotSlash including.
[doclang.git] / Language / RNC / Sym.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE TypeFamilyDependencies #-}
5 module Language.RNC.Sym where
6
7 import Control.Applicative (Applicative(..), (<$>))
8 import Data.Default.Class (Default(..))
9 import Data.Foldable (Foldable,foldl',foldr)
10 import Data.Function (($),(.),id,flip)
11 import Data.Int (Int)
12 import Data.Maybe (Maybe(..))
13 import Data.Text (Text)
14 import Text.Show (Show)
15 import qualified Data.Text.Lazy as TL
16
17 import Language.XML
18
19 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
20 foldlApp = foldl' (flip ($)) def
21 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
22 foldrApp = foldr ($) def
23
24 -- * Type 'Rule'
25 type Rule a = a -> a
26
27 -- ** Class 'Sym_Rule'
28 class Sym_Rule repr where
29 rule :: Show a => Text -> Rule (repr a)
30 rule _n = id
31
32 -- * Type family 'Perm'
33 type family Perm (repr:: * -> *) = (r :: * -> *) | r -> repr
34
35 -- * Class 'Sym_Interleaved'
36 class Sym_Interleaved repr where
37 interleaved :: Perm repr a -> repr a
38 (<$$>) :: (a -> b) -> repr a -> Perm repr b
39
40 (<$?>) :: (a -> b) -> (a,repr a) -> Perm repr b
41 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
42 (<|?>) :: Perm repr (a -> b) -> (a,repr a) -> Perm repr b
43
44 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
45 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
46
47 infixl 3 <|>
48 infixl 2 <$$>, <$?>, <$*>
49 infixl 1 <||>, <|?>, <|*>
50
51 -- * Class 'Sym_RNC'
52 class
53 ( Applicative repr
54 -- , Alternative repr
55 , Sym_Rule repr
56 , Sym_Interleaved repr
57 ) => Sym_RNC repr where
58 element :: XmlName -> repr a -> repr a
59 attribute :: XmlName -> repr a -> repr a
60 comment :: repr TL.Text
61 try :: repr a -> repr a
62 fail :: repr a
63 none :: repr ()
64 anyElem :: Show a => (XmlName -> repr a) -> repr a
65 any :: repr ()
66 text :: repr TL.Text
67 int :: repr Int
68 nat :: repr Nat
69 nat1 :: repr Nat1
70 (<|>) :: repr a -> repr a -> repr a
71 many :: repr a -> repr [a]
72 -- TODO: maybe use Seq instead of []
73 some :: repr a -> repr [a]
74 optional :: repr a -> repr (Maybe a)
75 option :: a -> repr a -> repr a
76 choice :: [repr a] -> repr a
77 intermany :: [repr a] -> repr [a]
78 intermany = many . choice . (try <$>)