3 ms·
This does work, and is available in e.g. the Parsec library for Haskell, but (1) can lead to exponential worst-case backtracking behavior. (2) can produce ver
by rntz 8y ago
This does work, and is available in e.g. the Parsec library for Haskell, but
(1) can lead to exponential worst-case backtracking behavior.
(2) can produce very unhelpful error messages without careful engineering.
In this case, for list comprehensions, I think you can show that you won't have exponential backtracking behavior. But it involves carefully thinking about whether patterns can nest inside of expressions nesting inside of patterns nesting... etc.
It's probably still the best solution if you're writing your own parser, though.