Skip to main content

parse_bibtex

Function parse_bibtex 

Source
pub fn parse_bibtex(input: &str) -> Result<Bibliography, BibParseError>
Expand description

Parse input as a minimal BibTeX database.

Returns a Bibliography whose entries are keyed by citation key. A duplicate citation key is rejected so later resolver work can report it before any source-location context is lost. Parsing stops at the first malformed entry and returns a BibParseError pinpointing the byte offset; well-formed input never panics.

§Errors

Returns a BibParseError when the input is not a sequence of well-formed @type{key, field = value, ...} entries separated by whitespace: for example a missing @, entry type, {, citation key, or =, or an unterminated brace/quote value.

§Examples

use mos_bib::parse_bibtex;

let bib = parse_bibtex("@article{rivest1978, author = {Ron Rivest}, year = 1978}")?;
assert_eq!(bib.entries["rivest1978"].fields["year"], "1978");