module Text.Interpolation.Nyan.Core
(
mkInt
, InterpolatorOptions
, defaultInterpolatorOptions
, defaultSwitchesOptions
, valueInterpolator
, invisibleCharsPreview
, DefaultSwitchesOptions
, basicDefaultSwitchesOptions
, recommendedDefaultSwitchesOptions
, defSpacesTrimming
, defIndentationStripping
, defLeadingNewlineStripping
, defTrailingSpacesStripping
, defReducedNewlines
, defReturnType
, defMonadic
, ValueInterpolator (..)
, simpleValueInterpolator
, tickedValueInterpolator
, InvisibleCharsPreview (..)
, simpleInvisibleCharsPreview
, RMode (..)
, TH.QuasiQuoter
) where
import qualified Data.Text as T
import qualified Language.Haskell.TH.Quote as TH
import Text.Interpolation.Nyan.Core.Internal.Base
import Text.Interpolation.Nyan.Core.Internal.Parser
import Text.Interpolation.Nyan.Core.Internal.Processor
import Text.Interpolation.Nyan.Core.Internal.RMode
import Text.Interpolation.Nyan.Core.Internal.Splice
mkInt :: InterpolatorOptions -> TH.QuasiQuoter
mkInt :: InterpolatorOptions -> QuasiQuoter
mkInt InterpolatorOptions
iopts = TH.QuasiQuoter
{ quoteExp :: String -> Q Exp
TH.quoteExp = \String
s -> do
(SwitchesOptions
sopts, ParsedInterpolatedString
sint) <-
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
DefaultSwitchesOptions
-> Text
-> Either String (SwitchesOptions, ParsedInterpolatedString)
parseIntString (InterpolatorOptions -> DefaultSwitchesOptions
defaultSwitchesOptions InterpolatorOptions
iopts) (Text -> Text
useUnixLineEndings forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s)
let sint' :: InterpolatedString
sint' = SwitchesOptions -> ParsedInterpolatedString -> InterpolatedString
processIntString SwitchesOptions
sopts ParsedInterpolatedString
sint
InterpolatorOptions
-> (SwitchesOptions, InterpolatedString) -> Q Exp
intSplice InterpolatorOptions
iopts (SwitchesOptions
sopts, InterpolatedString
sint')
, quotePat :: String -> Q Pat
TH.quotePat = \String
_ ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Cannot interpolate at pattern position"
, quoteType :: String -> Q Type
TH.quoteType = \String
_ ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Cannot interpolate at type position"
, quoteDec :: String -> Q [Dec]
TH.quoteDec = \String
_ ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Cannot interpolate at declaration position"
}
where
useUnixLineEndings :: T.Text -> T.Text
useUnixLineEndings :: Text -> Text
useUnixLineEndings = Text -> Text -> Text -> Text
T.replace Text
"\r\n" Text
"\n"
defaultInterpolatorOptions :: InterpolatorOptions
defaultInterpolatorOptions :: InterpolatorOptions
defaultInterpolatorOptions = InterpolatorOptions
{ defaultSwitchesOptions :: DefaultSwitchesOptions
defaultSwitchesOptions = DefaultSwitchesOptions
basicDefaultSwitchesOptions
, valueInterpolator :: ValueInterpolator
valueInterpolator = ValueInterpolator
simpleValueInterpolator
, invisibleCharsPreview :: InvisibleCharsPreview
invisibleCharsPreview = InvisibleCharsPreview
simpleInvisibleCharsPreview
}