diff options
| author | Eugen Wissner <belka@caraus.de> | 2021-09-22 08:50:20 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2021-09-22 08:50:20 +0200 |
| commit | eedab9e74250a4af56aec70c2909ece95a73daaa (patch) | |
| tree | 5eb112e9b70e3f6fb22328069c40e8004372c4a2 /src | |
| parent | a3f18932bd00661f7ecd2da724461d99a2d540ae (diff) | |
| download | graphql-eedab9e74250a4af56aec70c2909ece95a73daaa.tar.gz | |
Don't append a trailing newline in gql
Diffstat (limited to 'src')
| -rw-r--r-- | src/Language/GraphQL/TH.hs | 11 |
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 |
