Giter Site home page Giter Site logo

nom-bibtex's Introduction

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");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.