aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Parse.y
diff options
context:
space:
mode:
authorDavid Waern <david.waern@gmail.com>2012-07-23 16:50:40 +0200
committerDavid Waern <david.waern@gmail.com>2012-07-23 16:50:40 +0200
commitc3811c56988ecae6c3d3b2c4c202474de012e9ed (patch)
treec7d897e98c3523d056d38745b794c681b30a38f6 /src/Haddock/Parse.y
parent83a2a6ab67b25eec42c50b99b0b594313b8abe44 (diff)
parent0730c1b4088fd5d2c36671b0adf3c9e11222e233 (diff)
Merge branch 'dev' of https://github.com/sol/haddock into ghc-7.6
Conflicts: src/Haddock/InterfaceFile.hs
Diffstat (limited to 'src/Haddock/Parse.y')
-rw-r--r--src/Haddock/Parse.y13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Haddock/Parse.y b/src/Haddock/Parse.y
index e36e8416..b34b14b9 100644
--- a/src/Haddock/Parse.y
+++ b/src/Haddock/Parse.y
@@ -10,7 +10,7 @@
module Haddock.Parse where
import Haddock.Lex
-import Haddock.Types (Doc(..), Example(Example))
+import Haddock.Types (Doc(..), Example(Example), Hyperlink(..))
import Haddock.Doc
import HsSyn
import RdrName
@@ -107,7 +107,7 @@ seq1 :: { Doc RdrName }
elem1 :: { Doc RdrName }
: STRING { DocString $1 }
| '/../' { DocEmphasis (DocString $1) }
- | URL { DocURL $1 }
+ | URL { DocHyperlink (makeHyperlink $1) }
| PIC { DocPic $1 }
| ANAME { DocAName $1 }
| IDENT { DocIdentifier $1 }
@@ -121,6 +121,15 @@ strings :: { String }
happyError :: [LToken] -> Maybe a
happyError toks = Nothing
+-- | Create a `Hyperlink` from given string.
+--
+-- A hyperlink consists of a URL and an optional label. The label is separated
+-- from the url by one or more whitespace characters.
+makeHyperlink :: String -> Hyperlink
+makeHyperlink input = case break isSpace $ strip input of
+ (url, "") -> Hyperlink url Nothing
+ (url, label) -> Hyperlink url (Just . dropWhile isSpace $ label)
+
-- | Create an 'Example', stripping superfluous characters as appropriate
makeExample :: String -> String -> [String] -> Example
makeExample prompt expression result =