How to parse specific syntax elements and discard the rest?
Haskell Community [Unofficial]
May 7, 2026
What you’re describing sounds very similar to the find-all-matches mode of regular expression drivers.
You can, of course, recreate this with parser combinators.
findAll :: Parser a -> Text -> [(a, Word)]
findAll parser = go 0
where
go offset input = case runParser parser input of
Left _ -> go (succ offset) (Text.drop 1 input)
Right (result, rest) -> result : go (offset + Text.length input - Text.length rest) rest
Assuming, it’s impossible to mistake your token for another token in the target language if context is missing. E.g. it would be impossible to exclusively find all variable names in Rust code because they overlap with Type Identifiers and more.
Edit: 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).
Discussion in the ATmosphere