1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//! A feature complete *BibTeX* parser using [nom](https://github.com/Geal/nom). //! //! **nom-bibtex** can parse the four differents types of entries listed in the //! [BibTeX format description](http://www.bibtex.org/Format/): //! //! - 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 = "@preamble{ //! \"A bibtex preamble\" # \" another test\" //! } //! //! @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 another test"); //! //! 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[0], ("name".into(), "Charles Vandevoorde".into())); //! assert_eq!(variables[1], ("github".into(), "https://github.com/charlesvdv".into())); //! //! 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[0], ("author".into(), "Charles Vandevoorde".into())); //! assert_eq!(bib_tags[1], ("title".into(), "nom-bibtex".into())); //! assert_eq!(bib_tags[2], ("note".into(), "Github: https://github.com/charlesvdv".into())); //! } //! ``` //! extern crate nom; extern crate quick_error; pub mod error; pub mod model; mod parser; pub use model::{Bibliography, Bibtex}; pub use parser::Entry;