summaryrefslogtreecommitdiff
path: root/src/Language
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-09-22 08:50:20 +0200
committerEugen Wissner <belka@caraus.de>2021-09-22 08:50:20 +0200
commiteedab9e74250a4af56aec70c2909ece95a73daaa (patch)
tree5eb112e9b70e3f6fb22328069c40e8004372c4a2 /src/Language
parenta3f18932bd00661f7ecd2da724461d99a2d540ae (diff)
downloadgraphql-eedab9e74250a4af56aec70c2909ece95a73daaa.tar.gz
Don't append a trailing newline in gql
Diffstat (limited to 'src/Language')
-rw-r--r--src/Language/GraphQL/TH.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Language/GraphQL/TH.hs b/src/Language/GraphQL/TH.hs
index 02dd7d6..b6bc18c 100644
--- a/src/Language/GraphQL/TH.hs
+++ b/src/Language/GraphQL/TH.hs
@@ -11,18 +11,21 @@ import Language.Haskell.TH.Quote (QuasiQuoter(..))
import Language.Haskell.TH (Exp(..), Lit(..))
stripIndentation :: String -> String
-stripIndentation code = unlines
- $ reverse
- $ dropWhile null
+stripIndentation code = reverse
+ $ dropNewlines
$ reverse
+ $ unlines
$ indent spaces <$> lines withoutLeadingNewlines
where
indent 0 xs = xs
indent count (' ' : xs) = indent (count - 1) xs
indent _ xs = xs
- withoutLeadingNewlines = dropWhile (== '\n') code
+ withoutLeadingNewlines = dropNewlines code
+ dropNewlines = dropWhile (== '\n')
spaces = length $ takeWhile (== ' ') withoutLeadingNewlines
+-- | Removes leading and trailing newlines. Indentation of the first line is
+-- removed from each line of the string.
gql :: QuasiQuoter
gql = QuasiQuoter
{ quoteExp = pure . LitE . StringL . stripIndentation