charlesvdv / nom-bibtex

A feature complete bibtex parser using nom
https://docs.rs/nom-bibtex
MIT License
22 stars 15 forks source link

Refactor parser to use nom functions instead of macros #9

Closed TheZoq2 closed 4 years ago

TheZoq2 commented 4 years ago

I hope you don't mind my PR spam :) This one is a bit larger than the previous one, I hope you dont mind that either.

In #8 I mentioned that the point of that PR originally was to gain access to the VerboseError stuff from nom 0.5 which ultimately failed. The reason it failed was that those macros define functions that return (I, ErrorKind) which is not very useful. In order to fix it, I made the parser functions generic over the error type. I also had to add some extra macros to

  1. Avoid having to write the same function definition in all the functions
  2. Replace the do_parse! macro defined by nom which doesn't work.
  3. Avoid having to add delimited(multispace0, <some parser>, multispace0) everywhere

In order to make debugging even easier, I also added the nom_traceable crate along with a new feature called trace which allows printing of the work that the parsers do. This is primarily intended for development of the crate itself.

The structure of the parser is largely the same with some tiny differences. The tests remain the same, but I had to change the types for obvious reasons. I added a few new tests to debug issues I found, and finally I removed a test that said @preamble {my vars} should parse. As far as I can tell, that structure is not supported without quotes, and it caused issues. If that should be supported, let me know :)

TheZoq2 commented 4 years ago

Oh yea, like the previous pair of PRs, this one also includes the changes from #8

charlesvdv commented 4 years ago

I really don't mind! I am happy that someone finds the stuff I did somewhat useful! Thanks for the PR! It looks good to me!

And at the same time, it seems it's closing #1 at the same time. @rubdos Pinging you because you might be interested by what @TheZoq2 did..

rubdos commented 4 years ago

Cool stuff, thanks for the heads up :-)