Steve Klabnik changelog.com/posts

A Rust backend for Ragel

Yesterday, I read that Rust’s bindings to Ragel have been updated to work with Rust HEAD, so I figured I’d tell you! Here’s erickt’s repository.

What is Ragel? Ragel is a DSL that’s used to produce state machines that can be used to match some input. For example: HTTP has a grammar, so you could write it down with Ragel, and then Ragel would be able to spit out something that matches given input with the grammar.

Mongrel has a famously good Ragel HTTP parser that’s been used in basically every Ruby web server since. Here’s what an .rl file looks like. Zed Shaw, the author, once blogged about it:

Ragel is the software behind Mongrel’s speed and correct HTTP processing. With very little effort I was able to use Ragel to create a full HTTP processor that can process the protocol at insane speeds. From a developer point of view Ragel let me crank out a fully functioning web server in about a week. In fact, the number of changes to the parser in Mongrel only accounts for 4.2% of the total revisions.

Fun! Anyway, so here’s how it works: you write a .rl file that contains the grammar you’d like to make. You then run ragel on it, and tell it what language you’d like to use it in, and it makes a file with code in that language that you can use. Here is the C code that Ragel spit out for that .rl file above.

So, that’s what this project is: a fork of Ragel that supports a Rust backend. So you could take that HTTP parser from Zed, have it spit out some Rust code that parses HTTP requests, and you’d be on your way to writing a web sever in Rust. Awesome.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00