aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
diff options
context:
space:
mode:
authorŁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-06-05 00:07:52 +0200
committerŁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-06-30 22:37:48 +0200
commit57d4c9cff1d60f7dd0f8dafae5537218b63da90f (patch)
tree72763afb97e514052c66e6774c66df618aab83dc /haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
parent6fb8d5abbcc92f5155fdc9596ca1c87fe87f6187 (diff)
Adapt source span tagging to work with current whitespace handling.
Diffstat (limited to 'haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs')
-rw-r--r--haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
index be6b7ce5..53ff1f65 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -67,10 +67,13 @@ tag =
reverse . snd . foldl aux (Position 1 1, [])
where
aux (pos, cs) c =
- let pos' = if c == "\n"
- then pos { posRow = posRow pos + 1, posCol = 1 }
- else pos { posCol = posCol pos + length c }
- in (pos', (Span pos pos', c):cs)
+ let pos' = move pos c
+ in (pos', ((Span pos pos', c):cs))
+ move pos str@(c:_)
+ | isSpace c = foldl move' pos str
+ move pos str = pos { posCol = posCol pos + length str }
+ move' pos '\n' = pos { posRow = posRow pos + 1, posCol = 1 }
+ move' pos _ = pos { posCol = posCol pos + 1 }
tokenize :: [(Span, String)] -> [Token]
tokenize =