Skip to content

typho/bibparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bibparser

A Rust crate for parsing BibTeχ and BibLaTeχ files.

As opposed to the biblatex crate, this crate does not try to interpret the content of fields. This crate resulted from the usecase that biblatex threw an error when math inline mode was not terminated before text was cut off.

Who should use it?

Anyone, how wants to retrieve data from a .bib file.

How does one use it?

Add this to your Cargo.toml:

[dependencies]
bibparser = "0.4.0"

Instantiate the parser and iterate over the items:

use bibparser::Parser;

//let mut p = Parser::from_file("source.bib")?;
let mut p = Parser::from_str(r#"@book{tolkien1937, author = {J. R. R. Tolkien}}"#)?;
for result in p.iter() {
  let entry = result?;
  println!("type = {}", entry.kind);
  println!("id = {}", entry.id);
  for (name, data) in entry.fields.iter() {
      println!("\t{}\t= {}", name, data);
  }
}

How does one run it?

This library comes with one example:

$ cargo run --example cli -- --input refs.bib

You can also enable serde-json support in order to print data as JSON:

$ cargo run --features serde,serde_json --example cli -- --input refs.bib --json

In this example, the library would read file refs.bib and then only print the entry with ID tolkien1937 to stdout.

Where is the source code?

On github.

What is the content's license?

MIT License

Changelog

  • 2022-07-16 version 0.4.0: skip @preamble, proper escape character handling, more tests, bugfix lexing error propagation
  • 2022-01-30 version 0.3.2: bugfix cli example & add JSON support
  • 2022-01-30 version 0.3.1: fix documentation & README
  • 2022-01-30 version 0.3.0: initial release

Where can I ask you to fix a bug?

On github.

What are known bugs / limitations?

  • .bib are strongly associated with Teχ which is a programming language, not a markup language. As such only the plain Teχ engine would be capable of understanding the content (esp. the field's data content). This library explicitly takes the approach to assume the content to be a markup language, which hopefully serves 99% of all usecases.
  • The markup language parsed by this library is not formalized.
  • Compability to BibTeχ or biblatex was not comprehensively tested.

About

A bib file parser written in rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages