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

Parser.example, property: support multi-line syntax #1619

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 17 additions & 2 deletions haddock-library/src/Documentation/Haddock/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ examples = DocExamples <$> (many (try (skipHorizontalSpace *> "\n")) *> go)
go :: Parser [Example]
go = do
prefix <- takeHorizontalSpace <* ">>>"
expr <- takeLine
expr <- takeLineOrMultiLine
(rs, es) <- resultAndMoreExamples
return (makeExample prefix expr rs : es)
where
Expand Down Expand Up @@ -765,12 +765,27 @@ takeLine = try (takeWhile (/= '\n') <* endOfLine)
endOfLine :: Parser ()
endOfLine = void "\n" <|> Parsec.eof


actualLine :: Parser Text
actualLine = takeWhile (/= '\n') <* void "\n"

takeMultiLine :: Parser Text
takeMultiLine =
T.unlines <$>
(try ":{" *>
Parsec.manyTill actualLine (try $ skipHorizontalSpace *> ":}\n"))

takeLineOrMultiLine :: Parser Text
takeLineOrMultiLine =
liftA2 (<>) takeHorizontalSpace $ takeMultiLine <|> takeLine

-- | Property parser.
--
-- >>> snd <$> parseOnly property "prop> hello world"
-- Right (DocProperty "hello world")
property :: Parser (DocH mod a)
property = DocProperty . T.unpack . T.strip <$> ("prop>" *> takeWhile1 (/= '\n'))
property =
DocProperty . T.unpack . T.strip <$> ("prop>" *> takeLineOrMultiLine)

-- |
-- Paragraph level codeblock. Anything between the two delimiting \@ is parsed
Expand Down
Loading