pub fn parse_bibtex(input: &str) -> Result<Vec<ParsedItem<'_>>>Expand description
Parse a BibTeX file into raw items without expansion or processing
This is a low-level API that returns the raw parsed items before
string variable expansion or other processing. Most users should
use Library::parse() instead.
The returned items preserve the original structure:
- String variables are not expanded
- Concatenations are preserved as
Value::Concat - Comments are included (both
%line comments and@comment{}) - All items are returned in parse order
§Performance
This function uses the same zero-copy value parser as the high-level API, but returns raw items without string expansion or library indexing.
§Example
use bibtex_parser::parser::{parse_bibtex, ParsedItem};
use bibtex_parser::Value;
let input = r#"
@string{name = "John Doe"}
@article{test,
author = name,
title = "Part 1" # " and " # "Part 2"
}
"#;
let items = parse_bibtex(input)?;
// Find the entry
let entry = items.iter().find_map(|item| {
if let ParsedItem::Entry(e) = item { Some(e) } else { None }
}).unwrap();
// Author field contains unexpanded variable reference
let author_field = entry.fields.iter()
.find(|f| f.name == "author").unwrap();
match &author_field.value {
Value::Variable(var) => println!("Variable reference: {}", var),
_ => {}
}
// Title field contains concatenation structure
let title_field = entry.fields.iter()
.find(|f| f.name == "title").unwrap();
match &title_field.value {
Value::Concat(parts) => println!("Concatenation with {} parts", parts.len()),
_ => {}
}