Skip to main content

Module parser

Module parser 

Source
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:

  1. Anything outside an @...{...} block is a comment (ignored), including partial-line text before the first @.
  2. @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).
  3. Field values may be {...} (nested-brace-balanced), "..." (no nesting; a literal \" inside unescapes to "), or a bare token (word/number, or an @string name) — parts joined by # concatenate with no separator. The assembled value has leading/trailing whitespace stripped (verified: bibtexparser does this too — see naming.py::_field_value_span’s comment).
  4. Key uniqueness policy mirrors core/parser.py::parse_bib_source, NOT raw bibtexparser: the first entry for a given key goes to Library::entries; a later entry reusing that key goes ONLY to Library::duplicate_block_keys (never re-added to entries, matching the Python comment “bibtexparser kept the first occurrence… we must not double-flag them as parse errors”).
  5. Duplicate-field-within-an-entry policy also mirrors parse_bib_source, not raw bibtexparser: last value wins per field, the entry is recorded in duplicate_field_keys for BIBTEX-005 to report, AND (unlike a duplicate key) the recovered entry IS added to Library::entries too, so every other rule still lints it — Python re-inserts it explicitly via RemoveEnclosingMiddleware + 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.

Functions§

parse