-
Notifications
You must be signed in to change notification settings - Fork 132
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
Fix blocks not starting on new lines (#411) #416
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. Thanks a lot for opening the PR.
I left one minor comment regarding the test above.
A more significant problem is on line 175. Currently, we discover if a new block starts with a previous one still open, which typically highlights an error in the parsed file. In such a case, we abort processing the still open block, in deliberate deviation from "strict bibtex parsing". As we only considered @....
on the start of a new line, the risk of flagging a "false positive" was negligible, but at the same time the user experience increased drastically.
With your change, we would abort the parsing of a block when facing an unexpected @....
anywhere, e.g, the following could not be parsed:
@entry{key, title="all blocks must start with @entry{"}
To reduce this risk, I would love to keep the previous behavior and only abort the parsing of a block if a new block starts on a new line. Does that make sense?
Note:
Another problem, but one which does not have to be fixed in this PR is that biber-style comment won't be working after fixing this PR anymore, e.g. the following will likely result in an error.,
% @entry{key,
% title="sometitle"}
However, we technically still don't support biber comments and a clean solution is required there anyways, thus I'd leave this to #372
I don't think the python-bibtexparser/bibtexparser/splitter.py Lines 131 to 189 in 770eb00
In the example of I'm planning to rewrite this method and make another PR. |
Thanks for your PR update and for your long comment. First things first:Your argument convinced me that a plain Regarding the larger argument you made:This library is deliberately not 100% consistent with bibtex, but it attempts to be somewhat more fault-tolerant: We aim to be able to handle cases when there are small mistakes in the bibtex file gently, without messing up the parsing of subsequent blocks, or even prevent parsing at all. This is a request we received numerous times reagarding bibtexparser v1. Take the following example:
While the intention of the writer here is pretty clear, bibtex would not be happy: Note the Thus, I am very happy to review any improvement you make to the parsing (and I am sure there are plenty to be made ;-)), but please keep in mind that we take a deliberate trade-off between sticking to the pure bibtex rules, and user friendly parsing of imperfect files. If in doubt, before investing too much time, feel free to ask for mine (and anyones) comment in a seperate issue before investing too much time. Most importantlyThanks again for your contribution, and I am looking forward to your next PRs. |
This PR modifies the
@
marker regex so that it doesn't necessarily appear at a new line. It also passes all the tests.