Nom Tutorial

Taking a bite out of Rust's parser combinator crate

Benjamin Kay
donut with bite missing

Nom is a powerful parser/combinator library written in Rust for binary and text streams. Its applications are similar to that of regular expressions, but Nom offers better performance, type safety, and error handling. This tutorial supplements the official documentation for the newly-released version 5 of the library.

Nom's official documentation includes trivially simple examples (e.g. how to parse a hexadecimal RGB color code) and very complicated examples (e.g. how to parse json). When I first learned nom I found a steep learning curve in between the simple and complex examples. Furthermore, versions of nom prior to 5 (along with most of the existing documentation) make heavy use macros. From nom 5.0 onward macros are soft-deprecated in favor of functions. This tutorial aims to fill the gap between simple and complex parsers by parsing the contents of /proc/mounts, and it demonstrates the use of functions instead of macros.

So without further adieu, if this sounds interesting to you, go check out the tutorial hosted on GitHub. Please e-mail me with comments, suggestions, or if you found the tutorial helpful!