packages feed

yasi 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+78/−8 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Yasi: iB :: QuasiQuoter
+ Yasi: iBL :: QuasiQuoter
+ Yasi: iFS :: QuasiQuoter
+ Yasi: iS :: QuasiQuoter
+ Yasi: iT :: QuasiQuoter
+ Yasi: iTL :: QuasiQuoter
+ Yasi.Internal: ipExpr :: Exp -> Exp -> [Segment] -> Q Exp
- Yasi.Internal: interpolator :: Char -> ([Segment] -> Q [Segment]) -> (Exp -> Q Exp) -> QuasiQuoter
+ Yasi.Internal: interpolator :: Char -> (Exp -> Q Exp) -> QuasiQuoter

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for yasi +## 0.1.1.0 -- 2021-02-13++ * Add interpolator variants (with different return types)+ ## 0.1.0.0 -- 2021-02-13   * Support `show` abstractions
src/Yasi.hs view
@@ -6,9 +6,26 @@ --    by design (e.g. operator fixities). --  * Supports interpolating 'String', 'Data.Text.Text', 'Data.Text.Lazy.Text', --    'Data.ByteString.ByteString' and 'Data.ByteString.Lazy.ByteString' (UTF8).-module Yasi (i) where+module Yasi+  ( i, +    -- * Variants+    iFS,+    iS,+    iT,+    iTL,+    iB,+    iBL,+  )+where++import qualified Data.ByteString as B+import qualified Data.ByteString.Lazy as BL+import Data.String (IsString (..))+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL import qualified Language.Haskell.TH.Quote as TH+import qualified Language.Haskell.TH.Syntax as TH import Yasi.Internal  -- $setup@@ -16,7 +33,10 @@ -- >>> import Data.Text (Text) -- >>> import Data.ByteString (ByteString) --- | The interpolator, intended to be used with+int :: (TH.Exp -> TH.Exp) -> TH.QuasiQuoter+int f = interpolator '$' (pure . f)++-- | The main interpolator, intended to be used with -- [@QuasiQuotes@](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/template_haskell.html#extension-QuasiQuotes). -- -- >>> :set -XQuasiQuotes@@ -38,4 +58,51 @@ -- >>> [i|2 + 2 = $show|] (2 + 2) :: Text -- "2 + 2 = 4" i :: TH.QuasiQuoter-i = interpolator '$' pure pure+i = int id++-- | Like 'i', but works with 'IsString'.+--+-- @['iFS'|...|] = 'fromString' ['i'|...|]@+--+-- >>> :t [iFS|hi|]+-- [iFS|hi|] :: Data.String.IsString a => a+iFS :: TH.QuasiQuoter+iFS = int $ TH.AppE (TH.VarE 'fromString)++intT :: TH.Name -> TH.QuasiQuoter+intT = int . flip TH.SigE . TH.ConT++-- | Like 'i', but with the result type fixed to 'String'.+--+-- @['iS'|...|] = ['i'|...|] :: 'String'@+--+-- >>> :t [iS|hi|]+-- [iS|hi|] :: String+iS :: TH.QuasiQuoter+iS = intT ''String++-- | Like 'i', but with the result type fixed to 'T.Text'.+--+-- @['iT'|...|] = ['i'|...|] :: 'T.Text'@+--+-- >>> :t [iT|hi|]+-- [iT|hi|] :: Text+iT :: TH.QuasiQuoter+iT = intT ''T.Text++-- | Like 'iT', but lazy.+iTL :: TH.QuasiQuoter+iTL = intT ''TL.Text++-- | Like 'i', but with the result type fixed to 'B.ByteString'.+--+-- @['iB'|...|] = ['i'|...|] :: 'B.ByteString'@+--+-- >>> :t [iB|hi|]+-- [iB|hi|] :: ByteString+iB :: TH.QuasiQuoter+iB = intT ''B.ByteString++-- | Like 'iB', but lazy.+iBL :: TH.QuasiQuoter+iBL = intT ''BL.ByteString
src/Yasi/Internal.hs view
@@ -4,6 +4,7 @@ module Yasi.Internal   ( Segment (..),     parseSegments,+    ipExpr,     interpolator,     Stringy (..),   )@@ -94,14 +95,12 @@  interpolator ::   Char ->-  -- | postprocess the 'Segment's-  ([Segment] -> TH.Q [Segment]) ->   -- | postprocess the 'TH.Exp'   (TH.Exp -> TH.Q TH.Exp) ->   TH.QuasiQuoter-interpolator c pp pp' = TH.QuasiQuoter {..}+interpolator c pp = TH.QuasiQuoter {..}   where-    quoteExp = parseSegments c >=> pp >=> ipExpr (TH.VarE 'stringy) (TH.VarE 'mconcat) >=> pp'+    quoteExp = parseSegments c >=> ipExpr (TH.VarE 'stringy) (TH.VarE 'mconcat) >=> pp     quotePat = const $ fail "pattern context not supported"     quoteType = const $ fail "type context not supported"     quoteDec = const $ fail "declaration context not supported"
yasi.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: yasi-version: 0.1.0.0+version: 0.1.1.0  synopsis: Yet another string interpolator description: