#define DEMO(p,i) demo "p" i p
module Text.ParserCombinators.UU.Idioms where
import Text.ParserCombinators.UU
import Text.ParserCombinators.UU.BasicInstances
import Text.ParserCombinators.UU.Utils
import Text.ParserCombinators.UU.Demo.Examples hiding (show_demos)
import qualified Data.ListLike as LL
import Control.Applicative
data String' = String' {fromStr :: String}
data Ii = Ii
iI ::Idiomatic i (a -> a) g => g
iI = idiomatic (pure id)
class Idiomatic st f g | g -> f st where
idiomatic :: P st f -> g
instance Idiomatic st x (Ii -> P st x) where
idiomatic ix Ii = ix
instance Idiomatic st f g => Idiomatic st (a -> f) (P st a -> g) where
idiomatic isf is = idiomatic (isf <*> is)
instance Idiomatic st f g => Idiomatic st ((a -> b) -> f) ((a -> b) -> g) where
idiomatic isf f = idiomatic (isf <*> (pure f))
instance (Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, LL.ListLike state Char)
=> Idiomatic (Str Char state loc) f (String -> g) where
idiomatic isf str = idiomatic (isf <* pToken str)
instance (Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, LL.ListLike state Char)
=> Idiomatic (Str Char state loc) f (Char -> g) where
idiomatic isf c = idiomatic (isf <* pSym c)
show_demos = demo "(iI (+) '(' pNatural \"plus\" pNatural ')' Ii)::Parser Int" "(2 plus 3)" ((iI (+) '(' pNatural "+" pNatural ')' Ii)::Parser Int)