Expand description
BibTeX parser — a from-scratch tolerant parser tuned to match
bibtexparser v2’s observed behavior (empirically verified, same
methodology as tex::parser), not a general BibTeX grammar
implementation.
Empirically-verified rules this parser encodes:
- Anything outside an
@...{...}block is a comment (ignored), including partial-line text before the first@. @string{name = value}defines a macro; a later BARE-token field value (no{}/""delimiters) matching a defined name resolves to that string’s value.@comment{...}/@preamble{...}blocks are skipped entirely (their balanced-brace body is consumed but not otherwise interpreted).- Field values may be
{...}(nested-brace-balanced),"..."(no nesting; a literal\"inside unescapes to"), or a bare token (word/number, or an@stringname) — parts joined by#concatenate with no separator. The assembled value has leading/trailing whitespace stripped (verified:bibtexparserdoes this too — seenaming.py::_field_value_span’s comment). - Key uniqueness policy mirrors
core/parser.py::parse_bib_source, NOT rawbibtexparser: the first entry for a given key goes toLibrary::entries; a later entry reusing that key goes ONLY toLibrary::duplicate_block_keys(never re-added toentries, matching the Python comment “bibtexparser kept the first occurrence… we must not double-flag them as parse errors”). - Duplicate-field-within-an-entry policy also mirrors
parse_bib_source, not rawbibtexparser: last value wins per field, the entry is recorded induplicate_field_keysfor BIBTEX-005 to report, AND (unlike a duplicate key) the recovered entry IS added toLibrary::entriestoo, so every other rule still lints it — Python re-inserts it explicitly viaRemoveEnclosingMiddleware+library.add(entry)specifically so a single internal-duplicate-field typo doesn’t blind every other bib rule to that entry.
Known, deliberate gaps: no crossref inheritance, no @string
forward-reference validation (an undefined bare token is kept
literally, same fallback bibtexparser uses), no attempt at
bibtexparser’s full failed-block taxonomy — only the two variants
(DuplicateBlockKeyBlock, DuplicateFieldKeyBlock) the 13 bib
rules actually consume are modeled.