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
AstNodewrappers over CST nodes, with positional/structural accessors. These are a read-only typed view over the generic, greedy CST (AGENTS.md decision #8): a\sectionand a\newcommandshare theCOMMANDshape, 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
AstTokenwrappers over CST tokens. OnlyControlWordexists 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’sAstNode:castsucceeds iffcan_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 rawchildren().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
COMMANDnode (the leading\stripped), orNonefor a control symbol. - control_
word_ range - The range of a
COMMANDnode’s leadingCONTROL_WORDtoken, orNonefor a control symbol. - environment_
name - The environment name of a
BEGINorENDnode — the text of itsNAME_GROUPchild, braces dropped. - environment_
name_ range - The byte range of the environment name inside a
BEGINorENDnode’sNAME_GROUP. - first_
group_ range - The byte range of
commandspanning 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
COMMANDwrapped ingroup. A braced l3docv-type name argument (\begin{macro}{\foo}) captures its content as one opaqueVERBtoken instead of aCOMMAND(issue #60); a control-word- shapedVERB(\+ letters, nothing else) reads as the same name. - group_
inner_ source - The raw inner source of
groupwith its outer braces dropped, nested braces kept. - nth_
group - The
n-thGROUPargument node ofcommand, if present. - nth_
group_ inner - The byte range of the content inside the
n-thGROUPargument together with that inner text. - nth_
group_ text - The literal text inside the
n-thGROUPargument ofcommand, braces dropped.