Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Allow more characters in anchor following module reference #1220

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions haddock-library/src/Documentation/Haddock/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '_'

Expand Down
3 changes: 3 additions & 0 deletions haddock-library/test/Documentation/Haddock/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down