sepBy package:streamly-core
Apply two parsers alternately to an input stream. Parsing starts at
the first parser and stops at the first parser. The output of the
first parser is emiited and the output of the second parser is
discarded. It can be used to parse a infix style pattern e.g. p1 p2 p1
. Empty input or single parse of the first parser is accepted.
Definitions:
>>> sepBy p1 p2 f = Parser.deintercalate p1 p2 (Fold.catLefts f)
>>> sepBy p1 p2 f = Parser.sepBy1 p1 p2 f <|> Parser.fromEffect (Fold.extractM f)
Examples:
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList
>>> p2 = Parser.satisfy (== '+')
>>> p = Parser.sepBy p1 p2 Fold.toList
>>> Stream.parse p $ Stream.fromList ""
Right []
>>> Stream.parse p $ Stream.fromList "1"
Right ["1"]
>>> Stream.parse p $ Stream.fromList "1+"
Right ["1"]
>>> Stream.parse p $ Stream.fromList "1+2+3"
Right ["1","2","3"]
Like
sepBy but requires at least one successful parse.
Definition:
>>> sepBy1 p1 p2 f = Parser.deintercalate1 p1 p2 (Fold.catLefts f)
Examples:
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList
>>> p2 = Parser.satisfy (== '+')
>>> p = Parser.sepBy1 p1 p2 Fold.toList
>>> Stream.parse p $ Stream.fromList ""
Left (ParseError "takeWhile1: end of input")
>>> Stream.parse p $ Stream.fromList "1"
Right ["1"]
>>> Stream.parse p $ Stream.fromList "1+"
Right ["1"]
>>> Stream.parse p $ Stream.fromList "1+2+3"
Right ["1","2","3"]
Non-backtracking version of sepBy. Several times faster.
Take either the separator or the token. Separator is a Left value and
token is Right value.
Unimplemented