interpolatedstring-qq2: QuasiQuoter for multi-line interpolated strings

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), bytestring (>=0.10.8.2 && <0.11), haskell-src-meta (>=0.8.0.3 && <0.9), template-haskell (>=2.14.0.0 && <2.15), text (>=1.2.3.1 && <1.3) [details]
License BSD-3-Clause
Copyright 2019 Sandy Maguire
Author Sandy Maguire
Maintainer sandy@sandymaguire.me
Category Data
Home page https://github.com/isovector/interpolatedstring-qq2#readme
Bug tracker https://github.com/isovector/interpolatedstring-qq2/issues
Source repo head: git clone https://github.com/isovector/interpolatedstring-qq2
Uploaded by isovector at 2019-05-06T18:21:54Z
Distributions
Downloads 640 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-05-06 [all 1 reports]

Readme for interpolatedstring-qq2-0.1.0.0

[back to package description]

Text.InterpolatedString.QQ2

Build Status Hackage

QuasiQuoter for QQ2-style multi-line interpolated strings with "q", "qq" and "qc" support.

Description

QuasiQuoter for interpolated strings using Perl 6 syntax.

The q form does one thing and does it well: It contains a multi-line string with no interpolation at all:

{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules #-}
import Text.InterpolatedString.QQ2 (q)
foo :: String -- Text, ByteString etc also works
foo = [q|

Well here is a
    multi-line string!

|]

Any instance of the IsString class is permitted.

The qc form interpolates curly braces: expressions inside #{} will be directly interpolated if it's a Char, String, Text or ByteString, or it will have show called if it is not.

Escaping of '{' is done with backslash.

For interpolating numeric expressions without an explicit type signature, use the ExtendedDefaultRules lanuage pragma, as shown below:

{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules #-}
import Text.InterpolatedString.QQ2 (qc)
bar :: String
bar = [qc| Well #{"hello" ++ " there"} #{6 * 7} |]

bar will have the value " Well hello there 42 ".

If you want control over how show works on your types, define a custom ShowQ instance:

For example, this instance allows you to display interpolated lists of strings as a sequence of words, removing those pesky brackets, quotes, and escape sequences.

{-# LANGUAGE FlexibleInstances #-}
import Text.InterpolatedString.QQ2 (qc, ShowQ(..))
instance ShowQ [String] where
    showQ = unwords

qc permits output to any types with both IsString and Monoid instances.

{-# LANGUAGE QuasiQuotes, OverloadedStrings #-}
import Text.InterpolatedString.QQ2 (qc)
import Data.Text (Text)
import Data.ByteString.Char8 (ByteString)
qux :: ByteString
qux = [qc| This will convert #{"Text" :: Text} to #{"ByteString" :: ByteString} |]