packages feed

interpol 0.2.0 → 0.2.1

raw patch · 9 files changed

+84/−16 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.Interpol: instance [overlap ok] Interpol [Char]
+ Text.Interpol: instance [overlap ok] Show a => Interpol a
- Text.Interpol: (^-^) :: (Typeable a, Show a) => String -> a -> String
+ Text.Interpol: (^-^) :: Interpol a => String -> a -> String

Files

Main.hs view
@@ -3,6 +3,7 @@     ) where  import Data.Generics ( mkT, everywhere )+import Data.List ( isPrefixOf, tails ) import Language.Haskell.Exts ( prettyPrint                              , ParseResult(..), parseFileWithExts                              , Module(..), Exp(..), QOp(..)@@ -25,8 +26,14 @@              writeFile fout $ magicLine ++ prettyPrint (transform m)  transform :: Module -> Module-transform = addDecl . everywhere (mkT trans)+transform = addNecessaryDecls . everywhere (mkT trans)     where+      addNecessaryDecls m+          | strstr "^-^" (prettyPrint m) = addDecl m+          | otherwise                    = m++      strstr w = any id . map (isPrefixOf w) . tails+       addDecl :: Module -> Module       addDecl (Module sl mn mps mwt mes ids ds) =           let ids' = (ImportDecl{ importLoc = SrcLoc { srcFilename = ""
Makefile view
@@ -1,5 +1,6 @@-TESTS1 := Simple One String-TESTS2 := Standalone Pure+TESTS1 := Simple One String NoImport+TESTS2 := Standalone Pure PureString NoWarn JustShow+GHC := ghc -Wall -Werror  .PHONY: all build dist install clean clean-tests test doc @@ -27,8 +28,8 @@ endef  test: install clean-tests-	$(foreach t,$(TESTS1),cd Test && ghc -F -pgmF interpol $(t)${\n})-	$(foreach t,$(TESTS2),cd Test && ghc $(t)${\n})+	$(foreach t,$(TESTS1),cd Test && $(GHC) -F -pgmF interpol $(t)${\n})+	$(foreach t,$(TESTS2),cd Test && $(GHC) $(t)${\n}) 	$(foreach t,$(TESTS1) $(TESTS2),cd Test && [ "`./$(t)`" = "I have 23 apples." ]${\n})  dist/setup-config: interpol.cabal
README.md view
@@ -51,6 +51,10 @@      {-# OPTIONS_GHC -F -pgmF interpol #-} +Note that, unless you use this latter pragma,+[ghc-mod](http://www.mew.org/~kazu/proj/ghc-mod/en/) and other+`flymake`-based Emacs modes will probably complain about unused+variables.  Operation ---------
+ Test/JustShow.hs view
@@ -0,0 +1,15 @@+-- | This checks that a Show instance is enough to interpolate custom+-- data types.++import Text.Interpol++data Foo = Foo Int++instance Show Foo where+    show (Foo n) = show n++myVar :: Foo+myVar = Foo 23++main :: IO ()+main = putStrLn $ "I have " ^-^ myVar ^-^ " apples."
+ Test/NoImport.hs view
@@ -0,0 +1,7 @@+module Main where++val :: Int+val = 23++main :: IO ()+main = putStrLn "I have {val} apples."
+ Test/NoWarn.hs view
@@ -0,0 +1,13 @@+{-# OPTIONS_GHC -F -pgmF interpol #-}++-- | The idea here is to check that @foo n@ will not result in an+-- "unused variable" warning.  Of course, it doesn't really work+-- unless you open the file in Emacs or something.++module Main where++main :: IO ()+main = foo 23++foo :: Int -> IO ()+foo n = putStrLn "I have {n} apples."
+ Test/PureString.hs view
@@ -0,0 +1,9 @@+-- | This checks that 'String's do not get unnecessarily quoted.++import Text.Interpol++myVar :: String+myVar = "23"++main :: IO ()+main = putStrLn $ "I have " ^-^ myVar ^-^ " apples."
Text/Interpol.hs view
@@ -1,10 +1,10 @@+{-# LANGUAGE FlexibleInstances, UndecidableInstances, OverlappingInstances #-}+ -- | Support module for the @interpol@ preprocessor. module Text.Interpol (         (^-^)     ) where -import Data.Typeable ( Typeable, cast )- infixl 3 ^-^  -- | Append a showable value to a 'String' in a smart way.  In@@ -16,7 +16,14 @@ --   x ^-^ y = x ++ y --   x ^-^ y = x ++ show y -- @-(^-^) :: (Typeable a, Show a) => String -> a -> String-s ^-^ st = case cast st of-             Just s' -> s ++ s'-             Nothing -> s ++ show st+(^-^) :: Interpol a => String -> a -> String+(^-^) = interpol++class Interpol a where+    interpol :: String -> a -> String++instance Interpol [Char] where+    interpol s x = s ++ x++instance Show a => Interpol a where+    interpol s x = s ++ show x
interpol.cabal view
@@ -1,5 +1,5 @@ Name:           interpol-Version:        0.2.0+Version:        0.2.1 Cabal-Version:  >= 1.6 License:        GPL-3 License-File:   LICENSE@@ -13,20 +13,25 @@ Description:    This preprocessor enables variable interpolation in strings.                 See the README.md file for details. -Extra-source-files:     Test/Simple.hs,+Extra-source-files:     Makefile,+                        Test/JustShow.hs,+                        Test/NoImport.hs,+                        Test/NoWarn.hs,                         Test/One.hs,-                        Test/Standalone.hs,                         Test/Pure.hs,+                        Test/PureString.hs,+                        Test/Simple.hs,+                        Test/Standalone.hs,                         Test/String.hs -Data-files:             Makefile, README.md+Data-files:             README.md  Source-repository head   Type:                 git   Location:             git://github.com/scvalex/interpol.git  Executable interpol-  Build-Depends:        base >=4 && <5, syb, haskell-src-exts, regex-posix+  Build-Depends:        base >= 4 && <5, syb, haskell-src-exts, regex-posix   Main-Is:              Main.hs  Library