command-qq-0.3.0.0: Quasiquoters for external commands

Safe HaskellNone

System.Command.QQ

Contents

Description

Quasiquoters for external commands

Synopsis

Quasiquoters

Default shell

sh_ :: QuasiQuoterSource

Simple quasiquoter for the default shell

sh analog that always constructs an action of type IO () and so can always be used without type annotations

>>> [sh_|echo "hello, world!"|]
hello, world!

sh :: QuasiQuoterSource

Quasiquoter for the default shell

Constructs polymorphic action of type Eval a => a from passed string.

Uses SHELL environment variable as path to shell executable or /bin/sh if it is unset.

>>> [sh|echo "hello, world!"|] :: IO ExitCode
ExitSuccess
>>> [sh|echo "hello, world!"|] :: IO Text
"hello, world!\n"

Haskell values can be embedded with Ruby-like syntax:

>>> let apples = 7
>>> [sh|echo "#{apples} apples!"|] :: IO Text
"7 apples!\n"

Constructors

shell :: FilePath -> QuasiQuoterSource

Shell's quasiquoter constructor

"Shell" here means executable that has the following API:

 <SHELL> -c <COMMAND>

e.g. sh, bash, zsh, ksh, tcsh, python, etc

interpreter :: FilePath -> QuasiQuoterSource

Interpreter's quasiquoter constructor

"Interpreter" here means executable that has the following API:

 <INTERPRETER> -e <COMMAND>

e.g. perl, ruby, ghc, etc

Customizations

quoter :: (String -> Q Exp) -> QuasiQuoterSource

Construct quasiquoter from function taking the string and producing Haskell expression.

Other kinds of quasiquoters (patterns, types or declarations quasiquoters) will fail at compile time

callCommandSource

Arguments

:: FilePath

Command path

-> [String]

Arguments that go to command before quasiquoter contents

-> String

Quasiquoter contents

-> Q Exp 

Construct Haskell expression for external command call

substituteVars :: String -> Q ExpSource

Construct Haskell expression from the string, substituting variables for their values. Variable expansion uses a ruby-like syntax