Choosing a parser library for a language


#1

I want to create a really simple language that compiles to SPIRV. Today I had a look at various parser libraries.

The first libraries that came to mind were https://github.com/Geal/nom and https://github.com/Marwes/combine. I have to say combine looks really clean.

But then I found out that the author of combine also works on a language https://github.com/gluon-lang/gluon. Interestingly he chose https://github.com/nikomatsakis/lalrpop over his own parsing library. There is also https://github.com/PistonDevelopers/meta and https://github.com/kevinmehall/rust-peg for parsor generators.

I have to say I don’t fully see the advantage of parser generators at all, they seem too magical. Is there something inherently wrong with parser combinator libraries for parsing a language? I could potentially see that it might be easier to make large scale changes to a parser generator.

Which library would you choose and why?


#2

Not an answer to your question, but you might find the following paper interesting http://spw17.langsec.org/papers/chifflier-parsing-in-2017.pdf. It uses nom but talks a bit about parser generators vs parser combinators in principle.


#3

Thanks, I probably will also use nom.


#4

@MaikKlein I recently worked on a parser for a scene description (for my renderer) and tested pest. So far so good …


#5

This is why I like them, I write my grammar and I get AST, no coding involved. One of benefits is that library may improve with time in terms of speed or error messages, and I won’t have to do anything to get that, so +1 for lalrpop from me.
I am using it and had no problems with it, though I’d love to see ANTLR supporting Rust.


#6

I’m currently using nom in a project that involves parsing programming language source code:

I’m quite happy with nom for now, the documentation could be better (and I’ll try to also work on it). If you want to help improve it join the discussion here: