3.0 KiB
bibstd
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.
Requirements
- GNU Make
- Bash
- Flex
- Bison
- A C++17 compiler (for example, g++)
Build
From the repository root:
make
This generates:
dist/bibtex_lexer.cppdist/bibtex_parser.cppdist/bibtex_parser.hppdist/bibtex_compiler
To clean generated files:
make clean
Run
Use stdin redirection with a .bib file:
./dist/bibtex_compiler < test/sample.bib
Test
Run the repository script:
./build_and_test.sh
The script rebuilds the project and runs the compiler on:
test/sample.bibtest/A_Theory_of_Justice.bibtextest/big_file.bib
What The Tool Does
- 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.
Field Normalization
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).
Field Filtering
Some advertising/aggregator links are suppressed when found in url or note, including matches such as:
books.google.*jstor.orgresearchgate.netopenresearchlibrary.orgsemanticscholar.org
Required Field Checks
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.
Output And Exit Codes
- 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.
Project Layout
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
License
This project is licensed under the GNU General Public License, version 3.
See LICENSE for the full text.