JustBash.Commands.Sed.Parser (JustBash v0.4.0)

View Source

Parser for SED scripts.

Parses SED script strings into command structures that can be executed by the Executor.

Summary

Functions

Compile a regex pattern with the given flags. Converts BRE (Basic Regular Expression) to ERE for Elixir's PCRE engine.

Parse SED scripts into command structures.

Types

address()

@type address() :: nil | :last | {:line, pos_integer()} | {:regex, Regex.t()}

command()

@type command() ::
  :noop
  | :delete
  | :print
  | {:substitute, Regex.t(), String.t(), substitute_flags()}
  | {:append, String.t()}
  | {:insert, String.t()}
  | {:change, String.t()}
  | {:translate, String.t(), String.t()}

sed_command()

@type sed_command() :: %{
  address1: address(),
  address2: address(),
  negated: boolean(),
  command: command()
}

substitute_flags()

@type substitute_flags() :: [:global | :caseless | :print | {:nth, pos_integer()}]

Functions

compile_regex(pattern, flags, ctx)

@spec compile_regex(String.t(), substitute_flags(), ctx()) ::
  {:ok, Regex.t()} | {:error, String.t()}

Compile a regex pattern with the given flags. Converts BRE (Basic Regular Expression) to ERE for Elixir's PCRE engine.

parse(scripts, extended, limits \\ nil)

@spec parse([String.t()], boolean(), JustBash.Limit.t() | nil) ::
  {:ok, [sed_command()]} | {:error, String.t()}

Parse SED scripts into command structures.

Returns {:ok, commands} on success or {:error, message} on failure.