File: MultilineTh.hs

package info (click to toggle)
haskell-prettyprinter 1.7.1-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: haskell: 2,453; ansic: 16; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 652 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module MultilineTh (multiline) where



import qualified Data.Text                  as T
import           Language.Haskell.TH
import           Language.Haskell.TH.Quote
import           Language.Haskell.TH.Syntax
import           Prelude



multiline :: QuasiQuoter
multiline = QuasiQuoter
    { quoteExp = quoteUnlines
    , quotePat = const badUse
    , quoteType = const badUse
    , quoteDec = const badUse
    }
  where
    badUse = fail "multiline quasiquoter can only be used as an expression"

quoteUnlines :: String -> Q Exp
quoteUnlines =
      liftString
    . T.unpack
    . T.unwords
    . filter (not . T.null)
    . T.words
    . T.pack