aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2018-05-07 18:53:15 -0700
committerSimon Jakobi <simon.jakobi@gmail.com>2018-06-13 23:39:30 +0200
commit52405584f978c8d1afd6439b3ac0e3fd0f9b825e (patch)
tree98fe59480fe1cbe410423af6416ed31a37298844 /haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
parent524566646723ced878d49c903358e7b5f25442b9 (diff)
Filter out CRLFs in hyperlinker backend (#813)
This prevents spurious lines from appearing in the final output.
Diffstat (limited to 'haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs')
-rw-r--r--haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
index 8f77b8f5..92443bff 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -24,8 +24,13 @@ import Haddock.Backends.Hyperlinker.Types as T
-- (In reality, this only holds for input not containing '\r', '\t', '\f', '\v',
-- characters, since GHC transforms those into ' ' and '\n')
parse :: DynFlags -> FilePath -> String -> [T.Token]
-parse dflags fp s = ghcToks (processCPP dflags fp s)
-
+parse dflags fp = ghcToks . processCPP dflags fp . filterCRLF
+ where
+ -- Remove CRLFs from source
+ filterCRLF :: String -> String
+ filterCRLF ('\r':'\n':cs) = '\n' : filterCRLF cs
+ filterCRLF (c:cs) = c : filterCRLF cs
+ filterCRLF [] = []
-- | Parse the source into tokens using the GHC lexer.
--