diff options
Diffstat (limited to 'src/Language')
| -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 |
