aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs10
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs3
2 files changed, 11 insertions, 2 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index 149ff93d..bd01f354 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -242,12 +242,18 @@ monospace = DocMonospaced . parseParagraph
-- Note that we allow '#' and '\' to support anchors (old style anchors are of
-- the form "SomeModule\#anchor").
moduleName :: Parser (DocH mod a)
-moduleName = DocModule <$> ("\"" *> modid <* "\"")
+moduleName = DocModule <$> ("\"" *> (modid `maybeFollowedBy` anchor_) <* "\"")
where
modid = intercalate "." <$> conid `Parsec.sepBy1` "."
+ anchor_ = (++)
+ <$> (Parsec.string "#" <|> Parsec.string "\\#")
+ <*> many (Parsec.satisfy (\c -> c /= '"' && not (isSpace c)))
+
+ maybeFollowedBy pre suf = (\x -> maybe x (x ++)) <$> pre <*> optional suf
+
conid = (:)
<$> Parsec.satisfy (\c -> isAlpha c && isUpper c)
- <*> many (conChar <|> Parsec.oneOf "\\#")
+ <*> many conChar
conChar = Parsec.alphaNum <|> Parsec.char '_'
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index 8b59b560..9bf9b6ea 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -431,6 +431,9 @@ spec = do
it "accepts anchor reference syntax as DocModule" $ do
"\"Foo#bar\"" `shouldParseTo` DocModule "Foo#bar"
+ it "accepts anchor with hyphen as DocModule" $ do
+ "\"Foo#bar-baz\"" `shouldParseTo` DocModule "Foo\\#bar-baz"
+
it "accepts old anchor reference syntax as DocModule" $ do
"\"Foo\\#bar\"" `shouldParseTo` DocModule "Foo\\#bar"