HStringTemplate 0.5.1.1 → 0.5.1.2
raw patch · 3 files changed
+9/−51 lines, 3 filesdep ~basedep ~parsecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, parsec
API changes (from Hackage documentation)
- Text.StringTemplate.GenericStandard: instance [overlap ok] (Data a) => ToSElem a
Files
- HStringTemplate.cabal +6/−10
- Text/StringTemplate/GenericStandard.hs +0/−36
- Text/StringTemplate/QQ.hs +3/−5
HStringTemplate.cabal view
@@ -1,5 +1,5 @@ name: HStringTemplate-version: 0.5.1.1+version: 0.5.1.2 synopsis: StringTemplate implementation in Haskell. description: A port of the Java library by Terrence Parr. category: Text@@ -12,7 +12,7 @@ build-Depends: base Cabal-Version: >= 1.2 -flag small-base+flag smaller-base flag syb-with-class flag simple-generics flag quasi-quotation@@ -22,18 +22,14 @@ build-depends: syb-with-class exposed-modules: Text.StringTemplate.GenericWithClass - if flag(simple-generics)- build-depends: syb- exposed-modules: Text.StringTemplate.GenericStandard- if flag(quasi-quotation)- build-depends: template-haskell >= 2.3, syb, mtl+ build-depends: template-haskell >= 2.3, mtl exposed-modules: Text.StringTemplate.QQ - if flag(small-base)- build-depends: base >= 3, filepath, parsec < 3, containers, pretty, time, old-time, old-locale, bytestring, directory, array+ if flag(smaller-base)+ build-depends: syb, base >= 4, base < 5, filepath, parsec < 3, containers, pretty, time, old-time, old-locale, bytestring, directory, array else- build-depends: base < 3, filepath, parsec+ build-depends: base > 3, base < 4, filepath, parsec < 3, containers, pretty, time, old-time, old-locale, bytestring, directory, array exposed-modules: Text.StringTemplate Text.StringTemplate.Base Text.StringTemplate.Classes
− Text/StringTemplate/GenericStandard.hs
@@ -1,36 +0,0 @@-{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances, Rank2Types, ScopedTypeVariables #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}------------------------------------------------------------------------ | Generic Instance for ToSElem using standard Data.Generic libraries.---------------------------------------------------------------------}--module Text.StringTemplate.GenericStandard() where-import qualified Data.Map as M-import Text.StringTemplate.Classes-import Text.StringTemplate.Instances()-import Data.Generics.Basics-import Data.Generics.Aliases--gToSElem :: forall a b.(Data a, Stringable b) => a -> SElem b-gToSElem = (\x ->- case (map stripInitUnder (constrFields . toConstr $ x)) of- [] -> LI (STR (showConstr (toConstr x)) :- (gmapQ gToSElem x))- fs -> SM (M.fromList (zip fs (gmapQ gToSElem x)))- )- `ext1Q` (\t -> case t of (Just x) -> gToSElem x; _ -> SNull)- `ext1Q` (SM . fmap gToSElem)- `ext1Q` (LI . map gToSElem)- `extQ` (toSElem :: Bool -> SElem b)- `extQ` (toSElem :: Float -> SElem b)- `extQ` (toSElem :: Double -> SElem b)- `extQ` (toSElem :: Int -> SElem b)- `extQ` (toSElem :: Integer -> SElem b)- `extQ` (toSElem :: String -> SElem b)--instance Data a => ToSElem a- where toSElem = gToSElem--stripInitUnder :: [Char] -> [Char]-stripInitUnder ('_':s) = stripInitUnder s-stripInitUnder s = s
Text/StringTemplate/QQ.hs view
@@ -11,22 +11,20 @@ -- This module provides stmp, a quasi-quoter for StringTemplate expressions. -- Quoted templates are guaranteed syntactically well-formed at compile time, -- and antiquotation (of identifiers only) is provided by backticks.--- Usage: @ let var = [0,1,2] in toString [$stmp|($`var`; separator = ', '$)|] === "(0, 1, 2)"@+-- Usage: @ let var = [0,1,2] in toString [$stmp|($\`var\`; separator = ', '$)|] === \"(0, 1, 2)\"@ ----------------------------------------------------------------------------- module Text.StringTemplate.QQ (stmp) where -import Data.Generics import qualified Language.Haskell.TH as TH import Language.Haskell.TH.Quote import Text.StringTemplate.Base-import Text.ParserCombinators.Parsec import Control.Monad.Writer-import Control.Applicative quoteTmplExp :: String -> TH.ExpQ quoteTmplPat :: String -> TH.PatQ +stmp :: QuasiQuoter stmp = QuasiQuoter quoteTmplExp quoteTmplPat quoteTmplPat = error "Cannot apply stmp quasiquoter in patterns"@@ -34,7 +32,7 @@ where vars = case parseSTMPNames s of Right xs -> xs- Left err -> error (show err)+ Left err -> error $ show err base = TH.AppE (TH.VarE (TH.mkName "newSTMP")) (TH.LitE (TH.StringL $ s)) tmpl = foldr addAttrib base vars addAttrib var x = TH.AppE