Minga.Command.Parser (Minga v0.1.0)

Copy Markdown View Source

Parser for Vim-style : command-line input.

Converts a raw string (without the leading :) into a structured parsed/0 value that the editor can act on.

Supported commands

InputResult
w{:save, []}
w!{:force_save, []}
q{:quit, []}
q!{:force_quit, []}
qa{:quit_all, []}
qa!{:force_quit_all, []}
wq{:save_quit, []}
e <filename>{:edit, filename}
e!{:force_edit, []}
<number>{:goto_line, number}
anything else{:unknown, original_string}

Summary

Types

Structured result of parsing a command-line string.

Flags for :%s substitution.

Functions

Parses a command-line string (without the leading :) and returns a parsed/0 value.

Types

parsed()

@type parsed() ::
  {:save, []}
  | {:force_save, []}
  | {:quit, []}
  | {:force_quit, []}
  | {:quit_all, []}
  | {:force_quit_all, []}
  | {:save_quit, []}
  | {:save_quit_all, []}
  | {:edit, String.t()}
  | {:force_edit, []}
  | {:checktime, []}
  | {:new_buffer, []}
  | {:lsp_info, []}
  | {:extensions, []}
  | {:extension_update, []}
  | {:extension_update_all, []}
  | {:parser_restart, []}
  | {:agent_abort, []}
  | {:agent_new_session, []}
  | {:agent_set_provider, [String.t()]}
  | {:agent_set_model, [String.t()]}
  | {:agent_pick_model, []}
  | {:agent_cycle_model, []}
  | {:agent_cycle_thinking, []}
  | {:tool_install_named, [String.t()]}
  | {:tool_uninstall_named, [String.t()]}
  | {:tool_update_named, [String.t()]}
  | {:goto_line, pos_integer()}
  | {:set, atom()}
  | {:setglobal, atom()}
  | {:substitute, String.t(), String.t(), [substitute_flag()]}
  | {:rename, String.t()}
  | {:unknown, String.t()}

Structured result of parsing a command-line string.

  • {:save, []} — write the current buffer to disk (:w)
  • {:force_save, []} — force-write, skipping mtime check (:w!)
  • {:quit, []} — close current tab or quit if last tab (:q)
  • {:force_quit, []} — force close tab or quit without saving (:q!)
  • {:quit_all, []} — quit the entire editor (:qa)
  • {:force_quit_all, []} — force quit the entire editor (:qa!)
  • {:save_quit, []} — save and close tab, or save and quit if last tab (:wq)
  • {:save_quit_all, []} — save all buffers and quit (:wqa)
  • {:edit, filename} — open a file (:e filename)
  • {:force_edit, []} — reload current buffer from disk (:e!)
  • {:new_buffer, []} — create a new empty buffer (:new / :enew)
  • {:goto_line, n} — jump to line n (:<number>)
  • {:substitute, pattern, replacement, flags}:%s/old/new/flags
  • {:unknown, raw} — unrecognised command

substitute_flag()

@type substitute_flag() :: :global | :confirm

Flags for :%s substitution.

Functions

parse(input)

@spec parse(String.t()) :: parsed()

Parses a command-line string (without the leading :) and returns a parsed/0 value.

Examples

iex> Minga.Command.Parser.parse("w")
{:save, []}

iex> Minga.Command.Parser.parse("q!")
{:force_quit, []}

iex> Minga.Command.Parser.parse("e README.md")
{:edit, "README.md"}

iex> Minga.Command.Parser.parse("42")
{:goto_line, 42}

iex> Minga.Command.Parser.parse("w!")
{:force_save, []}

iex> Minga.Command.Parser.parse("e!")
{:force_edit, []}

iex> Minga.Command.Parser.parse("xyz")
{:unknown, "xyz"}