packages feed

neat-interpolation 0.2.3 → 0.3

raw patch · 3 files changed

+33/−39 lines, 3 filesdep +textPVP ok

version bump matches the API change (PVP)

Dependencies added: text

API changes (from Hackage documentation)

- NeatInterpolation: indentQQPlaceholder :: Int -> String -> String
- NeatInterpolation: string :: QuasiQuoter
+ NeatInterpolation: text :: QuasiQuoter

Files

executables/APITests.hs view
@@ -17,7 +17,7 @@     (escaped "one")   where     template a b = -      [string|+      [text|         function(){           function(){             $a@@ -25,6 +25,6 @@           return $b         }       |]-    escaped name = [string|this_could_be_${name}_long_identifier|]+    escaped name = [text|this_could_be_${name}_long_identifier|]     a = "{\n  indented line\n  indented line\n}" 
library/NeatInterpolation.hs view
@@ -8,11 +8,12 @@ --  -- Consider the following declaration: -- --- > {-# LANGUAGE QuasiQuotes, OverloadedStrings #-}+-- > {-# LANGUAGE QuasiQuotes #-} -- >  -- > import NeatInterpolation+-- > import Data.Text (Text) -- > --- > f :: String -> String -> String+-- > f :: Text -> Text -> Text -- > f a b =  -- >   [string| -- >     function(){@@ -25,7 +26,7 @@ --  -- Executing the following: -- --- > main = putStrLn $ f "1" "2"+-- > main = T.putStrLn $ f "1" "2" --  -- will produce this (notice the reduced indentation compared to how it was -- declared):@@ -39,7 +40,7 @@ --  -- Now let's test it with multiline string parameters: -- --- > main = putStrLn $ f +-- > main = T.putStrLn $ f -- >   "{\n  indented line\n  indented line\n}"  -- >   "{\n  indented line\n  indented line\n}"  --@@ -69,7 +70,7 @@ -- So -- -- > f "one" == "this_could_be_one_long_identifier"-module NeatInterpolation (string, indentQQPlaceholder) where+module NeatInterpolation (text) where  import BasePrelude @@ -79,17 +80,21 @@ import NeatInterpolation.String import NeatInterpolation.Parsing +import Data.Text (Text)+import qualified Data.Text as T + -- | -- The quasiquoter.-string :: QuasiQuoter-string = QuasiQuoter {quoteExp = quoteExprExp}+text :: QuasiQuoter+text = QuasiQuoter {quoteExp = quoteExprExp}  -- |--- A function used internally by quasiquoter. Just ignore it.-indentQQPlaceholder :: Int -> String -> String-indentQQPlaceholder indent text = case lines text of-  head:tail -> intercalate "\n" $ head : map (replicate indent ' ' ++) tail+-- A function used internally by the quasiquoter. Just ignore it.+indentQQPlaceholder :: Int -> Text -> Text+indentQQPlaceholder indent text = case T.lines text of+  head:tail -> T.intercalate (T.pack "\n") $+               head : map (T.replicate indent (T.singleton ' ') <>) tail   [] -> text   @@ -97,36 +102,24 @@ quoteExprExp input =    case parseLines $ normalizeQQInput input of     Left e -> fail $ show e-    Right lines -> appE [|unlines|] $ linesExp lines--linesExp :: [Line] -> Q Exp-linesExp [] = [|([] :: [String])|]-linesExp (head : tail) = -  (binaryOpE [|(:)|])-    (lineExp head)-    (linesExp tail)+    Right lines -> sigE (appE [|T.unlines|] $ listE $ map lineExp lines)+                        [t|Text|]  lineExp :: Line -> Q Exp-lineExp (Line indent contents) = -  msumExps $ map (contentExp $ fromIntegral indent) contents--+lineExp (Line indent contents) =+  case contents of+    []  -> [| T.empty |]+    [x] -> toExp x+    xs  -> appE [|T.concat|] $ listE $ map toExp xs+  where toExp = contentExp (fromIntegral indent)  contentExp :: Integer -> LineContent -> Q Exp-contentExp _ (LineContentText text) = stringE text+contentExp _ (LineContentText text) = appE [|T.pack|] (stringE text) contentExp indent (LineContentIdentifier name) = do   valueName <- lookupValueName name   case valueName of     Just valueName -> do-      Just indentQQPlaceholderName <- lookupValueName "indentQQPlaceholder"       appE-        (appE (varE indentQQPlaceholderName) $ litE $ integerL indent)+        (appE (varE 'indentQQPlaceholder) $ litE $ integerL indent)         (varE valueName)     Nothing -> fail $ "Value `" ++ name ++ "` is not in scope"--msumExps :: [Q Exp] -> Q Exp-msumExps = foldr (binaryOpE mappendE) memptyE-memptyE = [|mempty|]-mappendE = [|mappend|]--binaryOpE e = \a b -> e `appE` a `appE` b
neat-interpolation.cabal view
@@ -1,14 +1,14 @@ name:   neat-interpolation version:-  0.2.3+  0.3 synopsis:   A quasiquoter for neat and simple multiline text interpolation description:-  NeatInterpolation provides a quasiquoter for producing strings -  with a simple interpolation of input values. +  A quasiquoter for producing Text values with support for+  a simple interpolation of input values.    It removes the excessive indentation from the input and -  accurately manages the indentation of all lines of interpolated variables. +  accurately manages the indentation of all lines of the interpolated variables.  category:   String, QuasiQoutes license:@@ -47,6 +47,7 @@     NeatInterpolation.Parsing     NeatInterpolation.String   build-depends:+    text == 1.*,     parsec >= 3 && < 3.2,     template-haskell >= 2.8 && < 2.11,     base-prelude == 0.1.*,