External Publication
Visit Post

How to parse specific syntax elements and discard the rest?

Haskell Community [Unofficial] May 7, 2026
Source

VegOwOtenks:

findAll :: Parser a -> Text -> [(a, Word)]

You can also just do something like:

findAll :: Parser a -> Parser [a]
findAll p = p <|> anyChar *> findAll p

(Note that this assumes that your parser combinator library backtracks, some popular ones like parsec and megaparsec require manual try annotations around the first p.)

VegOwOtenks:

Efficiency is always questionable when using parser combinators. You are probably a lot better off hand-writing some pattern-matching/parsing code over the input string if performance starts mattering (or does already).

Or use flatparse, it generally is as fast as handwritten loops, unless you start doing fancy things with it.

Discussion in the ATmosphere

Loading comments...