packages feed

command-qq 0.2.0.0 → 0.2.1.0

raw patch · 8 files changed

+115/−92 lines, 8 files

Files

CHANGELOG.md view
@@ -1,7 +1,17 @@+0.2.1.0+=======++  * Add a bunch of predefined quasiquoters to `System.Command.QQ.Predef`++  * Add `Embed` instances for `Data.Text.Text` and `Data.Text.Lazy.Text`+ 0.2.0.0 =======    * Added `sh_` quasiquoter to avoid type annotations for trivial quotes+   * Moved `Eval` onto `Text` to speed I/O up.+   * Quasiquoters support literals and constructors with no arguments+   * More `Embed` instances
README.md view
@@ -1,6 +1,6 @@ # command-qq-[![Hackage](https://budueba.com/hackage/command-qq)](http://hackage.haskell.org/package/command-qq)-[![Build Status](https://secure.travis-ci.org/biegunka/command-qq.png?branch=master)](http://travis-ci.org/biegunka/command-qq)+[![Hackage](https://budueba.com/hackage/command-qq)](https://hackage.haskell.org/package/command-qq)+[![Build Status](https://secure.travis-ci.org/biegunka/command-qq.png?branch=master)](https://travis-ci.org/biegunka/command-qq) [![Build Status](https://drone.io/github.com/biegunka/command-qq/status.png)](https://drone.io/github.com/biegunka/command-qq/latest)  ```@@ -44,7 +44,7 @@ hello world! ``` -For more examples, see [`examples/CustomQQ.hs`][0]+For more examples, see [`System.Command.QQ.Predef`][0]  ### Haskell values embedding @@ -73,5 +73,5 @@  See [`examples/CommandT.hs`][1] -  [0]: https://github.com/biegunka/command-qq/blob/master/examples/CustomQQ.hs+  [0]: https://github.com/biegunka/command-qq/blob/master/src/System/Command/QQ/Predef.hs   [1]: https://github.com/biegunka/command-qq/blob/master/examples/CommandT.hs
command-qq.cabal view
@@ -1,5 +1,5 @@ name:                command-qq-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Quasiquoters for external commands description:   Features:@@ -18,7 +18,7 @@     > >>> [ghci| putStrLn "hello world!" |] :: IO ()     > hello world!   .-    For more examples, see @examples/CustomQQ.hs@+    For more examples, see "System.Command.QQ.Predef"   .   * Haskell values embedding   .@@ -40,9 +40,16 @@   CHANGELOG.md   README.md   examples/CommandT.hs-  examples/CustomQQ.hs +source-repository head+  type:              git+  location:          https://github.com/biegunka/command-qq +source-repository this+  type:              git+  location:          https://github.com/biegunka/command-qq+  tag:               0.2.1.0+ library   default-language:  Haskell2010   build-depends:@@ -55,6 +62,7 @@     System.Command.QQ     System.Command.QQ.Embed     System.Command.QQ.Eval+    System.Command.QQ.Predef  test-suite doctests   default-language:  Haskell2010@@ -81,8 +89,3 @@   other-modules:     System.Command.QQ.EmbedSpec     System.Command.QQ.EvalSpec---source-repository head-  type:              git-  location:          https://github.com/biegunka/command-qq
− examples/CustomQQ.hs
@@ -1,51 +0,0 @@--- | Custom quasiquoters built on top of command-qq-module CustomQQ-  ( sh, bash, zsh-  , python, perl, ruby, ghci-  ) where--import           Language.Haskell.TH.Quote -- template-haskell-import qualified System.Command.QQ as QQ   -- command-qq---- $setup--- >>> :set -XQuasiQuotes---- | Some shell quasiquoters------ >>> [sh|echo "`basename $0`"|] :: IO ()--- sh------ >>> [bash|echo "$(basename $0)"|] :: IO ()--- bash------ >>> [zsh|echo "$(basename $0)"|] :: IO ()--- zsh-sh, bash, zsh :: QuasiQuoter-sh   = QQ.shell "sh"-bash = QQ.shell "bash"-zsh  = QQ.shell "zsh"---- | Some interpreters quasiquoters------ >>> let foo = 11------ >>> [python|foo = 11; print foo == #{foo}|] :: IO ()--- True------ >>> [perl|my $foo = 11; print $foo == #{foo}|] :: IO ()--- 1------ >>> [ruby|foo = 11; puts foo == #{foo}|] :: IO ()--- true-python, perl, ruby :: QuasiQuoter-python = QQ.shell "python" -- For whatever reason python uses @python -c <command>@ syntax-perl   = QQ.interpreter "perl"-ruby   = QQ.interpreter "ruby"---- | More involved interpreter quasiquoter------ >>> let foo = 11--- >>> [ghci|let foo = 11 in print $ foo == #{foo}|] :: IO ()--- True-ghci :: QuasiQuoter-ghci = QQ.quoter $ QQ.callCommand "ghc" ["-ignore-dot-ghci", "-e"]
src/System/Command/QQ/Embed.hs view
@@ -6,11 +6,13 @@   ( Embed(..)   ) where -import Control.Applicative-import Data.Int-import Data.Ratio (Ratio)-import Data.Word-import Foreign.C.Types+import           Control.Applicative+import           Data.Int+import           Data.Ratio (Ratio)+import qualified Data.Text as Text+import qualified Data.Text.Lazy as Text.Lazy+import           Data.Word+import           Foreign.C.Types  -- $setup -- >>> import Data.Ratio@@ -72,7 +74,19 @@   embed = pure  -- |--- >>> embed "hi"+-- >>> embed ("hi" :: String) -- "hi" instance Embed String where   embed = id++-- |+-- >>> embed ("hi" :: Text.Text)+-- "hi"+instance Embed Text.Text where+  embed = Text.unpack++-- |+-- >>> embed ("hi" :: Text.Lazy.Text)+-- "hi"+instance Embed Text.Lazy.Text where+  embed = Text.Lazy.unpack
src/System/Command/QQ/Eval.hs view
@@ -26,8 +26,10 @@ class Eval r where   eval :: String -> [String] -> r --- | Most basic instance: nothing is known about what happened in external command+-- | The most basic instance: nothing is known about what happened in external command --+-- External command's stdout and stderr go to caller's stdout and stderr respectively+-- -- >>> [sh|echo hello world|] :: IO () -- hello world instance Eval (IO ()) where@@ -89,30 +91,29 @@  readProcessWithExitCode :: String -> [String] -> Text -> IO (ExitCode, Text, Text) readProcessWithExitCode cmd args input = do-    (Just ih, Just oh, Just eh, p) <--        P.createProcess (P.proc cmd args)-          { P.std_in  = P.CreatePipe-          , P.std_out = P.CreatePipe-          , P.std_err = P.CreatePipe-          }+  (Just inh, Just outh, Just errh, p) <-+      P.createProcess (P.proc cmd args)+        { P.std_in  = P.CreatePipe+        , P.std_out = P.CreatePipe+        , P.std_err = P.CreatePipe+        } -    m <- newEmptyMVar-    o <- T.hGetContents oh-    e <- T.hGetContents eh+  var <- newEmptyMVar+  out <- T.hGetContents outh+  err <- T.hGetContents errh -    forkFinally (evaluate (T.length o)) (\_ -> putMVar m ())-    forkFinally (evaluate (T.length e)) (\_ -> putMVar m ())+  forkFinally (evaluate (T.length out)) (\_ -> putMVar var ())+  forkFinally (evaluate (T.length err)) (\_ -> putMVar var ()) -    unless (T.null input) $ do-      T.hPutStr ih input-      hFlush ih-    hClose ih+  unless (T.null input) $+    T.hPutStr inh input >> hFlush inh+  hClose inh -    takeMVar m-    takeMVar m-    hClose oh-    hClose eh+  takeMVar var+  takeMVar var+  hClose outh+  hClose errh -    s <- P.waitForProcess p+  s <- P.waitForProcess p -    return (s, o, e)+  return (s, out, err)
+ src/System/Command/QQ/Predef.hs view
@@ -0,0 +1,46 @@+-- | Some predefined quasiquoters+module System.Command.QQ.Predef where++import Language.Haskell.TH.Quote (QuasiQuoter)++import System.Command.QQ (interpreter, shell, quoter, callCommand)++-- | @bash@ shell+bash :: QuasiQuoter+bash = shell "bash"++-- | @zsh@ shell+zsh :: QuasiQuoter+zsh = shell "zsh"++-- | @awk@ interpreter+awk :: QuasiQuoter+awk = quoter $ callCommand "awk" []+++-- | @ghci@ interpreter+ghci :: QuasiQuoter+ghci =+  quoter $ callCommand "ghc" ["-ignore-dot-ghci", "-e"]+++-- | @perl@ interpreter+perl :: QuasiQuoter+perl = interpreter "perl"++-- | @ruby@ interpreter+ruby :: QuasiQuoter+ruby = interpreter "ruby"+++-- | @python@ interpreter+python :: QuasiQuoter+python = shell "python"++-- | @python2@ interpreter+python2 :: QuasiQuoter+python2 = shell "python2"++-- | @python3@ interpreter+python3 :: QuasiQuoter+python3 = shell "python3"
tests/Doctests.hs view
@@ -8,6 +8,6 @@   [ "src/System/Command/QQ.hs"   , "src/System/Command/QQ/Embed.hs"   , "src/System/Command/QQ/Eval.hs"-  , "examples/CustomQQ.hs"+  , "src/System/Command/QQ/Predef.hs"   , "examples/CommandT.hs"   ]