From eedab9e74250a4af56aec70c2909ece95a73daaa Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 22 Sep 2021 08:50:20 +0200 Subject: Don't append a trailing newline in gql --- src/Language/GraphQL/TH.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') 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 -- cgit v1.2.3