Take the 2-minute tour ×
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.

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
4  
The Collection of Computer Science Bibliographies might be another source for test cases. –  Christian Lindig Apr 24 '11 at 12:23
2  
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
add comment

3 Answers 3

up vote 11 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
add comment

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
add comment

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-examples.bib

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.