Interpolation 0.2.6.0 → 0.3.0
raw patch · 2 files changed
+60/−20 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.String.Interpolation: endline :: String
+ Data.String.Interpolation: endline :: IsString a => a
- Data.String.Interpolation: tab :: String
+ Data.String.Interpolation: tab :: IsString a => a
Files
- Data/String/Interpolation.hs +52/−17
- Interpolation.cabal +8/−3
Data/String/Interpolation.hs view
@@ -1,13 +1,30 @@ {-# LANGUAGE CPP,QuasiQuotes,TemplateHaskell,DeriveDataTypeable,PatternGuards #-} {-# OPTIONS_GHC -fno-warn-missing-fields #-} ++-- | This module defines a quasiquoter for interpolated strings. For example:+--+-- @+-- import qualified Data.Text.Lazy as LT+-- let fb x | x \`mod\` 15 == 0 = \"FizzBuzz\" +-- | x \`mod\` 5 == 0 = \"Buzz\" +-- | x \`mod\` 3 == 0 = \"Fizz\" +-- | otherwise = LT.pack (show x)+-- @+--+-- >>> LT.take 85 [str|#x in [1..]:$fb x$|, #|] <> ".. "+-- "1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz.. "+-- +-- module Data.String.Interpolation(str,prnt,endline,tab) where import Language.Haskell.TH as TH import Language.Haskell.TH.Quote import Language.Haskell.Meta import Data.Data import Data.Maybe+import Data.Monoid import Data.Char-import Data.List(intercalate)+import Data.String+-- import Data.List(intercalate) @@ -69,37 +86,38 @@ -- e -- @ ----- Change log--- 0.2.5.2 - Possibly now compiles with GHC 6.12 +-- | Quasiquoter for interpolating strings. Produces values of `(Monoid m, IsString m) => m` str :: QuasiQuoter str = QuasiQuoter {quoteExp = quoteExprExp} +-- | Quasiquoter for printing an interpolated String prnt :: QuasiQuoter prnt = QuasiQuoter {quoteExp = quoteExprPExp} -- ** Predefined strings -- | End of the line -endline :: String-endline = "\n"+endline :: IsString a => a+endline = fromString "\n" -- | Tab-tab :: String-tab = "\t"+tab :: IsString a => a+tab = fromString "\t" ---quoteExprPExp = TH.appE (TH.varE (TH.mkName "putStr"))- . quoteExprExp --- quoteExprExp s = psToStringE (parParse $ norming s)++quoteExprPExp :: String -> ExpQ+quoteExprPExp = TH.appE [|putStr|] . quoteExprExp + -- psToStringE :: PieceString -> TH.Q TH.Exp-psToStringE [] = TH.stringE ""-psToStringE (x:xs) = TH.infixE (Just $ sbitToExp x)- ([| (++) |])- (Just $ psToStringE xs)+psToStringE [] = [|mempty|] --TH.stringE ""+psToStringE (x:xs) = ([| mappend |]) `TH.appE`+ (sbitToExp x) `TH.appE` + (psToStringE xs) runEither :: (Monad m) => [Char] -> Either [Char] t -> m t runEither _ (Right x) = return x@@ -107,10 +125,11 @@ appM :: (Monad m) => String -> m Exp appM expr = runEither ("Parse error in antiquote <"++expr++">") (parseExp expr)+ sbitToExp :: StringBits -> ExpQ-sbitToExp (Str x) = TH.stringE x -sbitToExp (Var x) = appM x --(TH.varE (TH.mkName x))-sbitToExp (SVar x) = TH.appE (TH.varE (TH.mkName "show"))+sbitToExp (Str x) = [| fromString |] `appE` TH.stringE x +sbitToExp (Var x) = appM x +sbitToExp (SVar x) = TH.appE [| fromString . show |]--(TH.varE (TH.mkName "show")) (sbitToExp (Var x)) sbitToExp (RepVar varName lstName rep sep) @@ -209,4 +228,20 @@ minimumD :: (Ord a) => a -> [a] -> a minimumD d [] = d minimumD _ x = minimum x+++-- Re-implementation of intercalate and intersperse using monoid instead of lists++intersperse :: a -> [a] -> [a]+intersperse _ [] = []+intersperse sep (x:xs) = x : prependToAll sep xs+++prependToAll :: a -> [a] -> [a]+prependToAll _ [] = []+prependToAll sep (x:xs) = sep : x : prependToAll sep xs++intercalate :: Monoid a => a -> [a] -> a+intercalate xs xss = mconcat (intersperse xs xss)+
Interpolation.cabal view
@@ -1,14 +1,19 @@ Name: Interpolation-Version: 0.2.6.0+Version: 0.3.0 Description: This package adds quasiquoter for multiline strings, interpolation and simple templating. It can handle repetition templates which makes it Handy for outputting larger structures, such as latex tables or gnuplot files. .- 0.2.6 -- Handy print quote.+ 0.3.0 - Instead of Strings, the `str` quasiquoter produces + values of type `(Monoid a, IsString a) => a`, making+ it compatible many other libraries, such as+ `Data.Text` and `Blaze.Builder`. .- 0.2.5.1 -- version bump for ghc-7.0.1+ 0.2.6 - A handy quote for printing+ .+ 0.2.5.1 - version bump for ghc-7.0.1 Category: Data,Text Synopsis: Multiline strings, interpolation and templating. License: OtherLicense