streamly icon indicating copy to clipboard operation
streamly copied to clipboard

Nested termination in folds and parsers

Open adithyaov opened this issue 4 years ago • 1 comments

Fold.many and Parse.many are functions with no termination. The default termination reapplies the parsing/folding combinator.

Parse.many itself can have a natural nesting termination by terminating on parser failure

Folds on the other hand don't have a failure and have to represent nesting termination in an elegant way, One simple solution is to pass in the nested terminating condition, For example,

manyEndBy :: (a -> Bool) ->  Fold m a b -> Fold m b c -> Fold m a c 

Note that terminating folds don't have backtracking and manyWhile is only possible with 1 element backtracking. We need to think about 1 element backtracking in folds and if it's worth adding it.

adithyaov avatar Jul 24 '21 04:07 adithyaov

Perhaps the manyTill parser is the right solution for this?

harendra-kumar avatar Jul 27 '21 08:07 harendra-kumar