vformat 0.13.0.0 → 0.14.0.0
raw patch · 4 files changed
+118/−14 lines, 4 filesdep +template-haskell
Dependencies added: template-haskell
Files
- ChangeLog.md +14/−11
- README.md +6/−1
- src/Text/Format/TH.hs +93/−0
- vformat.cabal +5/−2
ChangeLog.md view
@@ -1,20 +1,23 @@ # Changelog for vformat -## V0.10.0-- Rewrite error system & fix bugs-- Fix document-- Rewrite unit tests+## V0.14.0+- Add `QuasiQuoter`s for `Format` and `Format1` +## V0.13.0+- Add `FromArgKey` typeclass+- Fix `OVERLAPPABLE` issue++## V0.12.0+- Add `defaultSpecs`+- Remove `FormatTime` instance+ ## V0.11.0 - Simplify `ArgKey` - Make generic instantiate FormatArg configurable - Expose standard formatters - Fix some issue and doc -## V0.12.0-- Add `defaultSpecs`-- Remove `FormatTime` instance--## V0.13.0-- Add `FromArgKey` typeclass-- Fix `OVERLAPPABLE` issue+## V0.10.0+- Rewrite error system & fix bugs+- Fix document+- Rewrite unit tests
README.md view
@@ -1,3 +1,8 @@-# vformat+# vformat [](http://hackage.haskell.org/package/vformat) [](https://travis-ci.org/versioncloud/vformat) [](https://ci.appveyor.com/project/gqk007/vformat/branch/master) Please see http://hackage.haskell.org/package/vformat+++## Related packages+- http://hackage.haskell.org/package/vformat-time+- http://hackage.haskell.org/package/vformat-aeson
+ src/Text/Format/TH.hs view
@@ -0,0 +1,93 @@+{-# LANGUAGE DeriveLift #-}+{-# LANGUAGE StandaloneDeriving #-}++module Text.Format.TH ( formatQQ, format1QQ ) where++import Data.String+import Language.Haskell.TH+import Language.Haskell.TH.Quote+import Language.Haskell.TH.Syntax+import Text.Format.ArgFmt+import Text.Format.ArgKey+import Text.Format.Format++deriving instance Lift ArgKey+deriving instance Lift ArgFmt+deriving instance Lift FmtAlign+deriving instance Lift FmtSign+deriving instance Lift FmtNumSep+deriving instance Lift FmtItem+deriving instance Lift Format+deriving instance Lift Format1+++{-| A QuasiQuoter for 'Format' with which you can write multi-line 'Format'.++Note: @">>>"@ after @"[formatQQ|"@ means starting from the next line,+ @"<<<"@ before @"|]"@ means ending from the previous line.++==== Example++>>> :set -XTemplateHaskell+>>> :set -XQuasiQuotes+>>> import Text.Format+>>> import Text.Format.TH+>>> :{+fmt1 :: Format+fmt1 = [formatQQ|>>>+first line {hi}+newline {words}+last line {bye}+<<<|]+fmt2 :: Format+fmt2 = [formatQQ|first line {hi}+newline {words}+last line {bye}|]+fmt3 :: Format+fmt3 = "first line {hi}\nnewline {words}\nlast line {bye}"+:}+>>> format fmt1 ("hi" := "hi") ("words" := "say something") ("bye" := "bye")+"first line hi\nnewline say something\nlast line bye"+>>> format fmt2 ("hi" := "hi") ("words" := "say something") ("bye" := "bye")+"first line hi\nnewline say something\nlast line bye"+>>> format fmt3 ("hi" := "hi") ("words" := "say something") ("bye" := "bye")+"first line hi\nnewline say something\nlast line bye"++@since 0.14.0+-}+formatQQ :: QuasiQuoter+formatQQ = QuasiQuoter { quoteExp = formatExp+ , quotePat = undefined+ , quoteType = undefined+ , quoteDec = undefined+ }++formatExp :: String -> Q Exp+formatExp fs = lift $ (fromString (fixEnd $ fixBegin fs) :: Format)+++{-| Same as 'formatQQ', but for 'Format1'.++@since 0.14.0+-}+format1QQ :: QuasiQuoter+format1QQ = QuasiQuoter { quoteExp = format1Exp+ , quotePat = undefined+ , quoteType = undefined+ , quoteDec = undefined+ }++format1Exp :: String -> Q Exp+format1Exp fs = lift $ (fromString (fixEnd $ fixBegin fs) :: Format1)+++fixBegin :: String -> String+fixBegin ('>':'>':'>':"") = ""+fixBegin ('>':'>':'>':'\n':fs) = fs+fixBegin fs = fs+++fixEnd :: String -> String+fixEnd ('<':'<':'<':"") = ""+fixEnd fs | ('<':'<':'<':'\n':fs') <- reverse fs = reverse fs'+fixEnd fs = fs
vformat.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f705e4890246248ac73f5ee9489edc8b4f36b6938729787e055dcb2f2973386b+-- hash: 81b8aa366e7778096840d2ebe95e156e87ba58b0430ef7e01c19011083c4351e name: vformat-version: 0.13.0.0+version: 0.14.0.0 synopsis: A Python str.format() like formatter description: Please see the http://hackage.haskell.org/package/vformat category: Text, Format@@ -29,6 +29,7 @@ library exposed-modules: Text.Format+ Text.Format.TH other-modules: Text.Format.ArgFmt Text.Format.ArgKey@@ -42,6 +43,7 @@ base >=4.7 && <5 , containers >=0.5.9 && <1.0 , exceptions >=0.8 && <1.0+ , template-haskell >=2.12 && <3.0 default-language: Haskell2010 test-suite vformat-test@@ -58,5 +60,6 @@ , containers >=0.5.9 && <1.0 , exceptions >=0.8 && <1.0 , hspec >=2.1 && <3.0+ , template-haskell >=2.12 && <3.0 , vformat default-language: Haskell2010