Create a function to 'fallthrough parse' ie. try the second parser only

if the first one fails.
fixingIncompleteElements
Aadhavan Srinivasan 1 month ago
parent 83dd0024c4
commit 5fc1b1122a

@ -141,6 +141,12 @@ manyTillLazy p1 p2 = do
parseTillEol :: ReadP String
parseTillEol = manyTill get (void (char '\n') <++ eof)
-- Takes a list of parsers. Returns a parser that will try them in
-- order, moving to the next one only if the current one fails.
fallthroughParser :: [ReadP a] -> ReadP a
fallthroughParser [x] = x
fallthroughParser (x : xs) = x <++ fallthroughParser xs
-- ---------------
-- Parse a markdown header, denoted by 1-6 #'s followed by some text, followed by EOL.

Loading…
Cancel
Save