{-# LANGUAGE CPP #-}
module Data.Generics.Text (
gshow, gshows,
gread
) where
#ifdef __HADDOCK__
import Prelude
#endif
import Control.Monad
import Data.Data
import Data.Generics.Aliases
import Text.ParserCombinators.ReadP
import Text.Read.Lex
gshow :: Data a => a -> String
gshow :: forall a. Data a => a -> String
gshow a
x = forall a. Data a => a -> ShowS
gshows a
x String
""
gshows :: Data a => a -> ShowS
gshows :: forall a. Data a => a -> ShowS
gshows = ( \a
t ->
Char -> ShowS
showChar Char
'('
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> ShowS
showString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constr -> String
showConstr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Data a => a -> Constr
toConstr forall a b. (a -> b) -> a -> b
$ a
t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
gmapQ ((Char -> ShowS
showChar Char
' ' forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Data a => a -> ShowS
gshows) forall a b. (a -> b) -> a -> b
$ a
t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
')'
) forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
`extQ` (forall a. Show a => a -> ShowS
shows :: String -> ShowS)
gread :: Data a => ReadS a
gread :: forall a. Data a => ReadS a
gread = forall a. ReadP a -> ReadS a
readP_to_S forall a'. Data a' => ReadP a'
gread'
where
gread' :: Data a' => ReadP a'
gread' :: forall a'. Data a' => ReadP a'
gread' = ReadP a'
allButString forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
m a -> m b -> m a
`extR` ReadP String
stringCase
where
stringCase :: ReadP String
stringCase :: ReadP String
stringCase = forall a. ReadS a -> ReadP a
readS_to_P forall a. Read a => ReadS a
reads
myDataType :: DataType
myDataType = forall a. Data a => a -> DataType
dataTypeOf (forall a''. ReadP a'' -> a''
getArg ReadP a'
allButString)
where
getArg :: ReadP a'' -> a''
getArg :: forall a''. ReadP a'' -> a''
getArg = forall a. HasCallStack => a
undefined
allButString :: ReadP a'
allButString =
do
ReadP ()
skipSpaces
Char
_ <- Char -> ReadP Char
char Char
'('
ReadP ()
skipSpaces
String
str <- ReadP String
parseConstr
Constr
con <- String -> ReadP Constr
str2con String
str
a'
x <- forall (m :: * -> *) a.
(Monad m, Data a) =>
(forall d. Data d => m d) -> Constr -> m a
fromConstrM forall a'. Data a' => ReadP a'
gread' Constr
con
ReadP ()
skipSpaces
Char
_ <- Char -> ReadP Char
char Char
')'
ReadP ()
skipSpaces
forall (m :: * -> *) a. Monad m => a -> m a
return a'
x
str2con :: String -> ReadP Constr
str2con :: String -> ReadP Constr
str2con = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *) a. MonadPlus m => m a
mzero forall (m :: * -> *) a. Monad m => a -> m a
return
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> String -> Maybe Constr
readConstr DataType
myDataType
parseConstr :: ReadP String
parseConstr :: ReadP String
parseConstr =
String -> ReadP String
string String
"[]"
forall a. ReadP a -> ReadP a -> ReadP a
<++ String -> ReadP String
string String
"()"
forall a. ReadP a -> ReadP a -> ReadP a
<++ ReadP String
infixOp
forall a. ReadP a -> ReadP a -> ReadP a
<++ ReadP String
hsLex
infixOp :: ReadP String
infixOp :: ReadP String
infixOp = do Char
c1 <- Char -> ReadP Char
char Char
'('
String
str <- (Char -> Bool) -> ReadP String
munch1 (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> a -> Bool
(==) Char
')')
Char
c2 <- Char -> ReadP Char
char Char
')'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Char
c1] forall a. [a] -> [a] -> [a]
++ String
str forall a. [a] -> [a] -> [a]
++ [Char
c2]