badness_parser/bib/semantic/entry.rs
1//! Data types collected by the bib [`semantic`](super) model: regular entries,
2//! `@string` definitions, and `@string` uses. The bib analog of
3//! [`crate::semantic::label`] — plain records keyed by position in the model's
4//! vectors, with the resolve-pass flags (`duplicate`, `resolved`) filled in by
5//! [`super::builder`].
6
7use rowan::TextRange;
8use smol_str::SmolStr;
9
10/// A regular bibliographic entry (`@article{key, …}`). Entry type and key are
11/// lowercased and as-authored respectively — `entry_type` is normalized (BibTeX is
12/// case-insensitive), `key` keeps its source casing (cite keys are case-sensitive in
13/// practice, though BibTeX folds them; we preserve and compare case-insensitively in
14/// the resolver).
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct Entry {
17 /// The entry type, lowercased (`"article"`, `"inproceedings"`).
18 pub entry_type: SmolStr,
19 /// The cite key as authored.
20 pub key: SmolStr,
21 /// The cleaned `title` field value, if present. Cached here so citation
22 /// completion can build a `filterText` (key + title + authors) without a CST walk.
23 pub title: Option<SmolStr>,
24 /// The cleaned `author` field value, falling back to `editor` (matching the
25 /// citation card's author-or-editor rule). Cached for the same reason as `title`.
26 pub authors: Option<SmolStr>,
27 /// The byte range of the `KEY` node.
28 pub key_range: TextRange,
29 /// The byte range of the whole entry.
30 pub range: TextRange,
31 /// `true` when an earlier entry already defined this key (case-insensitive); set
32 /// by the resolve pass. The *first* occurrence stays `false`.
33 pub duplicate: bool,
34}
35
36/// An `@string{ name = value }` macro definition.
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct StringDef {
39 /// The macro name, lowercased.
40 pub name: SmolStr,
41 /// The byte range of the name (`FIELD_NAME`) node.
42 pub range: TextRange,
43}
44
45/// A use of an `@string` macro — a bare (unquoted, unbraced) name inside a field
46/// value.
47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct StringUse {
49 /// The referenced macro name, lowercased.
50 pub name: SmolStr,
51 /// The byte range of the `LITERAL` piece.
52 pub range: TextRange,
53 /// `true` when the name matches a `@string` definition in this file or a
54 /// predefined month macro; set by the resolve pass.
55 pub resolved: bool,
56}