[commit: haddock] master: Implement simple string chunking based on HsColour library. (413f7f3)

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


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

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

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

commit 413f7f322cd174e2ba4116dbf53c1b3c0d6a4f77
Author: Łukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date:   Thu Jun 4 21:10:26 2015 +0200

    Implement simple string chunking based on HsColour library.


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

413f7f322cd174e2ba4116dbf53c1b3c0d6a4f77
 .../src/Haddock/Backends/Hyperlinker/Parser.hs     | 28 +++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
index 4bcc0c8..4e0d738 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -1,5 +1,8 @@
 module Haddock.Backends.Hyperlinker.Parser (parse) where
 
+import Data.Char
+import Data.List
+
 data Token = Token
     { tkType :: TokenType
     , tkValue :: String
@@ -27,7 +30,30 @@ parse :: String -> [Token]
 parse = tokenize . tag . chunk
 
 chunk :: String -> [String]
-chunk = undefined
+chunk [] = []
+chunk str@(c:_)
+    | isSpace c = chunk' $ span isSpace str
+chunk str
+    | "--" `isPrefixOf` str = chunk' $ span (not . (== '\n')) str
+    | "{-" `isPrefixOf` str = chunk' $ chunkComment 0 str
+    | otherwise = chunk' $ head $ lex str
+
+chunk' :: (String, String) -> [String]
+chunk' (c, rest) = c:(chunk rest)
+
+chunkComment :: Int -> String -> (String, String)
+chunkComment _ [] = ("", "")
+chunkComment depth ('{':'-':str) =
+    let (c, rest) = chunkComment (depth + 1) str
+    in ("{-" ++ c, rest)
+chunkComment depth ('-':'}':str)
+    | depth == 1 = ("-}", str)
+    | otherwise =
+        let (c, rest) = chunkComment (depth - 1) str
+        in ("-}" ++ c, rest)
+chunkComment depth (e:str) =
+    let (c, rest) = chunkComment depth str
+    in (e:c, rest)
 
 tag :: [String] -> [(Span, String)]
 tag =



More information about the ghc-commits mailing list