Interpolation 0.2 → 0.2.1
raw patch · 2 files changed
+60/−17 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.String.Interpolation: endline :: String
+ Data.String.Interpolation: tab :: String
Files
- Data/String/Interpolation.hs +55/−14
- Interpolation.cabal +5/−3
Data/String/Interpolation.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE QuasiQuotes,TemplateHaskell,DeriveDataTypeable #-}-module Data.String.Interpolation(str) where+module Data.String.Interpolation(str,endline,tab) where import Language.Haskell.TH as TH import Language.Haskell.TH.Quote import Language.Haskell.Meta@@ -8,12 +8,18 @@ import Data.Char import Data.List(intercalate) ++ quoteExprExp :: String -> TH.ExpQ -- | Quasiquote 'str' implements multiline strings with interpolation.--- Interpolating a value of parameter a into the string is done by $a$--- and interpolating anything with instance Show is $:a$.+-- Interpolating a value into the string is done by +-- $\<String expression\>$+-- and interpolating anything with instance Show is +-- $:\<Show expression\>$. Due to pretty deep limitations, the parser+-- is not able to properly deduce associtivity of infix operators,+-- so use lots and lots of parenthesis. ----- Repetitive patterns can be made by # symbol using the following syntax: +-- Repetitive patterns can be made by # symbol: -- -- @ -- \#\<var\> in \<list\>: \<interpolated string\> (|\<interpolated string\>)\#@@ -22,24 +28,59 @@ -- Where (|\<interpolated string\>) denotes optional separator for the -- elements. -- +-- Multiline indentation is handled by aligning on smallest un-empty+-- line after the first. Neither pattern matching nor nested #-patterns+-- are supported. Normal '\\n' style escaping of special characters+-- is intentionally not supported. Please use $endline$ or $"\n"$ +-- style instead. (Also, in this beta release $,## and : symbols are+-- not escaped in the interpolated expressions. ----- Example:--- +-- As an example, let's plot set of vectors with gnuplot:+-- -- @--- \#i in myList: this is $i$|--\#+-- plotVecs :: [(String,[Double])] -> String+-- plotVecs vs = +-- [$str| ## Plot multiple vectors+-- plot #(n,_) in vs:'-' with lines lw 5 title $n$ |, #+-- #d in map snd vs:$singleVec d$$endline$e$endline$# |]+-- where+-- singleVec n = [$str|#(e,i) in zip n [1..]: $:i$ $:e$|$endline$#|] -- @ -- --- Which will evaluate to @ 1--2--3 @ given myList of [1,2,3]+-- @+-- *Gnuplotter> plotVecs [("A",[1..5]),("B",[2..6])]+-- # Plot multiple vectors+-- plot '-' with lines lw 5 title A , '-' with lines lw 5 title B +-- 1 1.0+-- 2 2.0+-- 3 3.0+-- 4 4.0+-- 5 5.0 -- --- --- Multiline indentation is handled by aligning on smallest un-empty--- line after the first.------ Pattern matching is not supported. ---+-- e+-- 1 2.0+-- 2 3.0+-- 3 4.0+-- 4 5.0+-- 5 6.0+-- +-- e+-- @ str :: QuasiQuoter str = QuasiQuoter quoteExprExp undefined++-- ** Predefined strings++-- | End of the line +endline :: String+endline = "\n"++-- | Tab+tab :: String+tab = "\t"++ -- quoteExprExp s = psToStringE (parParse $ norming s) --
Interpolation.cabal view
@@ -1,9 +1,11 @@ Name: Interpolation-Version: 0.2+Version: 0.2.1 Description: This package adds quasiquoter for multiline strings, interpolation and simple templating.- Handy for text generation.-Category: Text+ It can handle repetition templates which makes it+ Handy for outputting larger structures, such as+ latex tables or gnuplot files.+Category: Data,Text Synopsis: Multiline strings, interpolation and templating. License: OtherLicense License-file: LICENSE