Attoparsec: match many, skipping rest

Say I've got an Attoparsec parser like: p = string "prio:" *> digit And some text, e.g. s = "this is just a prio:5 example, I'd prio:6 very much like to prio:4 parse" What's the most idiomatic way to apply p to s so that I get out a list ['5', '6', '4']? Thanks, Tom

Hi! There was "recently" a family libraries published for exactly this purpose: https://github.com/jamesdbrock/replace-attoparsec In the past I've done it character by character, but I definitely wasn't caring about performance then. I would assume the replace-* family of libraries are more efficient for the purpose ======= Georgi

On 2020-04-11 4:23 p.m., amindfv@gmail.com wrote:
Say I've got an Attoparsec parser like:
p = string "prio:" *> digit
And some text, e.g.
s = "this is just a prio:5 example, I'd prio:6 very much like to prio:4 parse"
What's the most idiomatic way to apply p to s so that I get out a list ['5', '6', '4']?
I'd go with many (many (notFollowedBy (string "prio:") *> anyChar *> skipWhile (/= 'p') *> string "prio:" *> digit)

Am 11.04.20 um 22:23 schrieb amindfv@gmail.com:
Say I've got an Attoparsec parser like:
p = string "prio:" *> digit
And some text, e.g.
s = "this is just a prio:5 example, I'd prio:6 very much like to prio:4 parse"
What's the most idiomatic way to apply p to s so that I get out a list ['5', '6', '4']?
If your input language is regular, as it appears to be, you could try regex-applicative. Your desired combinator could be expressed simply as: many_ending_with p = many (many anySym *> p) without incurring any backtracking cost. Cheers Ben
participants (4)
-
amindfv@gmail.com
-
Ben Franksen
-
Georgi Lyubenov
-
Mario