charlesvdv / nom-bibtex

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

Remember order of tags in BibTeX entry #28

Open pjhuxford opened 5 months ago

pjhuxford commented 5 months ago

Currently the tags of a bibliography entry are stored in a HashMap, which means the order of the tags is unstable.

I have a use-case in mind where I would like to parse a bibliography entry from a file, perform some minor edits, and then write the new entry back to the same file. If I use nom-bibtex for the parsing then I have no way to recover the original order of the tags in the entry. This could potentially make the version control history of the file confusing to decipher.

If you're also interested in remembering the order of the tags, I suppose one option would be to replace HashMap with IndexMap from the indexmap crate. Another option would be storing a Vec<String> of the keys alongside the HashMap.

A6GibKm commented 5 months ago

Makes sense to me, but returning a struct thats not from the lib, nor from std is kinda annoying.

pjhuxford commented 5 months ago

Yeah it is annoying that IndexMap isn't in std, although it does seem like the most performant way to handle this. Maybe storing the keys of the tags in a Vec<String> is a better approach though. What do you think?