1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
-- | This module is based off the QQ implementation from string-qq
-- (https://github.com/audreyt/string-qq).
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE RankNTypes #-}
module Data.String.QQ (s) where
import Data.String (IsString(..))
import Language.Haskell.TH.Quote (QuasiQuoter(..))
s :: QuasiQuoter
s = QuasiQuoter expr pat typ dec
where
expr = (\a -> [|fromString a|]) . clean
pat = error "Cannot use s as a pattern"
typ = error "Cannot use s as a type"
dec = error "Cannot use s as a dec"
clean = removeCarriageReturns . trimLeadingNewline
removeCarriageReturns = filter (/= '\r')
trimLeadingNewline ('\n':xs) = xs
trimLeadingNewline xs = xs
|