6 ms·
Attoparsec is fast, but used to have bad error messages. How do the 2 parsers compare w.r.t error messaging? Haskell has Parsec/Megaparsec which have better e
by Peaker 9y ago
Attoparsec is fast, but used to have bad error messages.
How do the 2 parsers compare w.r.t error messaging?
Haskell has Parsec/Megaparsec which have better error messages, but are extremely slow.
- kccqzy 9y agoI don't think Parsec is "extremely slow." It's not as fast as attoparsec, but not bad either. Trifecta has the best error messages, but takes some more work to fully make the error messages great.
- Peaker 9y agoIn my experience using Parsec, it was extremely slow. Took around 20 seconds to parse a few hundred thousand lines (almost no backtracking, too). Attoparsec/parsec have very similar APIs. I wonder why it cannot parse optimistically with attoparsec, and in case of failure - re-parse with parsec to get a nice error message. This should yield the best of both worlds?
- mrkgnao 9y agoMegaparsec is more actively maintained than Parsec (which it's a fork of). You could try that. It's not as fast as attoparsec, but it's close.
- mrkgnao 9y agoTrifecta has poor documentation. I've been thinking about reading the Idris parser to learn trifecta/parsers.
- axman6 9y agoTrifecta is best used via the parsers library, which is fairly well documented. This also (in theory) allows you to switch which parser you use between trifecta, parsec, attoparsec and even ReadP. I say in theory because the the semantics of these libraries differ.
- quchen 9y agoI recommend the much smaller project by Merijn, lambda-except [1]. I learned Trifecta from it, and it’s really not all that difficult, just embarassingly poorly documented. I then wrote the parser for my STGi project based on Trifecta, so that may also be worth a look. [1]: https://github.com/merijn/lambda-except https://github.com/merijn/lambda-except [2]: https://github.com/quchen/stgi/blob/master/src/Stg/Parser/Parser.hs https://github.com/quchen/stgi/blob/master/src/Stg/Parser/Pa...
- Gabriel439 9y agoThe trick is to use the `parsers` library, which lets you switch out parsing backends. You can prototype with the `trifecta` library (which has good error messages) and then switch to `attoparsec` when you're done For this specific post, the main thing I do is ignore the error messages and just look at where parsing fails by retrieving the leftovers when it fails (using the lower-level `parse` function). Usually that gave me enough of a clue to figure out what was going wrong.