Skip to main content

Module ast

Module ast 

Source
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 AstNode wrappers over the BibTeX CST, with syntactic accessors. The bib analog of crate::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’s AstNode (and crate::ast::AstNode): cast succeeds iff can_cast(node.kind()). Re-declared here rather than shared with the LaTeX side because the two CSTs have distinct SyntaxKind enums and Language markers.

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 ENTRY and the byte range of its KEY node. None when 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"). None for a malformed entry with no ENTRY_TYPE child. Case is preserved; callers normalize.
field_name
The name of a FIELD (the text of its FIELD_NAME), or None if absent.
field_value
The VALUE node of a FIELD (the right-hand side of =), or None if absent.
fields
The FIELD children 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 its FIELD_NAME node. None for a malformed @string with no name = … field.
value_macro_uses
The bare-macro uses inside a VALUE: each LITERAL piece whose single token is a WORD (an unquoted, unbraced name) is an @string reference. A LITERAL wrapping a NUMBER is a literal number, not a macro use, and is skipped. Yields (name, range) with the range of the LITERAL piece.
value_text_cleaned
A field VALUE as 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.