Rust Ragel Parser Alternatives


Over the years I have used Ragel to generate parsers. I have found the following features to be really useful:

  • A Ragel program can be converted to different computer languages quite easily. One project I did needed a parser for both iOS and Android – Ragel saved the day.
  • The parsers tend to be efficient, more so than a parser hand written by me.
  • There exists a hacky solution to parse length delimited values such as {5}xxxxx which would mean the next 5 bytes. This is hard for a parser generator to handle and was once a research problem. Despite this difficulty, the length delimited construct appears in lots of protocols.

So I use and like Ragel. I was sad to see that Ragel will no longer support alternative languages such as Rust, Go and Java.

Can anyone that has been using parsers in Rust recommend an alternative? I know I can get an answer from a quick internet search but its not necessarily a good answer. I also know I will need to compromise on the things I like about Ragel - cross language support, efficiency and length delimited parsing. The most important of these for me is the length delimited parsing.

Thanks in advance for any help.


I’ve been using nom for parsing, and it seems like it meets some of your requirements.

  1. Nom runs on any platform that Rust can compile to. It doesn’t support generating C, although it does let you create a static library that can then be linked to C, if Rust supports the target platform.

  2. It’s efficient. The big selling point is that it’s zero-copy, which means that the parser hands out pointers into the buffer that it was given to parse, instead of copying out pieces of it.

  3. It supports length-delimited values, like with the length_data combinator.