Expand description
Bibliography records for Mosaic (manifest §12).
parse_bibtex reads a BibTeX string into typed BibEntry records,
keyed by citation key inside a Bibliography. The grammar is a
deliberately small, well-defined BibTeX subset: entry type, citation
key, and {braced} / "quoted" / bare string fields: chosen to give a
later citation resolver a stable, ordered record model to build on.
Within that subset the parser is complete: it accepts any
@type{key, field = value, ...} entry, lowercases the (case-insensitive)
entry type and field names while keeping citation keys verbatim, balances
nested braces, and reports malformed input as a BibParseError with a
byte offset instead of panicking. Entries and fields live in
BTreeMaps, so iteration is deterministic
and sorted.
Bibliography features beyond record parsing are separate concerns and
live elsewhere when they land: CSL / BibLaTeX styling, @string /
@preamble / @comment and # concatenation, TeX decoding, name
parsing, reading .bib files from disk, citation-key resolution, and
citation or bibliography rendering. This crate does none of those and has
no mos-eval / layout / PDF wiring.
§Examples
use mos_bib::parse_bibtex;
let bib = parse_bibtex("@article{knuth1984, title = {Literate Programming}, year = 1984}")?;
let entry = &bib.entries["knuth1984"];
assert_eq!(entry.entry_type, "article");
assert_eq!(entry.fields["title"], "Literate Programming");
assert_eq!(entry.fields["year"], "1984");Modules§
- content 🔒
- Content-hash boundary for bibliography inputs (manifest §7, §32; design
note
docs/incremental-dependencies.md§4.1). - error 🔒
- The local BibTeX parse error type,
BibParseError, and itsBibParseErrorKindclassification. - parser 🔒
- Hand-rolled recursive-descent parser for the minimal BibTeX subset.
- record 🔒
- The parsed bibliography data model:
Bibliography,BibEntry, and the document-bodyCitationreference.
Structs§
- BibEntry
- A single parsed BibTeX entry: one
@type{...}record. - BibParse
Error - A recoverable BibTeX parse error: a
BibParseErrorKindplus the byte offset into the original input where the problem was detected. - Bibliography
- A parsed bibliography: every
BibEntrykeyed by its citation key. - Citation
- A citation reference within the document body: a single key that
resolves into a
Bibliographyentry at render time.
Enums§
- BibParse
Error Kind - What went wrong while parsing BibTeX. Paired with a byte offset inside a
BibParseError.
Functions§
- bibliography_
content_ hash - Compute the content-hash boundary for one bibliography source’s raw bytes.
- parse_
bibtex - Parse
inputas a minimal BibTeX database.