git.iko.soy/typeable/postgresql-simple
on 602c954 help sign in
30 lines 1.0 kB history raw
1{-# LANGUAGE TemplateHaskell #-}
3module StringsQQ (strings, longstring) where
5import Language.Haskell.TH
6import Language.Haskell.TH.Quote
8import Data.Char (toUpper)
10strings = QuasiQuoter { quotePat = undefined,
11 quoteType = undefined,
12 quoteExp = stringsExp,
13 quoteDec = undefined }
15-- stringE = return . LitE . StringL
17stringsExp :: String -> Q Exp
18stringsExp = foldr (\x xs -> [e| $(x) : $(xs) |]) [e| [] |]
19 . map delta . filter (not . null) . map words . lines
20 where delta [(x:xs)] = [e| ( $(stringE $ x:xs )
21 , $(stringE $ toUpper x : xs ) ) |]
22 delta [xs,ys] = [e| ( $(stringE xs) , $(stringE ys) ) |]
24longstring = QuasiQuoter { quotePat = undefined,
25 quoteType = undefined,
26 quoteExp = longstringExp,
27 quoteDec = undefined }
29longstringExp ('\n':xs) = stringE xs
30longstringExp xs = stringE xs