A small BibTeX parser and formatter built with Flex and Bison.
It reads BibTeX from standard input, validates key required fields for common entry types, normalizes selected fields, and prints canonicalized BibTeX to standard output.
- GNU Make
- Bash
- Flex
- Bison
- A C++17 compiler (for example, g++)
From the repository root:
makeThis generates:
dist/bibtex_lexer.cppdist/bibtex_parser.cppdist/bibtex_parser.hppdist/bibtex_compiler
To clean generated files:
make cleanUse stdin redirection with a .bib file:
./dist/bibtex_compiler < test/sample.bibRun the repository script:
./build_and_test.shThe script rebuilds the project and runs the compiler on:
test/sample.bibtest/A_Theory_of_Justice.bibtextest/big_file.bib
- Parses entries of the form
@type{key, field=value, ...}. - Reports parse errors with source location (
line:column). - Validates required fields for selected entry types.
- Canonicalizes output entry type to lowercase.
- Regenerates entry IDs from content when possible.
- Orders fields using a preferred field list, then alphabetically for unknown fields.
- Wraps long braced field values to 80 columns.
authorvalues are normalized toFirst Lastform per author and emitted in braces.journaltitleis renamed tojournal.date={YYYY}is normalized toyear={YYYY}.date={YYYY-MM}is split into:year={YYYY}month={M}(non-zero-padded)
- Existing numeric
monthvalues are de-zero-padded (01->1).
Some advertising/aggregator links are suppressed when found in url or note, including matches such as:
books.google.*jstor.orgresearchgate.netopenresearchlibrary.orgsemanticscholar.org
The parser checks required fields for these types:
article:author,title,yearbook:title,year, and one ofauthororeditorinproceedings:author,title,booktitle,yearincollection:author,title,booktitle,publisher,yearphdthesisandmastersthesis:author,title,school,yeartechreport:author,title,institution,yearbooklet:title
If any required fields are missing, the program prints an error and exits with status 1.
- Success: prints normalized BibTeX to stdout, exits 0.
- Validation failure: prints missing-field error to stderr, exits 1.
- Parse failure: prints parse error with location to stderr.
src/bibtex_lexer.l: Flex lexersrc/bibtex_parser.y: Bison grammar, validation, normalization, and outputtest/: sample inputsbuild_and_test.sh: convenience build and test scriptMakefile: build rules
This project is licensed under the GNU General Public License, version 3.
See LICENSE for the full text.