3 ms·
Great writeup, clear and easy to follow. For readers unfamiliar with nom, it would be even more helpful if the author included reference links, because I was i
by metadat 4y ago
Great writeup, clear and easy to follow.
For readers unfamiliar with nom, it would be even more helpful if the author included reference links, because I was immediately confused about the sudden appearance of the "alt(..)" function scene, seemingly materialized out of thin air (presumably imports omitted for brevity).
https://docs.rs/nom/latest/nom/branch/fn.alt.html https://docs.rs/nom/latest/nom/branch/fn.alt.html
- jmholla 4y agoWhat's with the 21 parsers limit?
- School-Cotton 4y agoIt's currently not possible to write a Rust function that's generic over a tuple with arbitrarily many entries, so they had to implement a trait by hand for tuple sizes up to 21 (presumably that limit was chosen arbitrarily).
- metadat 4y agoDoes Rust have a template or macro system that would facilitate generating up to e.g. 221 instead? If I'm understanding correctly, some Regex features may require implementing more than 21 rules for a thorough and complete implementation.
- jcparkyn 4y agoThe workaround is just to nest multiple `alt`s inside each other.
- iudqnolq 4y agoYes, rust declarative macros shine at exactly this kind of problem. And nom does use this to generate the implementation. But for some reason it's customary in rust to stick to a lower number of autogenerated implementations. My first guess would be it might be a compile time issue? https://docs.rs/nom/latest/src/nom/branch/mod.rs.html#245 https://docs.rs/nom/latest/src/nom/branch/mod.rs.html#245