6 releases (breaking)

0.5.0 Sep 24, 2023
0.4.0 Mar 14, 2023
0.3.0 Jul 22, 2020
0.2.0 May 29, 2017
0.1.1 May 23, 2017

#322 in Parser implementations

Download history 137/week @ 2023-12-04 108/week @ 2023-12-11 453/week @ 2023-12-18 125/week @ 2023-12-25 267/week @ 2024-01-01 251/week @ 2024-01-08 104/week @ 2024-01-15 172/week @ 2024-01-22 139/week @ 2024-01-29 118/week @ 2024-02-05 150/week @ 2024-02-12 173/week @ 2024-02-19 224/week @ 2024-02-26 266/week @ 2024-03-04 240/week @ 2024-03-11 277/week @ 2024-03-18

1,036 downloads per month
Used in 4 crates

MIT license

44KB
1K SLoC

nom-bibtex

Rust Docs Badge crates.io

A feature complete BibTeX parser using nom.

nom-bibtex can parse the four differents types of entries listed in the BibTeX format description:

  • Preambles which allows to call LaTeX command inside your BibTeX.
  • Strings which defines abbreviations in a key-value format.
  • Comments.
  • Bibliography entries.

Example

extern crate nom_bibtex;
use nom_bibtex::*;

const BIBFILE_DATA: &str = r#"@preamble{
        "A bibtex preamble"
    }

    @Comment{
        Here is a comment.
    }

    Another comment!

    @string ( name= "Charles Vandevoorde")
    @string (github = "https://github.com/charlesvdv")

    @misc {my_citation_key,
        author= name,
        title = "nom-bibtex",
        note = "Github: " # github
    }
"#;

fn main() {
    let bibtex = Bibtex::parse(BIBFILE_DATA).unwrap();

    let preambles = bibtex.preambles();
    assert_eq!(preambles[0], "A bibtex preamble");

    let comments = bibtex.comments();
    assert_eq!(comments[0], "Here is a comment.");
    assert_eq!(comments[1], "Another comment!");

    let variables = bibtex.variables();
    assert_eq!(variables["name"], "Charles Vandevoorde");
    assert_eq!(variables["github"], "https://github.com/charlesvdv");

    let biblio = &bibtex.bibliographies()[0];
    assert_eq!(biblio.entry_type(), "misc");
    assert_eq!(biblio.citation_key(), "my_citation_key");

    let bib_tags = biblio.tags();
    assert_eq!(bib_tags["author"], "Charles Vandevoorde");
    assert_eq!(bib_tags["title"], "nom-bibtex");
    assert_eq!(bib_tags["note"], "Github: https://github.com/charlesvdv");
}

Dependencies

~2.5MB
~54K SLoC