pigeon
A recursive descent parser generator library that use inlined macs.
Json
For example, to parse a json file, you can write the following code, and use parse<Json> to parse a json formatted string. That's it.
use *;
The format string is simple. You can think of it as the reverse of a rust printing format string.
// printing
println!;
// when we match {0} to something and {1} to something.
// we fill it as Add({0}, {1})
Add,
Precedence
To handle binary expression with left recursion and precedence, you can do this:
use *;
The precedence=..., gives a precedence to this pattern, and by putting a number {...:n} after a hole, it means we only allow rules with precedence <n in that hole.
So Mul only allow Number on its left hand side.
Pitfall
A bad thing about recursive descendent parser is that it only supports right association, so a - b - c is parsed as a - (b - c) , which is not what we normally think it is. But you can write a transformation to remove that or implement add/sub as iterators.