[commit: haddock] v2.17: Change Hyperlinked lexer to know about DataKinds ticks (aa6ac68)

git at git.haskell.org git at git.haskell.org
Mon Nov 20 21:06:25 UTC 2017


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

On branch  : v2.17
Link       : http://git.haskell.org/haddock.git/commitdiff/aa6ac688daa520a4e4166473069d976f5220f75a

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

commit aa6ac688daa520a4e4166473069d976f5220f75a
Author: Oleg Grenrus <oleg.grenrus at iki.fi>
Date:   Tue May 24 16:53:35 2016 +0300

    Change Hyperlinked lexer to know about DataKinds ticks


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

aa6ac688daa520a4e4166473069d976f5220f75a
 haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs | 12 +++++++++++-
 haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs  |  3 +++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
index e206413..e434560 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -31,12 +31,20 @@ chunk str@(c:_)
 chunk str
     | "--" `isPrefixOf` str = chunk' $ spanToNewline str
     | "{-" `isPrefixOf` str = chunk' $ chunkComment 0 str
-    | otherwise = case lex str of
+    | otherwise = case lex' str of
         (tok:_) -> chunk' tok
         [] -> [str]
   where
     chunk' (c, rest) = c:(chunk rest)
 
+-- | A bit better lexer then the default, i.e. handles DataKinds quotes
+lex' :: ReadS String
+lex' ('\'' : '\'' : rest)              = [("''", rest)]
+lex' str@('\'' : '\\' : _ : '\'' : _)  = lex str
+lex' str@('\'' : _ : '\'' : _)         = lex str
+lex' ('\'' : rest)                     = [("'", rest)]
+lex' str                               = lex str
+
 -- | Split input to "first line" string and the rest of it.
 --
 -- Ideally, this should be done simply with @'break' (== '\n')@. However,
@@ -124,6 +132,8 @@ classify str
     | "--" `isPrefixOf` str = TkComment
     | "{-#" `isPrefixOf` str = TkPragma
     | "{-" `isPrefixOf` str = TkComment
+classify "''" = TkSpecial
+classify "'"  = TkSpecial
 classify str@(c:_)
     | isSpace c = TkSpace
     | isDigit c = TkNumber
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs
index 5f4dbc8..b27ec4d 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs
@@ -12,16 +12,19 @@ data Token = Token
     , tkValue :: String
     , tkSpan :: Span
     }
+    deriving (Show)
 
 data Position = Position
     { posRow :: !Int
     , posCol :: !Int
     }
+    deriving (Show)
 
 data Span = Span
     { spStart :: Position
     , spEnd :: Position
     }
+    deriving (Show)
 
 data TokenType
     = TkIdentifier



More information about the ghc-commits mailing list