fix(bib): handle @comment@entry-type per BibTeX spec#15
Open
wali-reheman wants to merge 1 commit into
Open
Conversation
Per the BibTeX specification, @comment must be followed by a delimiter (whitespace, {, or ,) to be recognized as a comment command. Otherwise, the text after @ is treated as an entry type. For example, '@comment@book{key, title = {T}}' is parsed as entry type 'book' (key='key'), not as a comment. This matches BibTeX behaviour where '@comment@book' is treated as an entry of type 'book'. The parser previously consumed '@comment@book' as a single identifier token and treated it as entry type 'comment@book', which is incorrect. Fixes aclements#13.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per the BibTeX specification,
@commentmust be followed by a delimiter (whitespace,{, or,) to be recognized as a comment command. Otherwise, the text after@is treated as an entry type.For example,
@comment@book{key, title = {T}}is parsed as entry type book (key=key), not as a comment. This matches BibTeX behaviour where@comment@bookis treated as an entry of typebook.The parser previously consumed
@comment@bookas a single identifier token (becauseID_REincludes@) and treated it as entry typecomment@book, which is incorrect.Fix
In
_scan_command_or_entry, after scanning the identifier token, check if it starts withcomment@. If so, this is the@comment@...pattern — rewind to the second@and reparse as a fresh entry. A__in_comment_rewindflag prevents the@stringmacro command from being treated as a regular entry during the rewind.Test cases added
@comment@book{test, title = {Test}}→ entry type book@comment@string{foo, title = {Bar}}→ entry type string@comment {text}followed by@misc{x, title = {X}}→ entry x (comment ignored)@string{foo = {Bar}}still works as a macro commandReferences