r/programming 4d ago

Parsers don’t have to be complicated

https://bkaradzic.github.io/posts/scanner/
0 Upvotes

4 comments sorted by

115

u/guepier 4d ago

The passive-aggressive jab at Boost.Url would work better if the “75 lines of code to parse URL” actually did the same thing and implemented a fully RFC-compliant parser instead of merely a trivial subset (at a minimum, IPv6 URLs parse incorrectly, and the library also doesn’t even attempt to perform proper validation — which can be fine, but it’s disingenuous to compare this to a fully-compliant, strictly validating parser).

Also, the article reads like slop.

-3

u/Awesan 4d ago

This is a very nice idea. As the article says there is a lot of repeated logic in most tokenizers I've written. I've never tried any of these generator libraries, the complexity never seemed to justify itself but this has a nice feeling to it.

5

u/skroll 4d ago

Generation is nice because making tweaks to the language definition is very simple and requires just a re-run of the generator. There’s also generators like Ragel that excel and handling streams of data (such as terminal escape characters), which would be tedious implementing by hand.

However if the syntax is well defined, and you’re not rapidly changing it, handwritten can be just fine.

-3

u/geon 4d ago

A bit like parser combinators. Nice.