Humans-of-Julia / BibParser.jl

Parser for bibliographic formats, including BibTeX, in pure Julia
MIT License
13 stars 4 forks source link

Bugs in `@string` parsing #31

Open goerz opened 1 year ago

goerz commented 1 year ago

The parsing of @string entries seems to have some bugs:

import BibParser

bibtex = """
@string{foo = {Mrs. Foo}}

@string {bar = "Mr. Bar"}
"""

BibParser.BibTeX.parse_string(bibtex; check=:error)

results in

Warning: The entry is incomplete and end from (line 1, character 13) to (line 3, character 1): '= {Mrs. Foo}}'
Warning: The entry kind is invalid from (line 3, character 2) to (line 3, character 9): '@string'

The first @string using braces instead of quotes may not actually be in line with the description at http://www.bibtex.org/Format/, but it is definitely accepted by bibtex, and, more importantly, it's what BibDesk generates. The second @string with a space before the opening brace is directly from http://www.bibtex.org/Format/. It's not a format I personally use, but it should definitely be valid.

Azzaare commented 1 year ago

Good catch! Thank you.

I don't see the issue in parsing entries that are not fitting exactly BibTeX format description. As long as it doesn't conflict with the format, I am fine with any addition.

Adding the option to parse without errors, both string entries in your example should be quick (I am quite busy until mid-March though). However, it also touches one issue that is to handle and/or replace the entries of @string in the parsed bibliography. I will try to get all of those done during March.

goerz commented 1 year ago

No rush… I can work around this and #32 by adjusting the .bib file a bit, so it's not really a dealbreaker. Maybe I'll have a look at if I can make a PR to fix this, too.