Skip to main content

Module ast

Module ast 

Source
Expand description

A typed AST layer over the CST — thin, read-only wrappers (AstNode / AstToken) giving nodes a typed identity and named, positional accessors (reading a COMMAND’s name and its literal {…} argument text, an ENVIRONMENT’s \begin/\end, …).

Purely syntactic: the wrappers know nothing about what any command means, so both the syntactic project/ layer and the semantic layer build on them without meaning leaking downward (AGENTS.md decision #2). Because the CST is generic and greedy (decision #8), accessors are positional (nodes::Command::nth_group) and tolerate over-attached groups by construction — they never pretend arity is fixed.

The free functions below are thin shims over the wrapper methods, kept so existing &SyntaxNode-based call sites compile unchanged during the migration.

Re-exports§

pub use nodes::Begin;
pub use nodes::Command;
pub use nodes::End;
pub use nodes::Environment;
pub use nodes::Group;
pub use nodes::NameGroup;
pub use nodes::Optional;
pub use tokens::ControlWord;

Modules§

nodes
Typed AstNode wrappers over CST nodes, with positional/structural accessors. These are a read-only typed view over the generic, greedy CST (AGENTS.md decision #8): a \section and a \newcommand share the COMMAND shape, so accessors are positional (Command::nth_group) and tolerate greedily over-attached groups by construction. They expose structure only, never command meaning (decision #2) — no signature-DB lookup lives here.
tokens
Typed AstToken wrappers over CST tokens. Only ControlWord exists today — the rest of the lexer’s tokens (L_BRACE, WORD, trivia, …) are matched raw by the formatter’s token loops, which is idiomatic and should stay that way. Add a wrapper here only when a token grows a named accessor consumer.

Traits§

AstNode
A typed wrapper over a CST node of a single SyntaxKind. Mirrors rust-analyzer’s AstNode: cast succeeds iff can_cast(node.kind()).
AstToken
A typed wrapper over a CST token of a single SyntaxKind.

Functions§

child
The first child node castable to N. Replaces the raw children().find(|c| c.kind() == X) idiom at field-extraction sites.
child_token
The first child token castable to T.
children
All child nodes castable to N, in source order.
command_name
The control-word name of a COMMAND node (the leading \ stripped), or None for a control symbol.
control_word_range
The range of a COMMAND node’s leading CONTROL_WORD token, or None for a control symbol.
environment_name
The environment name of a BEGIN or END node — the text of its NAME_GROUP child, braces dropped.
environment_name_range
The byte range of the environment name inside a BEGIN or END node’s NAME_GROUP.
first_group_range
The byte range of command spanning its control word through the end of its first {…} group; the full command range when the first group is absent.
group_command_name
The control-word name of a single COMMAND wrapped in group. A braced l3doc v-type name argument (\begin{macro}{\foo}) captures its content as one opaque VERB token instead of a COMMAND (issue #60); a control-word- shaped VERB (\ + letters, nothing else) reads as the same name.
group_inner_source
The raw inner source of group with its outer braces dropped, nested braces kept.
nth_group
The n-th GROUP argument node of command, if present.
nth_group_inner
The byte range of the content inside the n-th GROUP argument together with that inner text.
nth_group_text
The literal text inside the n-th GROUP argument of command, braces dropped.