{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE CPP #-}
module Text.Shakespeare.Base
( Deref (..)
, Ident (..)
, Scope
, parseDeref
, parseHash
, parseVar
, parseVarString
, parseAt
, parseUrl
, parseUrlString
, parseCaret
, parseUnder
, parseInt
, parseIntString
, derefToExp
, flattenDeref
, readUtf8File
, readUtf8FileString
, readFileQ
, readFileRecompileQ
) where
import Language.Haskell.TH.Syntax
import Language.Haskell.TH (appE)
import Data.Char (isUpper, isSymbol, isPunctuation, isAscii)
import Text.ParserCombinators.Parsec
import Text.Parsec.Prim (Parsec)
import Data.List (intercalate)
import Data.Ratio (Ratio, numerator, denominator, (%))
import Data.Data (Data)
import Data.Typeable (Typeable)
import qualified Data.Text.Lazy as TL
import qualified System.IO as SIO
import qualified Data.Text.Lazy.IO as TIO
import Control.Monad (when)
newtype Ident = Ident String
deriving (Int -> Ident -> ShowS
[Ident] -> ShowS
Ident -> String
(Int -> Ident -> ShowS)
-> (Ident -> String) -> ([Ident] -> ShowS) -> Show Ident
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ident] -> ShowS
$cshowList :: [Ident] -> ShowS
show :: Ident -> String
$cshow :: Ident -> String
showsPrec :: Int -> Ident -> ShowS
$cshowsPrec :: Int -> Ident -> ShowS
Show, Ident -> Ident -> Bool
(Ident -> Ident -> Bool) -> (Ident -> Ident -> Bool) -> Eq Ident
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ident -> Ident -> Bool
$c/= :: Ident -> Ident -> Bool
== :: Ident -> Ident -> Bool
$c== :: Ident -> Ident -> Bool
Eq, ReadPrec [Ident]
ReadPrec Ident
Int -> ReadS Ident
ReadS [Ident]
(Int -> ReadS Ident)
-> ReadS [Ident]
-> ReadPrec Ident
-> ReadPrec [Ident]
-> Read Ident
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ident]
$creadListPrec :: ReadPrec [Ident]
readPrec :: ReadPrec Ident
$creadPrec :: ReadPrec Ident
readList :: ReadS [Ident]
$creadList :: ReadS [Ident]
readsPrec :: Int -> ReadS Ident
$creadsPrec :: Int -> ReadS Ident
Read, Typeable Ident
DataType
Constr
Typeable Ident =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ident -> c Ident)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ident)
-> (Ident -> Constr)
-> (Ident -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ident))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ident))
-> ((forall b. Data b => b -> b) -> Ident -> Ident)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r)
-> (forall u. (forall d. Data d => d -> u) -> Ident -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Ident -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident)
-> Data Ident
Ident -> DataType
Ident -> Constr
(forall b. Data b => b -> b) -> Ident -> Ident
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ident -> c Ident
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ident
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Ident -> u
forall u. (forall d. Data d => d -> u) -> Ident -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ident
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ident -> c Ident
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ident)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ident)
$cIdent :: Constr
$tIdent :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Ident -> m Ident
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident
gmapMp :: (forall d. Data d => d -> m d) -> Ident -> m Ident
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident
gmapM :: (forall d. Data d => d -> m d) -> Ident -> m Ident
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ident -> m Ident
gmapQi :: Int -> (forall d. Data d => d -> u) -> Ident -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ident -> u
gmapQ :: (forall d. Data d => d -> u) -> Ident -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Ident -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ident -> r
gmapT :: (forall b. Data b => b -> b) -> Ident -> Ident
$cgmapT :: (forall b. Data b => b -> b) -> Ident -> Ident
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ident)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ident)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Ident)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ident)
dataTypeOf :: Ident -> DataType
$cdataTypeOf :: Ident -> DataType
toConstr :: Ident -> Constr
$ctoConstr :: Ident -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ident
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ident
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ident -> c Ident
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ident -> c Ident
$cp1Data :: Typeable Ident
Data, Typeable, Eq Ident
Eq Ident =>
(Ident -> Ident -> Ordering)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Ident)
-> (Ident -> Ident -> Ident)
-> Ord Ident
Ident -> Ident -> Bool
Ident -> Ident -> Ordering
Ident -> Ident -> Ident
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ident -> Ident -> Ident
$cmin :: Ident -> Ident -> Ident
max :: Ident -> Ident -> Ident
$cmax :: Ident -> Ident -> Ident
>= :: Ident -> Ident -> Bool
$c>= :: Ident -> Ident -> Bool
> :: Ident -> Ident -> Bool
$c> :: Ident -> Ident -> Bool
<= :: Ident -> Ident -> Bool
$c<= :: Ident -> Ident -> Bool
< :: Ident -> Ident -> Bool
$c< :: Ident -> Ident -> Bool
compare :: Ident -> Ident -> Ordering
$ccompare :: Ident -> Ident -> Ordering
$cp1Ord :: Eq Ident
Ord)
type Scope = [(Ident, Exp)]
data Deref = DerefModulesIdent [String] Ident
| DerefIdent Ident
| DerefIntegral Integer
| DerefRational Rational
| DerefString String
| DerefBranch Deref Deref
| DerefList [Deref]
| DerefTuple [Deref]
deriving (Int -> Deref -> ShowS
[Deref] -> ShowS
Deref -> String
(Int -> Deref -> ShowS)
-> (Deref -> String) -> ([Deref] -> ShowS) -> Show Deref
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Deref] -> ShowS
$cshowList :: [Deref] -> ShowS
show :: Deref -> String
$cshow :: Deref -> String
showsPrec :: Int -> Deref -> ShowS
$cshowsPrec :: Int -> Deref -> ShowS
Show, Deref -> Deref -> Bool
(Deref -> Deref -> Bool) -> (Deref -> Deref -> Bool) -> Eq Deref
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Deref -> Deref -> Bool
$c/= :: Deref -> Deref -> Bool
== :: Deref -> Deref -> Bool
$c== :: Deref -> Deref -> Bool
Eq, ReadPrec [Deref]
ReadPrec Deref
Int -> ReadS Deref
ReadS [Deref]
(Int -> ReadS Deref)
-> ReadS [Deref]
-> ReadPrec Deref
-> ReadPrec [Deref]
-> Read Deref
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Deref]
$creadListPrec :: ReadPrec [Deref]
readPrec :: ReadPrec Deref
$creadPrec :: ReadPrec Deref
readList :: ReadS [Deref]
$creadList :: ReadS [Deref]
readsPrec :: Int -> ReadS Deref
$creadsPrec :: Int -> ReadS Deref
Read, Typeable Deref
DataType
Constr
Typeable Deref =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Deref -> c Deref)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Deref)
-> (Deref -> Constr)
-> (Deref -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Deref))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref))
-> ((forall b. Data b => b -> b) -> Deref -> Deref)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r)
-> (forall u. (forall d. Data d => d -> u) -> Deref -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Deref -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref)
-> Data Deref
Deref -> DataType
Deref -> Constr
(forall b. Data b => b -> b) -> Deref -> Deref
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Deref -> c Deref
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Deref
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Deref -> u
forall u. (forall d. Data d => d -> u) -> Deref -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Deref
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Deref -> c Deref
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Deref)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref)
$cDerefTuple :: Constr
$cDerefList :: Constr
$cDerefBranch :: Constr
$cDerefString :: Constr
$cDerefRational :: Constr
$cDerefIntegral :: Constr
$cDerefIdent :: Constr
$cDerefModulesIdent :: Constr
$tDeref :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Deref -> m Deref
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref
gmapMp :: (forall d. Data d => d -> m d) -> Deref -> m Deref
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref
gmapM :: (forall d. Data d => d -> m d) -> Deref -> m Deref
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Deref -> m Deref
gmapQi :: Int -> (forall d. Data d => d -> u) -> Deref -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Deref -> u
gmapQ :: (forall d. Data d => d -> u) -> Deref -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Deref -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r
gmapT :: (forall b. Data b => b -> b) -> Deref -> Deref
$cgmapT :: (forall b. Data b => b -> b) -> Deref -> Deref
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Deref)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Deref)
dataTypeOf :: Deref -> DataType
$cdataTypeOf :: Deref -> DataType
toConstr :: Deref -> Constr
$ctoConstr :: Deref -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Deref
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Deref
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Deref -> c Deref
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Deref -> c Deref
$cp1Data :: Typeable Deref
Data, Typeable, Eq Deref
Eq Deref =>
(Deref -> Deref -> Ordering)
-> (Deref -> Deref -> Bool)
-> (Deref -> Deref -> Bool)
-> (Deref -> Deref -> Bool)
-> (Deref -> Deref -> Bool)
-> (Deref -> Deref -> Deref)
-> (Deref -> Deref -> Deref)
-> Ord Deref
Deref -> Deref -> Bool
Deref -> Deref -> Ordering
Deref -> Deref -> Deref
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Deref -> Deref -> Deref
$cmin :: Deref -> Deref -> Deref
max :: Deref -> Deref -> Deref
$cmax :: Deref -> Deref -> Deref
>= :: Deref -> Deref -> Bool
$c>= :: Deref -> Deref -> Bool
> :: Deref -> Deref -> Bool
$c> :: Deref -> Deref -> Bool
<= :: Deref -> Deref -> Bool
$c<= :: Deref -> Deref -> Bool
< :: Deref -> Deref -> Bool
$c< :: Deref -> Deref -> Bool
compare :: Deref -> Deref -> Ordering
$ccompare :: Deref -> Deref -> Ordering
$cp1Ord :: Eq Deref
Ord)
instance Lift Ident where
lift :: Ident -> Q Exp
lift (Ident s :: String
s) = [|Ident|] Q Exp -> Q Exp -> Q Exp
`appE` String -> Q Exp
forall t. Lift t => t -> Q Exp
lift String
s
instance Lift Deref where
lift :: Deref -> Q Exp
lift (DerefModulesIdent v :: [String]
v s :: Ident
s) = do
Exp
dl <- [|DerefModulesIdent|]
Exp
v' <- [String] -> Q Exp
forall t. Lift t => t -> Q Exp
lift [String]
v
Exp
s' <- Ident -> Q Exp
forall t. Lift t => t -> Q Exp
lift Ident
s
Exp -> Q Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Q Exp) -> Exp -> Q Exp
forall a b. (a -> b) -> a -> b
$ Exp
dl Exp -> Exp -> Exp
`AppE` Exp
v' Exp -> Exp -> Exp
`AppE` Exp
s'
lift (DerefIdent s :: Ident
s) = do
Exp
dl <- [|DerefIdent|]
Exp
s' <- Ident -> Q Exp
forall t. Lift t => t -> Q Exp
lift Ident
s
Exp -> Q Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Q Exp) -> Exp -> Q Exp
forall a b. (a -> b) -> a -> b
$ Exp
dl Exp -> Exp -> Exp
`AppE` Exp
s'
lift (DerefBranch x :: Deref
x y :: Deref
y) = do
Exp
x' <- Deref -> Q Exp
forall t. Lift t => t -> Q Exp
lift Deref
x
Exp
y' <- Deref -> Q Exp
forall t. Lift t => t -> Q Exp
lift Deref
y
Exp
db <- [|DerefBranch|]
Exp -> Q Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Q Exp) -> Exp -> Q Exp
forall a b. (a -> b) -> a -> b
$ Exp
db Exp -> Exp -> Exp
`AppE` Exp
x' Exp -> Exp -> Exp
`AppE` Exp
y'
lift (DerefIntegral i :: Integer
i) = [|DerefIntegral|] Q Exp -> Q Exp -> Q Exp
`appE` Integer -> Q Exp
forall t. Lift t => t -> Q Exp
lift Integer
i
lift (DerefRational r :: Rational
r) = do
Exp
n <- Integer -> Q Exp
forall t. Lift t => t -> Q Exp
lift (Integer -> Q Exp) -> Integer -> Q Exp
forall a b. (a -> b) -> a -> b
$ Rational -> Integer
forall a. Ratio a -> a
numerator Rational
r
Exp
d <- Integer -> Q Exp
forall t. Lift t => t -> Q Exp
lift (Integer -> Q Exp) -> Integer -> Q Exp
forall a b. (a -> b) -> a -> b
$ Rational -> Integer
forall a. Ratio a -> a
denominator Rational
r
Exp
per <- [|(%) :: Int -> Int -> Ratio Int|]
Exp
dr <- [|DerefRational|]
Exp -> Q Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Q Exp) -> Exp -> Q Exp
forall a b. (a -> b) -> a -> b
$ Exp
dr Exp -> Exp -> Exp
`AppE` Maybe Exp -> Exp -> Maybe Exp -> Exp
InfixE (Exp -> Maybe Exp
forall a. a -> Maybe a
Just Exp
n) Exp
per (Exp -> Maybe Exp
forall a. a -> Maybe a
Just Exp
d)
lift (DerefString s :: String
s) = [|DerefString|] Q Exp -> Q Exp -> Q Exp
`appE` String -> Q Exp
forall t. Lift t => t -> Q Exp
lift String
s
lift (DerefList x :: [Deref]
x) = [|DerefList $(lift x)|]
lift (DerefTuple x :: [Deref]
x) = [|DerefTuple $(lift x)|]
derefParens, derefCurlyBrackets :: UserParser a Deref
derefParens :: UserParser a Deref
derefParens = ParsecT String a Identity Char
-> ParsecT String a Identity Char
-> UserParser a Deref
-> UserParser a Deref
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '(') (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ')') UserParser a Deref
forall a. UserParser a Deref
parseDeref
derefCurlyBrackets :: UserParser a Deref
derefCurlyBrackets = ParsecT String a Identity Char
-> ParsecT String a Identity Char
-> UserParser a Deref
-> UserParser a Deref
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{') (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}') UserParser a Deref
forall a. UserParser a Deref
parseDeref
derefList, derefTuple :: UserParser a Deref
derefList :: UserParser a Deref
derefList = ParsecT String a Identity Char
-> ParsecT String a Identity Char
-> UserParser a Deref
-> UserParser a Deref
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '[') (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ']') (([Deref] -> Deref)
-> ParsecT String a Identity [Deref] -> UserParser a Deref
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Deref] -> Deref
DerefList (ParsecT String a Identity [Deref] -> UserParser a Deref)
-> ParsecT String a Identity [Deref] -> UserParser a Deref
forall a b. (a -> b) -> a -> b
$ UserParser a Deref
-> ParsecT String a Identity Char
-> ParsecT String a Identity [Deref]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy UserParser a Deref
forall a. UserParser a Deref
parseDeref (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ','))
derefTuple :: UserParser a Deref
derefTuple = UserParser a Deref -> UserParser a Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (UserParser a Deref -> UserParser a Deref)
-> UserParser a Deref -> UserParser a Deref
forall a b. (a -> b) -> a -> b
$ do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '('
[Deref]
x <- UserParser a Deref
-> ParsecT String a Identity Char
-> ParsecT String a Identity [Deref]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 UserParser a Deref
forall a. UserParser a Deref
parseDeref (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ',')
Bool
-> ParsecT String a Identity () -> ParsecT String a Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Deref] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Deref]
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 2) (ParsecT String a Identity () -> ParsecT String a Identity ())
-> ParsecT String a Identity () -> ParsecT String a Identity ()
forall a b. (a -> b) -> a -> b
$ ParsecT String a Identity ()
forall tok st a. GenParser tok st a
pzero
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ')'
Deref -> UserParser a Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> UserParser a Deref) -> Deref -> UserParser a Deref
forall a b. (a -> b) -> a -> b
$ [Deref] -> Deref
DerefTuple [Deref]
x
parseDeref :: UserParser a Deref
parseDeref :: UserParser a Deref
parseDeref = do
ParsecT String a Identity Char -> ParsecT String a Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (String -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf " \t")
UserParser a Deref
forall a. UserParser a Deref
derefList UserParser a Deref -> UserParser a Deref -> UserParser a Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> UserParser a Deref
forall a. UserParser a Deref
derefTuple UserParser a Deref -> UserParser a Deref -> UserParser a Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> UserParser a Deref
forall a. UserParser a Deref
derefOther
where
derefOther :: ParsecT String u Identity Deref
derefOther = do
Deref
x <- ParsecT String u Identity Deref
forall a. UserParser a Deref
derefSingle
Deref -> ParsecT String u Identity Deref
forall st. Deref -> GenParser Char st Deref
derefInfix Deref
x ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Deref -> ParsecT String u Identity Deref
forall st. Deref -> GenParser Char st Deref
derefPrefix Deref
x
delim :: ParsecT String u Identity ()
delim = (ParsecT String u Identity Char -> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ' ') ParsecT String u Identity String
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> ParsecT String u Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return())
ParsecT String u Identity ()
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity () -> ParsecT String u Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf "(\"" ParsecT String u Identity Char
-> ParsecT String u Identity () -> ParsecT String u Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> ParsecT String u Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
derefOp :: GenParser Char st Deref
derefOp = GenParser Char st Deref -> GenParser Char st Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Deref -> GenParser Char st Deref)
-> GenParser Char st Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ do
Char
_ <- Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '('
String
x <- ParsecT String st Identity Char
-> ParsecT String st Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String st Identity Char
-> ParsecT String st Identity String)
-> ParsecT String st Identity Char
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf " \t\n\r()"
Char
_ <- Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ')'
Deref -> GenParser Char st Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> GenParser Char st Deref)
-> Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ Ident -> Deref
DerefIdent (Ident -> Deref) -> Ident -> Deref
forall a b. (a -> b) -> a -> b
$ String -> Ident
Ident String
x
isOperatorChar :: Char -> Bool
isOperatorChar c :: Char
c
| Char -> Bool
isAscii Char
c = Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` "!#$%&*+./<=>?@\\^|-~:"
| Bool
otherwise = Char -> Bool
isSymbol Char
c Bool -> Bool -> Bool
|| Char -> Bool
isPunctuation Char
c
derefPrefix :: Deref -> ParsecT String u Identity Deref
derefPrefix x :: Deref
x = do
Deref
res <- ([Deref] -> [Deref]) -> ParsecT String u Identity Deref
forall (t :: * -> *) u.
Foldable t =>
([Deref] -> t Deref) -> ParsecT String u Identity Deref
deref' (([Deref] -> [Deref]) -> ParsecT String u Identity Deref)
-> ([Deref] -> [Deref]) -> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$ (:) Deref
x
ParsecT String u Identity Char -> ParsecT String u Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT String u Identity Char -> ParsecT String u Identity ())
-> ParsecT String u Identity Char -> ParsecT String u Identity ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf " \t"
Deref -> ParsecT String u Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return Deref
res
derefInfix :: Deref -> GenParser Char st Deref
derefInfix x :: Deref
x = GenParser Char st Deref -> GenParser Char st Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Deref -> GenParser Char st Deref)
-> GenParser Char st Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ do
()
_ <- ParsecT String st Identity ()
forall u. ParsecT String u Identity ()
delim
[Deref]
xs <- GenParser Char st Deref -> ParsecT String st Identity [Deref]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (GenParser Char st Deref -> ParsecT String st Identity [Deref])
-> GenParser Char st Deref -> ParsecT String st Identity [Deref]
forall a b. (a -> b) -> a -> b
$ GenParser Char st Deref -> GenParser Char st Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Deref -> GenParser Char st Deref)
-> GenParser Char st Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ GenParser Char st Deref
forall a. UserParser a Deref
derefSingle GenParser Char st Deref
-> (Deref -> GenParser Char st Deref) -> GenParser Char st Deref
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \x' :: Deref
x' -> ParsecT String st Identity ()
forall u. ParsecT String u Identity ()
delim ParsecT String st Identity ()
-> GenParser Char st Deref -> GenParser Char st Deref
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Deref -> GenParser Char st Deref
forall (m :: * -> *) a. Monad m => a -> m a
return Deref
x'
String
op <- ParsecT String st Identity Char
-> ParsecT String st Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Char -> Bool) -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isOperatorChar) ParsecT String st Identity String
-> String -> ParsecT String st Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> "operator"
Bool
-> ParsecT String st Identity () -> ParsecT String st Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String
op String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "$") (ParsecT String st Identity () -> ParsecT String st Identity ())
-> ParsecT String st Identity () -> ParsecT String st Identity ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail "don't handle $"
let op' :: Deref
op' = Ident -> Deref
DerefIdent (Ident -> Deref) -> Ident -> Deref
forall a b. (a -> b) -> a -> b
$ String -> Ident
Ident String
op
[Deref]
ys <- GenParser Char st Deref -> ParsecT String st Identity [Deref]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (GenParser Char st Deref -> ParsecT String st Identity [Deref])
-> GenParser Char st Deref -> ParsecT String st Identity [Deref]
forall a b. (a -> b) -> a -> b
$ GenParser Char st Deref -> GenParser Char st Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Deref -> GenParser Char st Deref)
-> GenParser Char st Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity ()
forall u. ParsecT String u Identity ()
delim ParsecT String st Identity ()
-> GenParser Char st Deref -> GenParser Char st Deref
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GenParser Char st Deref
forall a. UserParser a Deref
derefSingle
ParsecT String st Identity Char -> ParsecT String st Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT String st Identity Char -> ParsecT String st Identity ())
-> ParsecT String st Identity Char -> ParsecT String st Identity ()
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf " \t"
Deref -> GenParser Char st Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> GenParser Char st Deref)
-> Deref -> GenParser Char st Deref
forall a b. (a -> b) -> a -> b
$ Deref -> Deref -> Deref
DerefBranch (Deref -> Deref -> Deref
DerefBranch Deref
op' (Deref -> Deref) -> Deref -> Deref
forall a b. (a -> b) -> a -> b
$ (Deref -> Deref -> Deref) -> [Deref] -> Deref
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 Deref -> Deref -> Deref
DerefBranch ([Deref] -> Deref) -> [Deref] -> Deref
forall a b. (a -> b) -> a -> b
$ Deref
x Deref -> [Deref] -> [Deref]
forall a. a -> [a] -> [a]
: [Deref]
xs) ((Deref -> Deref -> Deref) -> [Deref] -> Deref
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 Deref -> Deref -> Deref
DerefBranch [Deref]
ys)
derefSingle :: ParsecT String u Identity Deref
derefSingle = ParsecT String u Identity Deref
forall a. UserParser a Deref
derefTuple ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
derefList ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
derefOp ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
derefParens ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
numeric ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
strLit ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
forall a. UserParser a Deref
ident
deref' :: ([Deref] -> t Deref) -> ParsecT String u Identity Deref
deref' lhs :: [Deref] -> t Deref
lhs =
ParsecT String u Identity Deref
forall a. UserParser a Deref
dollar ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Deref
derefSingle'
ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Deref -> ParsecT String u Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return ((Deref -> Deref -> Deref) -> t Deref -> Deref
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 Deref -> Deref -> Deref
DerefBranch (t Deref -> Deref) -> t Deref -> Deref
forall a b. (a -> b) -> a -> b
$ [Deref] -> t Deref
lhs [])
where
dollar :: ParsecT String st Identity Deref
dollar = do
Char
_ <- GenParser Char st Char -> GenParser Char st Char
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st Char -> GenParser Char st Char)
-> GenParser Char st Char -> GenParser Char st Char
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity ()
forall u. ParsecT String u Identity ()
delim ParsecT String st Identity ()
-> GenParser Char st Char -> GenParser Char st Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> GenParser Char st Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '$'
Deref
rhs <- ParsecT String st Identity Deref
forall a. UserParser a Deref
parseDeref
let lhs' :: Deref
lhs' = (Deref -> Deref -> Deref) -> t Deref -> Deref
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 Deref -> Deref -> Deref
DerefBranch (t Deref -> Deref) -> t Deref -> Deref
forall a b. (a -> b) -> a -> b
$ [Deref] -> t Deref
lhs []
Deref -> ParsecT String st Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> ParsecT String st Identity Deref)
-> Deref -> ParsecT String st Identity Deref
forall a b. (a -> b) -> a -> b
$ Deref -> Deref -> Deref
DerefBranch Deref
lhs' Deref
rhs
derefSingle' :: ParsecT String u Identity Deref
derefSingle' = do
Deref
x <- ParsecT String u Identity Deref -> ParsecT String u Identity Deref
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String u Identity Deref
-> ParsecT String u Identity Deref)
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$ ParsecT String u Identity ()
forall u. ParsecT String u Identity ()
delim ParsecT String u Identity ()
-> ParsecT String u Identity Deref
-> ParsecT String u Identity Deref
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String u Identity Deref
forall a. UserParser a Deref
derefSingle
([Deref] -> t Deref) -> ParsecT String u Identity Deref
deref' (([Deref] -> t Deref) -> ParsecT String u Identity Deref)
-> ([Deref] -> t Deref) -> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$ [Deref] -> t Deref
lhs ([Deref] -> t Deref) -> ([Deref] -> [Deref]) -> [Deref] -> t Deref
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Deref
x
numeric :: ParsecT String u Identity Deref
numeric = do
String
n <- (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '-' ParsecT String u Identity Char
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> ParsecT String u Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return "-") ParsecT String u Identity String
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String u Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return ""
String
x <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
Maybe String
y <- (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '.' ParsecT String u Identity Char
-> ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (String -> Maybe String)
-> ParsecT String u Identity String
-> ParsecT String u Identity (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Maybe String
forall a. a -> Maybe a
Just (ParsecT String u Identity Char -> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit)) ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe String -> ParsecT String u Identity (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
Deref -> ParsecT String u Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> ParsecT String u Identity Deref)
-> Deref -> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$ case Maybe String
y of
Nothing -> Integer -> Deref
DerefIntegral (Integer -> Deref) -> Integer -> Deref
forall a b. (a -> b) -> a -> b
$ String -> String -> Integer
forall a. Read a => String -> String -> a
read' "Integral" (String -> Integer) -> String -> Integer
forall a b. (a -> b) -> a -> b
$ String
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
x
Just z :: String
z -> Rational -> Deref
DerefRational (Rational -> Deref) -> Rational -> Deref
forall a b. (a -> b) -> a -> b
$ Double -> Rational
forall a. Real a => a -> Rational
toRational
(String -> String -> Double
forall a. Read a => String -> String -> a
read' "Rational" (String -> Double) -> String -> Double
forall a b. (a -> b) -> a -> b
$ String
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ '.' Char -> ShowS
forall a. a -> [a] -> [a]
: String
z :: Double)
strLit :: ParsecT String u Identity Deref
strLit = do
Char
_ <- Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '"'
String
chars <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String u Identity Char
forall u. ParsecT String u Identity Char
quotedChar
Char
_ <- Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '"'
Deref -> ParsecT String u Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> ParsecT String u Identity Deref)
-> Deref -> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$ String -> Deref
DerefString String
chars
quotedChar :: ParsecT String u Identity Char
quotedChar = (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String u Identity Char
forall u. ParsecT String u Identity Char
escapedChar) ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf "\""
escapedChar :: ParsecT String u Identity Char
escapedChar =
let cecs :: [(Char, Char)]
cecs = [('n', '\n'), ('r', '\r'), ('b', '\b'), ('t', '\t')
,('\\', '\\'), ('"', '"'), ('\'', '\'')]
in [ParsecT String u Identity Char] -> ParsecT String u Identity Char
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT String u Identity Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
ec | (c :: Char
c, ec :: Char
ec) <- [(Char, Char)]
cecs]
ident :: ParsecT String u Identity Deref
ident = do
[String]
mods <- ParsecT String u Identity String
-> ParsecT String u Identity [String]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String u Identity String
forall st. GenParser Char st String
modul
String
func <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '_' ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\'')
let func' :: Ident
func' = String -> Ident
Ident String
func
Deref -> ParsecT String u Identity Deref
forall (m :: * -> *) a. Monad m => a -> m a
return (Deref -> ParsecT String u Identity Deref)
-> Deref -> ParsecT String u Identity Deref
forall a b. (a -> b) -> a -> b
$
if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
mods
then Ident -> Deref
DerefIdent Ident
func'
else [String] -> Ident -> Deref
DerefModulesIdent [String]
mods Ident
func'
modul :: GenParser Char st String
modul = GenParser Char st String -> GenParser Char st String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st String -> GenParser Char st String)
-> GenParser Char st String -> GenParser Char st String
forall a b. (a -> b) -> a -> b
$ do
Char
c <- ParsecT String st Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
upper
String
cs <- ParsecT String st Identity Char -> GenParser Char st String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT String st Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum ParsecT String st Identity Char
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '_')
Char
_ <- Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '.'
String -> GenParser Char st String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> GenParser Char st String)
-> String -> GenParser Char st String
forall a b. (a -> b) -> a -> b
$ Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: String
cs
read' :: Read a => String -> String -> a
read' :: String -> String -> a
read' t :: String
t s :: String
s =
case ReadS a
forall a. Read a => ReadS a
reads String
s of
(x :: a
x, _):_ -> a
x
[] -> String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ " read failed: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
expType :: Ident -> Name -> Exp
expType :: Ident -> Name -> Exp
expType (Ident (c :: Char
c:_)) = if Char -> Bool
isUpper Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ':' then Name -> Exp
ConE else Name -> Exp
VarE
expType (Ident "") = String -> Name -> Exp
forall a. HasCallStack => String -> a
error "Bad Ident"
derefToExp :: Scope -> Deref -> Exp
derefToExp :: Scope -> Deref -> Exp
derefToExp s :: Scope
s (DerefBranch x :: Deref
x y :: Deref
y) = Scope -> Deref -> Exp
derefToExp Scope
s Deref
x Exp -> Exp -> Exp
`AppE` Scope -> Deref -> Exp
derefToExp Scope
s Deref
y
derefToExp _ (DerefModulesIdent mods :: [String]
mods i :: Ident
i@(Ident s :: String
s)) =
Ident -> Name -> Exp
expType Ident
i (Name -> Exp) -> Name -> Exp
forall a b. (a -> b) -> a -> b
$ OccName -> NameFlavour -> Name
Name (String -> OccName
mkOccName String
s) (ModName -> NameFlavour
NameQ (ModName -> NameFlavour) -> ModName -> NameFlavour
forall a b. (a -> b) -> a -> b
$ String -> ModName
mkModName (String -> ModName) -> String -> ModName
forall a b. (a -> b) -> a -> b
$ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate "." [String]
mods)
derefToExp scope :: Scope
scope (DerefIdent i :: Ident
i@(Ident s :: String
s)) =
case Ident -> Scope -> Maybe Exp
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Ident
i Scope
scope of
Just e :: Exp
e -> Exp
e
Nothing -> Ident -> Name -> Exp
expType Ident
i (Name -> Exp) -> Name -> Exp
forall a b. (a -> b) -> a -> b
$ String -> Name
mkName String
s
derefToExp _ (DerefIntegral i :: Integer
i) = Lit -> Exp
LitE (Lit -> Exp) -> Lit -> Exp
forall a b. (a -> b) -> a -> b
$ Integer -> Lit
IntegerL Integer
i
derefToExp _ (DerefRational r :: Rational
r) = Lit -> Exp
LitE (Lit -> Exp) -> Lit -> Exp
forall a b. (a -> b) -> a -> b
$ Rational -> Lit
RationalL Rational
r
derefToExp _ (DerefString s :: String
s) = Lit -> Exp
LitE (Lit -> Exp) -> Lit -> Exp
forall a b. (a -> b) -> a -> b
$ String -> Lit
StringL String
s
derefToExp s :: Scope
s (DerefList ds :: [Deref]
ds) = [Exp] -> Exp
ListE ([Exp] -> Exp) -> [Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ (Deref -> Exp) -> [Deref] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map (Scope -> Deref -> Exp
derefToExp Scope
s) [Deref]
ds
derefToExp s :: Scope
s (DerefTuple ds :: [Deref]
ds) = [Exp] -> Exp
TupE ([Exp] -> Exp) -> [Exp] -> Exp
forall a b. (a -> b) -> a -> b
$
#if MIN_VERSION_template_haskell(2,16,0)
map Just $
#endif
(Deref -> Exp) -> [Deref] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map (Scope -> Deref -> Exp
derefToExp Scope
s) [Deref]
ds
flattenDeref :: Deref -> Maybe [String]
flattenDeref :: Deref -> Maybe [String]
flattenDeref (DerefIdent (Ident x :: String
x)) = [String] -> Maybe [String]
forall a. a -> Maybe a
Just [String
x]
flattenDeref (DerefBranch (DerefIdent (Ident x :: String
x)) y :: Deref
y) = do
[String]
y' <- Deref -> Maybe [String]
flattenDeref Deref
y
[String] -> Maybe [String]
forall a. a -> Maybe a
Just ([String] -> Maybe [String]) -> [String] -> Maybe [String]
forall a b. (a -> b) -> a -> b
$ [String]
y' [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
x]
flattenDeref _ = Maybe [String]
forall a. Maybe a
Nothing
parseHash :: UserParser a (Either String Deref)
parseHash :: UserParser a (Either String Deref)
parseHash = Char -> UserParser a (Either String Deref)
forall a. Char -> UserParser a (Either String Deref)
parseVar '#'
curlyBrackets :: UserParser a String
curlyBrackets :: UserParser a String
curlyBrackets = do
Char
_<- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{'
String
var <- ParsecT String a Identity Char -> UserParser a String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String a Identity Char -> UserParser a String)
-> ParsecT String a Identity Char -> UserParser a String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf "}"
Char
_<- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}'
String -> UserParser a String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> UserParser a String) -> String -> UserParser a String
forall a b. (a -> b) -> a -> b
$ ('{'Char -> ShowS
forall a. a -> [a] -> [a]
:String
var) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "}"
type UserParser a = Parsec String a
parseVar :: Char -> UserParser a (Either String Deref)
parseVar :: Char -> UserParser a (Either String Deref)
parseVar c :: Char
c = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
(Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left [Char
c])) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
Deref
deref <- UserParser a Deref
forall a. UserParser a Deref
derefCurlyBrackets
Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String Deref -> UserParser a (Either String Deref))
-> Either String Deref -> UserParser a (Either String Deref)
forall a b. (a -> b) -> a -> b
$ Deref -> Either String Deref
forall a b. b -> Either a b
Right Deref
deref) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
()
_ <- ParsecT String a Identity () -> ParsecT String a Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (String -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf "\r\n" ParsecT String a Identity Char
-> ParsecT String a Identity () -> ParsecT String a Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> ParsecT String a Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) ParsecT String a Identity ()
-> ParsecT String a Identity () -> ParsecT String a Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String a Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String Deref -> UserParser a (Either String Deref))
-> Either String Deref -> UserParser a (Either String Deref)
forall a b. (a -> b) -> a -> b
$ String -> Either String Deref
forall a b. a -> Either a b
Left ""
) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left [Char
c])
parseAt :: UserParser a (Either String (Deref, Bool))
parseAt :: UserParser a (Either String (Deref, Bool))
parseAt = Char -> Char -> UserParser a (Either String (Deref, Bool))
forall a.
Char -> Char -> UserParser a (Either String (Deref, Bool))
parseUrl '@' '?'
parseUrl :: Char -> Char -> UserParser a (Either String (Deref, Bool))
parseUrl :: Char -> Char -> UserParser a (Either String (Deref, Bool))
parseUrl c :: Char
c d :: Char
d = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
(Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> UserParser a (Either String (Deref, Bool))
-> UserParser a (Either String (Deref, Bool))
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String (Deref, Bool)
-> UserParser a (Either String (Deref, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String (Deref, Bool)
forall a b. a -> Either a b
Left [Char
c])) UserParser a (Either String (Deref, Bool))
-> UserParser a (Either String (Deref, Bool))
-> UserParser a (Either String (Deref, Bool))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
Bool
x <- (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
d ParsecT String a Identity Char
-> ParsecT String a Identity Bool -> ParsecT String a Identity Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT String a Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) ParsecT String a Identity Bool
-> ParsecT String a Identity Bool -> ParsecT String a Identity Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Bool -> ParsecT String a Identity Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
(do
Deref
deref <- UserParser a Deref
forall a. UserParser a Deref
derefCurlyBrackets
Either String (Deref, Bool)
-> UserParser a (Either String (Deref, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (Deref, Bool)
-> UserParser a (Either String (Deref, Bool)))
-> Either String (Deref, Bool)
-> UserParser a (Either String (Deref, Bool))
forall a b. (a -> b) -> a -> b
$ (Deref, Bool) -> Either String (Deref, Bool)
forall a b. b -> Either a b
Right (Deref
deref, Bool
x))
UserParser a (Either String (Deref, Bool))
-> UserParser a (Either String (Deref, Bool))
-> UserParser a (Either String (Deref, Bool))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String (Deref, Bool)
-> UserParser a (Either String (Deref, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String (Deref, Bool)
forall a b. a -> Either a b
Left (String -> Either String (Deref, Bool))
-> String -> Either String (Deref, Bool)
forall a b. (a -> b) -> a -> b
$ if Bool
x then [Char
c, Char
d] else [Char
c]))
parseInterpolatedString :: Char -> UserParser a (Either String String)
parseInterpolatedString :: Char -> UserParser a (Either String String)
parseInterpolatedString c :: Char
c = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
(Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String String
forall a b. a -> Either a b
Left ['\\', Char
c])) UserParser a (Either String String)
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
String
bracketed <- UserParser a String
forall st. GenParser Char st String
curlyBrackets
Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String String -> UserParser a (Either String String))
-> Either String String -> UserParser a (Either String String)
forall a b. (a -> b) -> a -> b
$ String -> Either String String
forall a b. b -> Either a b
Right (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:String
bracketed)) UserParser a (Either String String)
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String String
forall a b. a -> Either a b
Left [Char
c])
parseVarString :: Char -> UserParser a (Either String String)
parseVarString :: Char -> UserParser a (Either String String)
parseVarString = Char -> UserParser a (Either String String)
forall a. Char -> UserParser a (Either String String)
parseInterpolatedString
parseUrlString :: Char -> Char -> UserParser a (Either String String)
parseUrlString :: Char -> Char -> UserParser a (Either String String)
parseUrlString c :: Char
c d :: Char
d = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
(Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String String
forall a b. a -> Either a b
Left [Char
c, '\\'])) UserParser a (Either String String)
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
String
ds <- (Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
d ParsecT String a Identity Char
-> ParsecT String a Identity String
-> ParsecT String a Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> ParsecT String a Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return [Char
d]) ParsecT String a Identity String
-> ParsecT String a Identity String
-> ParsecT String a Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String a Identity String
forall (m :: * -> *) a. Monad m => a -> m a
return []
(do String
bracketed <- ParsecT String a Identity String
forall st. GenParser Char st String
curlyBrackets
Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String String -> UserParser a (Either String String))
-> Either String String -> UserParser a (Either String String)
forall a b. (a -> b) -> a -> b
$ String -> Either String String
forall a b. b -> Either a b
Right (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:String
ds String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
bracketed))
UserParser a (Either String String)
-> UserParser a (Either String String)
-> UserParser a (Either String String)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String String -> UserParser a (Either String String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String String
forall a b. a -> Either a b
Left (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:String
ds)))
parseIntString :: Char -> UserParser a (Either String String)
parseIntString :: Char -> UserParser a (Either String String)
parseIntString = Char -> UserParser a (Either String String)
forall a. Char -> UserParser a (Either String String)
parseInterpolatedString
parseCaret :: UserParser a (Either String Deref)
parseCaret :: UserParser a (Either String Deref)
parseCaret = Char -> UserParser a (Either String Deref)
forall a. Char -> UserParser a (Either String Deref)
parseInt '^'
parseInt :: Char -> UserParser a (Either String Deref)
parseInt :: Char -> UserParser a (Either String Deref)
parseInt c :: Char
c = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
(UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall tok st a. GenParser tok st a -> GenParser tok st a
try (UserParser a (Either String Deref)
-> UserParser a (Either String Deref))
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> ParsecT String a Identity Char -> ParsecT String a Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{' ParsecT String a Identity Char
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left [Char
c, '{'])) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
Deref
deref <- UserParser a Deref
forall a. UserParser a Deref
derefCurlyBrackets
Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String Deref -> UserParser a (Either String Deref))
-> Either String Deref -> UserParser a (Either String Deref)
forall a b. (a -> b) -> a -> b
$ Deref -> Either String Deref
forall a b. b -> Either a b
Right Deref
deref) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left [Char
c])
parseUnder :: UserParser a (Either String Deref)
parseUnder :: UserParser a (Either String Deref)
parseUnder = do
Char
_ <- Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '_'
(Char -> ParsecT String a Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String a Identity Char
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left "_")) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (do
Deref
deref <- UserParser a Deref
forall a. UserParser a Deref
derefCurlyBrackets
Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String Deref -> UserParser a (Either String Deref))
-> Either String Deref -> UserParser a (Either String Deref)
forall a b. (a -> b) -> a -> b
$ Deref -> Either String Deref
forall a b. b -> Either a b
Right Deref
deref) UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
-> UserParser a (Either String Deref)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Either String Deref -> UserParser a (Either String Deref)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Either String Deref
forall a b. a -> Either a b
Left "_")
readUtf8FileString :: FilePath -> IO String
readUtf8FileString :: String -> IO String
readUtf8FileString fp :: String
fp = (Text -> String) -> IO Text -> IO String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> String
TL.unpack (IO Text -> IO String) -> IO Text -> IO String
forall a b. (a -> b) -> a -> b
$ String -> IO Text
readUtf8File String
fp
readUtf8File :: FilePath -> IO TL.Text
readUtf8File :: String -> IO Text
readUtf8File fp :: String
fp = do
Handle
h <- String -> IOMode -> IO Handle
SIO.openFile String
fp IOMode
SIO.ReadMode
Handle -> TextEncoding -> IO ()
SIO.hSetEncoding Handle
h TextEncoding
SIO.utf8_bom
Text
ret <- Handle -> IO Text
TIO.hGetContents Handle
h
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> IO Text) -> Text -> IO Text
forall a b. (a -> b) -> a -> b
$
#ifdef WINDOWS
TL.filter ('\r'/=) ret
#else
Text
ret
#endif
readFileQ :: FilePath -> Q String
readFileQ :: String -> Q String
readFileQ fp :: String
fp = IO String -> Q String
forall (m :: * -> *) a. Quasi m => IO a -> m a
qRunIO (String -> IO String
readUtf8FileString String
fp)
readFileRecompileQ :: FilePath -> Q String
readFileRecompileQ :: String -> Q String
readFileRecompileQ fp :: String
fp = String -> Q ()
addDependentFile String
fp Q () -> Q String -> Q String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Q String
readFileQ String
fp