-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minimize nom macros #3
Comments
I think it would be great to move to idiomatic nom 5 code! I never liked the macro approach much, since it makes debugging hard and control flow unwieldy to express. So I'm definitely up for replacing the macros with functions. I took a brief look at your example snippet. I'm not familiar with the new nom yet, but it looks like you can get rid of the |
Unfortunately
However, for better or worse, nom's error type in Instead we have the
While I'm obviously in favor of minimizing macro use, I updated the branch to lift the logic for endianness conversion out of |
That does indeed work, no? As a quick test I compiled your branch and then replaced I think your endianness check got a little more complicated since it introduced a bug(?). Based on your changes I pushed another version: https://github.com/dthul/matfile/compare/nom_no_macros#diff-258c0555e6f9c4bc4fba3a551d81638aL117 |
You are right, I was confused about the limitations on Thank you for pointing out my bug with regard to endian byte swapping. I see your way of parsing/verifying the version and endianness uses about the same number of lines, but it is easier to follow because it is broken up into multiple statements rather than one big nested parser. I will work on converting the remaining methods in |
With nom 5.0 the author, Geoffroy, has soft-deprecated macros in nom. Although macros used to be needed to write concise parsers with nom, as Rust has evolved it is now possible to write equally concise parsers without macros. The advantages of minimizing macro use include more comprehensible error messages and less of a learning curve for newcomers since they do not have to learn and understand nom's niche macro conventions.
I'm interested in contributing to matfile and would prefer to write code using nom methods instead of nom macros. I realize that as the library author you may have strong preferences about this. I've rewritten
parse_header()
as an example of what parsing would look like with less reliance on nom macros. (I also removed panics and removed the assumption that the host machine is little endian.) Of course, the rewritten version still passescargo test
.Please let me know what you think. I would be happy to work on the rest of the nom parsing code, but I don't want to waste time if you hate the macro-less syntax.
The text was updated successfully, but these errors were encountered: