Closed toburger closed 8 years ago
Thanks for contributing! This looks good but I think a few things could be improved:
loop
does a lot of unnecessary wrapping and unwrapping of the Parser
sloop
as a name is inconsistent with the rest of the library (accumulate
is the convention)res
rather than a
and end
rather than b
)succ
binding is unusedSo how about this instead:
manyTill : Parser res -> Parser end -> Parser (List res)
manyTill p end =
let
accumulate acc cx =
case app end cx of
(Fail err, cx) ->
case app p cx of
(Done res, cx') ->
accumulate (res :: acc) cx'
_ ->
(Fail err, cx)
(Done _, cx') ->
(Done (List.reverse acc), cx')
in
Parser <| accumulate []
Go ahead! I knew my code could be improved! thx! :)
Alright, it's in 1.2.0
:). Thanks again for contributing!
Hi Bogdan,
I'm using your parser combinator lib for parsing XML responses (from a legacy web service). I love your lib so far, however I was missing one specific combinator, available in other parser combinator libs (Haskell, F#) called
manyTill
. It allows to process one parser till another parser matches.This combinator is especially useful for parsing comments like for instance:
I'm not an expert in writing combinators (nor in elm) so I'm sure there exists a better implementation for this function.
Cheers Tobias