←back to thread

Parser Combinators Beat Regexes

(entropicthoughts.com)
120 points mooreds | 2 comments | | HN request time: 0s | source
Show context
yen223 ◴[] No.43639551[source]
Parser combinators are one of those ideas that is really powerful in practice, but will never be mainstream because it had the bad fortune of coming from the functional programming world. It's a shame too, because parser combinators are what made parsers click for me.

Take the hard problem of parsing a language, break it down into the much simpler problem of reading tokens, then write simple "combinators" (and, or, one_or_many, etc etc) to combine these simple parsers into larger more complex parsers.

You could almost build an entire parser combinator library from scratch from memory, because none of the individual components are complicated.

replies(13): >>43639775 #>>43639805 #>>43639834 #>>43640597 #>>43641009 #>>43641205 #>>43641459 #>>43641675 #>>43642100 #>>43642148 #>>43643853 #>>43644151 #>>43650405 #
skybrian ◴[] No.43639834[source]
Never is a long time. Other ideas from functional language have become mainstream.
replies(1): >>43639896 #
yen223 ◴[] No.43639896[source]
I would be very happy to be proven wrong here.

But I view parser combinators in the same lens as lenses, another powerful approach to solving a specific problem that is unlikely to receive mainstream recognition because of all the Haskell.

replies(3): >>43639982 #>>43640004 #>>43643966 #
1. BoiledCabbage ◴[] No.43640004[source]
> But I view parser combinators in the same lens as lenses

Hmm, anything else you have in that list I should be looking into? As I also agree they are two of the most interesting things I got from learning Haskell. (Along with type driven reasoning, monoids and functors).

replies(1): >>43640188 #
2. yen223 ◴[] No.43640188[source]
The big one that springs to mind, though it's not a Haskell idea, are algebraic effects and effects handler