Create a function to 'fallthrough parse' ie. try the second parser only
if the first one fails.
This commit is contained in:
@@ -141,6 +141,12 @@ manyTillLazy p1 p2 = do
|
|||||||
parseTillEol :: ReadP String
|
parseTillEol :: ReadP String
|
||||||
parseTillEol = manyTill get (void (char '\n') <++ eof)
|
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.
|
-- Parse a markdown header, denoted by 1-6 #'s followed by some text, followed by EOL.
|
||||||
|
Reference in New Issue
Block a user