3 ms·
Personally, I disagree that parsing was hard before and made easy with PEG parsing. For decades it has been easy and common to implement parsers by hand. From
by eatonphil 5y ago
Personally, I disagree that parsing was hard before and made easy with PEG parsing.
For decades it has been easy and common to implement parsers by hand.
From what I can tell, universities and textbooks just overcomplicated the process by teaching parser generators.
I have done a few studies of various open source ecosystems now and (edited: other than CPython) I haven't seen PEG parsers really used in anything but toy implementations of things.
- linux2647 5y agoCPython appears to use a PEG parser for its implementation: https://github.com/python/cpython/blob/b77158b4da449ec5b8f682816a79d004fd65ed07/Grammar/python.gram https://github.com/python/cpython/blob/b77158b4da449ec5b8f68...
- eatonphil 5y agoThat's true, but it's still quite rare to see.
- UncleEntity 5y agoPretty sure that’s relatively new and had a hand written parser for most of their history. …which also implies that it used to be hard and now isn’t.
- eatonphil 5y agoNo they moved from pgen, a custom parser generator, to this PEG parser. The parser was never handwritten.
- TheCondor 5y agoIt’s been a minute but parsing with decent performance is what caused all the parser generator stuff. It is a historically hard problem. PEGs allow the generator input to more closely match the mental model programmers have, *LR require the language to be structured just a little differently than how most people think it.
- eatonphil 5y agoWell if most production parsers use hand-written parsers (and aside from SQL databases, they mostly do) I don't think performance would really make sense to be the reason anyone chooses parser generators. I'd be curious to read any posts/papers you've got that have benchmarks that show performance to be a reason.
- sillysaurusx 5y agoI recently used lark and liked it. To my surprise.
- smilekzs 5y agoIMHO the barrier of entry really came down because with PEG-styled parser libs they put you back in the comfortable "declarative land" where you specify what you want using roughly the same mental model as RegEx without having to worry too much about quirks caused by implementation (i.e. leaky abstraction).
- chrisseaton 5y ago> IMHO the barrier of entry really came down because with PEG-styled parser libs they put you back in the comfortable "declarative land" The whole idea of PEGs is that they’re specifically not declarative - they’re an imperative way to express a parser.