When trying to parse huge bibtex files (e.g. one of the cryptobib files) recursion in the entries parser at src/parser.rs:368:51 exhausts the stack and causes an overflow. Try using e.g. backtrace_on_stack_overflow to verify this.
Example code:
extern crate nom_bibtex;
use std::fs;
use nom_bibtex::Bibtex;
fn main() {
unsafe {
backtrace_on_stack_overflow::enable()
};
let filename: &str = "crypto.bib";
let buf = fs::read_to_string(filename).expect("Couldn't open file");
let bib = Bibtex::parse(buf.as_str()).unwrap(); // <-- HERE
println!("{:?}", bib); // or something
}
Using a loop instead resolves this issue (see diff). This also removes the need for the O(n) insert operation because the entries are parsed in the original order instead of reversed, so push can be used.
I also added the option to have bracketed strings in concatenation, so the crypto.bib file can be parsed without any fixes to it. The bibtex binary also accepts this syntax as valid.
Switched test file to original crypto.bib that can be found here.
When trying to parse huge bibtex files (e.g. one of the cryptobib files) recursion in the
entries
parser atsrc/parser.rs:368:51
exhausts the stack and causes an overflow. Try using e.g. backtrace_on_stack_overflow to verify this.Example code:
Using a loop instead resolves this issue (see diff). This also removes the need for the
O(n)
insert operation because the entries are parsed in the original order instead of reversed, so push can be used.