Skip to main content

Module excommand

Module excommand 

Source
Expand description

Phase 2->3 ex-command parser.

Every :-line input becomes a CommandInvocation dispatched through lattice_grammar::execute() (DESIGN.md §5.2.1). Two parse shapes feed the same dispatcher:

  • Keyword form (:w foo.txt, :q!, :set number): split off the command word + optional bang, look up by alias in the registry, call the spec’s parse_args(rest, bang) to get typed Args, build a CommandInvocation.
  • Delimiter form (:s/.../.../, :%s/.../.../, :g/.../.../, :v/.../.../): the delimiter syntax doesn’t fit the keyword parse, so the front-end parses the body itself and produces an Args::List([pattern, replacement, flags]) for :substitute or Args::List([pattern, inverted, body]) for :global (DESIGN.md §B.1, §B.2). The same dispatcher then resolves the registered command id and runs the matching apply closure.

Structs§

CommandLineDecorations
Live decorations for the : line (MB.4): syntax spans, an optional validation error, and an optional parameter hint.
CommandLineSpan
One highlighted span of the : command line. range is a byte range into the line text (the : prompt is NOT included — spans are relative to command_line()).
SubstitutePartial
Result of a best-effort parse of an in-progress substitute command line, used by the live-preview path (refresh_substitute_preview in App). Unlike the full try_parse_substitute path, this never errors on incomplete input – a half-typed pattern or a missing second / is fine. Returns None only when the input doesn’t look like a substitute at all.

Enums§

ExCommandError
SubstitutePartialScope
Vim’s [%]s/pattern/replacement/[flags]. Produces a registered-invocation pointing at ex:substitute with the scope expressed via Range::CurrentLine / Range::Whole and Args::List([pattern, replacement, flags]). Scope (current line vs. whole buffer) detected on the partial or full :s / :%s form. Used by both the substitute parser and the live-preview parser below.

Functions§

aliases
Built-in aliases as a (short, canonical) map. Exposed for tests and any future :describe-aliases view.
command_line_decorations
Compute the live decorations for a : command line (MB.4). line is the text without the leading : (i.e. command_line()). Pure + cheap (one line, no I/O) so it runs on the actor thread each edit.
parse
Parse a : line into a CommandInvocation dispatchable through the unified grammar::execute().
preferred_alias_for
Reverse map of the alias table: for each canonical name, the preferred user-facing alias (the longest one). Used by completion to rewrite raw gen:commands output (which produces canonical names like ex:describe-command) into the form a user actually types (describe-command).
resolve_command_name_or_alias
Resolve a user-typed command spelling against the registry, trying the canonical form first then falling back to the alias table. Mirrors parse’s two-stage resolution so introspection (:describe-command, :apropos) accepts both forms a user can type at : (canonical ex:write or alias w / write).
try_parse_substitute_partial
Best-effort parse of a partial :s / :%s command line. Used by the live-preview path: as the user types, we want to highlight matches of the in-progress pattern even before the second / or closing / is typed. Backslash-escapes are honored the same way try_parse_substitute honors them, so a partial \/ doesn’t flip the field state mid-stream.