custom-interpolation-0.1.0.1: Customizable string interpolation quasiquoters
Safe HaskellSafe-Inferred
LanguageHaskell2010

CustomInterpolation

Description

This module reexports all the relevant tools of the custom-interpolation package.

Synopsis

Template Haskell

The main entry points of the library. Use these to build your template haskell functions and quasiquoters.

interpolateQQ :: InterpolationConfig a -> QuasiQuoter Source #

Create a new QuasiQuoter that interpolates strings as specified by the given InterpolationConfig.

interpolate :: InterpolationConfig a -> String -> Q Exp Source #

Interpolate a string as specified by the given InterpolationConfig.

Configuration

data InterpolationConfig a Source #

Rules for interpolating a string.

Constructors

InterpolationConfig 

Fields

Instances

Instances details
Default (InterpolationConfig a) Source #
def = defaultConfig
Instance details

Defined in CustomInterpolation.Config

simpleConfig :: InterpolationConfig () Source #

Type-restricted simple version of defaultConfig. Use this if you just want to substitute interpolated segments with a string expression.

defaultConfig :: InterpolationConfig a Source #

Default InterpolationConfig. Has no handlers, finalize ignores any extra values returned when interpolating and escape does nothing.

Interpolators

data Interpolator a Source #

Constructors

Interpolator 

Fields

  • prefix :: Prefix

    InterpolationConfig prefix, a prefix of e.g. "$" will lead to anything inside ${expr} being interpolated (assuming curlyBrackets).

  • handler :: Q Exp -> (a, Q Exp)

    Transforms the interpolated string segment into a string expression and some value of type a to accumulate.

  • brackets :: Brackets

    The brackets to use for the interpolation syntax.

Interpolator Helpers

Constructors for common Interpolators.

simpleInterpolator :: Interpolator () Source #

Default Interpolator. Inserts the interpolated expression as is and uses curlyBrackets with no prefix.

applyInterpolator :: Monoid a => Q Exp -> Interpolator a Source #

Create an Interpolator that applies a quoted function to the interpolated expression. Uses curlyBrackets and no prefix.

Example

Expand
>>> $(interpolate (simpleConfig {handlers = [applyInterpolator [|show . (^ 2)|]]}) "two squared equals {2}")
"two squared equals 4"

Brackets

data Brackets Source #

Constructors

Brackets 

Fields

Instances

Instances details
Show Brackets Source # 
Instance details

Defined in CustomInterpolation.Config