breakCap Break on and capture one pattern
Find the first occurence of a pattern in a text stream, capture the found pattern, and break the input text stream on the found pattern.
The breakCap function is like takeWhile, but can be predicated
beyond more than just the next one token. It's also like breakOn,
but the needle can be a pattern instead of a constant string.
Be careful not to look too far
ahead; if the sep parser looks to the end of the input then breakCap
could be O(n²).
The pattern parser sep may match a zero-width pattern (a pattern which
consumes no parser input on success).
Output
Nothingwhen no pattern match was found.Just (prefix, parse_result, suffix)for the result of parsing the pattern match, and theprefixstring before and thesuffixstring after the pattern match.prefixandsuffixmay be zero-length strings.
Access the matched section of text
If you want to capture the matched string, then combine the pattern
parser sep with match.
With the matched string, we can reconstruct the input string.
For all input, sep, if
let (Just (prefix, (infix, _), suffix)) = breakCap (match sep) input
then
input == prefix <> infix <> suffix