From 5fc1b1122ae3ce6167fe152291ebec908eff6ace Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Tue, 20 May 2025 12:18:23 -0500 Subject: [PATCH] Create a function to 'fallthrough parse' ie. try the second parser only if the first one fails. --- src/MdToHTML.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MdToHTML.hs b/src/MdToHTML.hs index fff6926..6920485 100644 --- a/src/MdToHTML.hs +++ b/src/MdToHTML.hs @@ -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.