File: QQ.hs

package info (click to toggle)
haskell-pandoc-types 1.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 248 kB
  • sloc: haskell: 2,293; makefile: 5
file content (19 lines) | stat: -rw-r--r-- 691 bytes parent folder | download
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