TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've developed a simple BibTeX parser. I want to test whether it can handle all possible nuances that can occur in BibTeX databases.

Is there a standard .bib file against which I can check my parser, so that I can be assured of its parsing capabilities?

I've already tried some .bib files off the Internet and they are being processed correctly.

share|improve this question
The Collection of Computer Science Bibliographies might be another source for test cases. – Christian Lindig Apr 24 '11 at 12:23
Is your parser, by any chance, open source? I would be very interested in a good parser implementation, even better if it can convert to HTML – Federico Poloni Apr 25 '11 at 9:42
@Christian, that's an excellent choice, you may want to put that down as an answer. – user5018 Apr 26 '11 at 3:58
@Federico, I'm sorry but my parser only stores the results in an SQLite DB for querying. I can share the source code if needed. You should surely check out bib2html (litech.org/~wkiri/bib2html) though. – user5018 Apr 26 '11 at 4:01
up vote 12 down vote accepted

The Collection of Science Bibliographies provides a huge number of test cases. It might be that the ones on site are generated by a pretty printer and thus would be quite uniform in their syntactical features. However, there are also links to the original files which should be more diverse.

For testing parsers in general, there typically is no one Gold standard. Compiler writers rely on individual test cases and test case generators. A test case generator is driven by the grammar of a language and can help to find corner cases that rarely occur in practice. Developing those requires substantial effort, though. If you are curious, look for fuzz testing. As an example for the C language, Finding and Understanding Bugs in C Compilers is a fascinating read about this subject.

share|improve this answer

If you have biblatex installed, then you have a nice example .bib file at $TEXMF\bibtex\bib\biblatex\biblatex-examples.bib. It has a lot of comments describing the possible pitfalls of each bibtex entry. Alternatively you can download the file here: http://mirror.ctan.org/macros/latex/contrib/biblatex/bibtex/bib/biblatex/biblatex-examples.bib

share|improve this answer

I was thinking on a BNF grammar of the BibTeX format, but I coudn't find one by myself. The closest I found was this one (from a TCL/TK wiki):

# A rough grammar (case-insensitive):
# Database  ::= (Junk '@' Entry)*
# Junk      ::= .*?
# Entry ::= Record
#       |   Comment
#       |   String
#       |   Preamble
# Comment   ::= "comment" [^\n]* \n     -- ignored
# String    ::= "string" '{' Field* '}'
# Preamble  ::= "preamble" '{' .* '}'   -- (balanced)
# Record    ::= Type '{' Key ',' Field* '}'
#       |   Type '(' Key ',' Field* ')' -- not handled
# Type  ::= Name
# Key   ::= Name
# Field ::= Name '=' Value
# Name      ::= [^\s\"#%'(){}]*
# Value ::= [0-9]+
#       |   '"' ([^'"']|\\'"')* '"'
#       |   '{' .* '}'          -- (balanced)

If your parser is handling well all the .bib files you tested, I think you already did a great job!

share|improve this answer
You don't need salutations or closings in your answers. That grammar is also wrong. – TH. Apr 26 '11 at 7:18
@TH.: Thanks for the hints. As I said, that grammar is the closest I found on the subject. Unfortunately, I'm not that used to BibTeX neither BNF to provide a better grammar. I just thought that'd be a nice starting point. Glad you pointed that. – Paulo Cereda Apr 26 '11 at 12:45

protected by Kurt May 19 at 15:57

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?