Expand description
A typed AST layer over the BibTeX CST — the bib analog of crate::ast. Thin,
read-only wrappers (AstNode) giving nodes a typed identity and syntactic
accessors (an entry’s type and cite key, its fields’ names and values, an
@string definition’s name, the bare macro uses inside a value).
Purely syntactic: they know nothing about what a field or entry means (AGENTS.md decisions #2, #10), so the semantic layer, formatter, and linter build on them without meaning leaking downward.
The free functions below are thin, kind-agnostic shims over the wrapper methods,
kept so existing &SyntaxNode-based call sites compile unchanged.
Re-exports§
pub use nodes::Entry;pub use nodes::EntryType;pub use nodes::Field;pub use nodes::FieldName;pub use nodes::Key;pub use nodes::StringEntry;pub use nodes::Value;
Modules§
- nodes
- Typed
AstNodewrappers over the BibTeX CST, with syntactic accessors. The bib analog ofcrate::ast::nodes. Purely syntactic: they know nothing about what a field or entry means (AGENTS.md decisions #2, #10).
Traits§
- AstNode
- A typed wrapper over a bib CST node of a single
SyntaxKind. Mirrors rust-analyzer’sAstNode(andcrate::ast::AstNode):castsucceeds iffcan_cast(node.kind()). Re-declared here rather than shared with the LaTeX side because the two CSTs have distinctSyntaxKindenums andLanguagemarkers.
Functions§
- child
- The first child node castable to
N. - children
- All child nodes castable to
N, in source order. - cite_
key - The cite key of a regular
ENTRYand the byte range of itsKEYnode.Nonewhen the entry has no key (a recovery case) or the key is empty. - entry_
type - The entry type of an
ENTRY/STRING_ENTRY/ … node — the word following@(e.g."article","string").Nonefor a malformed entry with noENTRY_TYPEchild. Case is preserved; callers normalize. - field_
name - The name of a
FIELD(the text of itsFIELD_NAME), orNoneif absent. - field_
value - The
VALUEnode of aFIELD(the right-hand side of=), orNoneif absent. - fields
- The
FIELDchildren of an entry, in source order. - string_
def_ name - The macro name defined by a
STRING_ENTRY(@string{ name = value }) and the byte range of itsFIELD_NAMEnode.Nonefor a malformed@stringwith noname = …field. - value_
macro_ uses - The bare-macro uses inside a
VALUE: eachLITERALpiece whose single token is aWORD(an unquoted, unbraced name) is an@stringreference. ALITERALwrapping aNUMBERis a literal number, not a macro use, and is skipped. Yields(name, range)with the range of theLITERALpiece. - value_
text_ cleaned - A field
VALUEas plain display text: the node text, trimmed, with one layer of surrounding{…}/"…"removed and interior whitespace collapsed. Shared by the LSP hover/completion cards and the semantic model’s cached title/author facts.