pub struct Command { /* private fields */ }Expand description
A control sequence with its greedily-attached argument groups.
Implementations§
Source§impl Command
impl Command
Sourcepub fn control_word(&self) -> Option<ControlWord>
pub fn control_word(&self) -> Option<ControlWord>
The leading CONTROL_WORD token, or None for a control symbol. The
grammar bumps the control word as the command’s first token.
Sourcepub fn name(&self) -> Option<SmolStr>
pub fn name(&self) -> Option<SmolStr>
The control-word name (leading \ stripped), or None for a control
symbol.
Sourcepub fn control_word_range(&self) -> Option<TextRange>
pub fn control_word_range(&self) -> Option<TextRange>
The range of the leading CONTROL_WORD token (the \foo itself, backslash
included), or None for a control symbol. Callers use this to underline just
the control word rather than the whole node, which may carry greedily-attached
argument groups.
Sourcepub fn nth_group(&self, n: usize) -> Option<Group>
pub fn nth_group(&self, n: usize) -> Option<Group>
The n-th GROUP argument, if present. Filters GROUP only, so OPTIONAL
arguments do not shift brace indexing (\cmd[o]{a} → nth_group(0) is
{a}).
Sourcepub fn optionals(&self) -> impl Iterator<Item = Optional>
pub fn optionals(&self) -> impl Iterator<Item = Optional>
The OPTIONAL argument nodes, in source order.
Sourcepub fn nth_group_text(&self, n: usize) -> Option<SmolStr>
pub fn nth_group_text(&self, n: usize) -> Option<SmolStr>
The literal text inside the n-th GROUP argument, braces dropped. Returns
None when there is no n-th group or it holds non-token content (a nested
command — not a flat literal). See Group::inner_text.
Sourcepub fn nth_group_inner(&self, n: usize) -> Option<(TextRange, SmolStr)>
pub fn nth_group_inner(&self, n: usize) -> Option<(TextRange, SmolStr)>
The byte range of the content inside the n-th GROUP argument together
with that inner text — the location-aware counterpart to
Command::nth_group_text. See Group::inner.
Sourcepub fn first_group_range(&self) -> TextRange
pub fn first_group_range(&self) -> TextRange
The byte range of this command spanning its control word through the end of
its first {…} group — e.g. \label{key} up to the closing brace of
{key}. Deliberately not SyntaxNode::text_range, which the greedy parser
may stretch over a second group it attached without knowing arity
(\label{a}\n{…}; decision #8). Falls back to the full command range when the
first group is absent.