[commit: haddock] master: Implement function for tagging parsed chunks with source spans. (e17f625)

git at git.haskell.org git at git.haskell.org
Wed Jul 8 08:39:52 UTC 2015


Repository : ssh://git@git.haskell.org/haddock

On branch  : master
Link       : http://git.haskell.org/haddock.git/commitdiff/e17f62506ecf20d61781c610d6fbb5f3c8cd132e

>---------------------------------------------------------------

commit e17f62506ecf20d61781c610d6fbb5f3c8cd132e
Author: Łukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date:   Thu Jun 4 19:59:27 2015 +0200

    Implement function for tagging parsed chunks with source spans.


>---------------------------------------------------------------

e17f62506ecf20d61781c610d6fbb5f3c8cd132e
 haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
index 11a92b5..4bcc0c8 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -30,7 +30,14 @@ chunk :: String -> [String]
 chunk = undefined
 
 tag :: [String] -> [(Span, String)]
-tag = undefined
+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)
 
 tokenize :: [(Span, String)] -> [Token]
 tokenize = undefined



More information about the ghc-commits mailing list